xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision 2af7aa66)
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;
556*2af7aa66SLuiz 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;
71004837f64SMarcel Holtmann 	__u8		mode;
7111da177e4SLinus Torvalds 	__u8		type;
71240bef302SJohan Hedberg 	__u8		role;
713a0c808b3SJohan Hedberg 	bool		out;
7144c67bc74SMarcel Holtmann 	__u8		attempt;
7151da177e4SLinus Torvalds 	__u8		dev_class[3];
716cad718edSJohan Hedberg 	__u8		features[HCI_MAX_PAGES][8];
717a8746417SMarcel Holtmann 	__u16		pkt_type;
71804837f64SMarcel Holtmann 	__u16		link_policy;
71913d39315SWaldemar Rymarkiewicz 	__u8		key_type;
72040be492fSMarcel Holtmann 	__u8		auth_type;
7218c1b2355SMarcel Holtmann 	__u8		sec_level;
722765c2a96SJohan Hedberg 	__u8		pending_sec_level;
723980e1a53SJohan Hedberg 	__u8		pin_length;
724726b4ffcSVinicius Costa Gomes 	__u8		enc_key_size;
72517fa4b9dSJohan Hedberg 	__u8		io_capability;
72692a25256SJohan Hedberg 	__u32		passkey_notify;
72792a25256SJohan Hedberg 	__u8		passkey_entered;
728052b30b0SMarcel Holtmann 	__u16		disc_timeout;
72909ae260bSJohan Hedberg 	__u16		conn_timeout;
73010c62ddcSFrédéric Dalleau 	__u16		setting;
731302975cbSSpoorthi Ravishankar Koppad 	__u16		auth_payload_timeout;
7321e406eefSAndre Guedes 	__u16		le_conn_min_interval;
7331e406eefSAndre Guedes 	__u16		le_conn_max_interval;
734e04fde60SMarcel Holtmann 	__u16		le_conn_interval;
735e04fde60SMarcel Holtmann 	__u16		le_conn_latency;
736e04fde60SMarcel Holtmann 	__u16		le_supv_timeout;
737db08722fSLuiz Augusto von Dentz 	__u8		le_adv_data[HCI_MAX_EXT_AD_LENGTH];
738fd45ada9SAlfonso Acosta 	__u8		le_adv_data_len;
739eca0ae4aSLuiz Augusto von Dentz 	__u8		le_per_adv_data[HCI_MAX_PER_AD_LENGTH];
740eca0ae4aSLuiz Augusto von Dentz 	__u8		le_per_adv_data_len;
7411efd927dSLuiz Augusto von Dentz 	__u8		le_tx_phy;
7421efd927dSLuiz Augusto von Dentz 	__u8		le_rx_phy;
7435ae76a94SAndrzej Kaczmarek 	__s8		rssi;
7445a134faeSAndrzej Kaczmarek 	__s8		tx_power;
745d0455ed9SAndrzej Kaczmarek 	__s8		max_tx_power;
74626afbd82SLuiz Augusto von Dentz 	struct bt_iso_qos iso_qos;
74751a8efd7SJohan Hedberg 	unsigned long	flags;
7481da177e4SLinus Torvalds 
74976b13996SManish Mandlik 	enum conn_reasons conn_reason;
750a13f316eSLuiz Augusto von Dentz 	__u8		abort_reason;
75176b13996SManish Mandlik 
75233f35721SJohan Hedberg 	__u32		clock;
75333f35721SJohan Hedberg 	__u16		clock_accuracy;
75433f35721SJohan Hedberg 
755dd983808SAndrzej Kaczmarek 	unsigned long	conn_info_timestamp;
756dd983808SAndrzej Kaczmarek 
75703b555e1SJohan Hedberg 	__u8		remote_cap;
75803b555e1SJohan Hedberg 	__u8		remote_auth;
7593161ae1cSAndrei Emeltchenko 	__u8		remote_id;
76003b555e1SJohan Hedberg 
7611da177e4SLinus Torvalds 	unsigned int	sent;
7621da177e4SLinus Torvalds 
7631da177e4SLinus Torvalds 	struct sk_buff_head data_q;
7642c33c06aSGustavo F. Padovan 	struct list_head chan_list;
7651da177e4SLinus Torvalds 
76619c40e3bSGustavo F. Padovan 	struct delayed_work disc_work;
7677bc18d9dSJohan Hedberg 	struct delayed_work auto_accept_work;
768a74a84f6SJohan Hedberg 	struct delayed_work idle_work;
7699489eca4SJohan Hedberg 	struct delayed_work le_conn_timeout;
7701da177e4SLinus Torvalds 
771b219e3acSMarcel Holtmann 	struct device	dev;
77223b9ceb7SMarcel Holtmann 	struct dentry	*debugfs;
773b219e3acSMarcel Holtmann 
7741da177e4SLinus Torvalds 	struct hci_dev	*hdev;
7751da177e4SLinus Torvalds 	void		*l2cap_data;
7761da177e4SLinus Torvalds 	void		*sco_data;
77726afbd82SLuiz Augusto von Dentz 	void		*iso_data;
7789740e49dSAndrei Emeltchenko 	struct amp_mgr	*amp_mgr;
7791da177e4SLinus Torvalds 
78006149746SLuiz Augusto von Dentz 	struct list_head link_list;
78106149746SLuiz Augusto von Dentz 	struct hci_conn	*parent;
78206149746SLuiz Augusto von Dentz 	struct hci_link *link;
78306149746SLuiz Augusto von Dentz 
784b2af264aSKiran K 	struct bt_codec codec;
785e9a416b5SJohan Hedberg 
786e9a416b5SJohan Hedberg 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
787e9a416b5SJohan Hedberg 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
788e9a416b5SJohan Hedberg 	void (*disconn_cfm_cb)	(struct hci_conn *conn, u8 reason);
78926afbd82SLuiz Augusto von Dentz 
79026afbd82SLuiz Augusto von Dentz 	void (*cleanup)(struct hci_conn *conn);
7911da177e4SLinus Torvalds };
7921da177e4SLinus Torvalds 
79306149746SLuiz Augusto von Dentz struct hci_link {
79406149746SLuiz Augusto von Dentz 	struct list_head list;
79506149746SLuiz Augusto von Dentz 	struct hci_conn *conn;
79606149746SLuiz Augusto von Dentz };
79706149746SLuiz Augusto von Dentz 
79873d80debSLuiz Augusto von Dentz struct hci_chan {
79973d80debSLuiz Augusto von Dentz 	struct list_head list;
80042c4e53eSAndrei Emeltchenko 	__u16 handle;
80173d80debSLuiz Augusto von Dentz 	struct hci_conn *conn;
80273d80debSLuiz Augusto von Dentz 	struct sk_buff_head data_q;
80373d80debSLuiz Augusto von Dentz 	unsigned int	sent;
804168df8e5SMat Martineau 	__u8		state;
8055c4c8c95SArchie Pusaka 	bool		amp;
80673d80debSLuiz Augusto von Dentz };
80773d80debSLuiz Augusto von Dentz 
80815819a70SAndre Guedes struct hci_conn_params {
80915819a70SAndre Guedes 	struct list_head list;
81093450c75SJohan Hedberg 	struct list_head action;
81115819a70SAndre Guedes 
81215819a70SAndre Guedes 	bdaddr_t addr;
81315819a70SAndre Guedes 	u8 addr_type;
81415819a70SAndre Guedes 
81515819a70SAndre Guedes 	u16 conn_min_interval;
81615819a70SAndre Guedes 	u16 conn_max_interval;
817f044eb05SMarcel Holtmann 	u16 conn_latency;
818f044eb05SMarcel Holtmann 	u16 supervision_timeout;
8199fcb18efSAndre Guedes 
8209fcb18efSAndre Guedes 	enum {
8219fcb18efSAndre Guedes 		HCI_AUTO_CONN_DISABLED,
822a3451d27SJohan Hedberg 		HCI_AUTO_CONN_REPORT,
8234b9e7e75SMarcel Holtmann 		HCI_AUTO_CONN_DIRECT,
8249fcb18efSAndre Guedes 		HCI_AUTO_CONN_ALWAYS,
8259fcb18efSAndre Guedes 		HCI_AUTO_CONN_LINK_LOSS,
826158e9218SJakub Pawlowski 		HCI_AUTO_CONN_EXPLICIT,
8279fcb18efSAndre Guedes 	} auto_connect;
828f161dd41SJohan Hedberg 
829f161dd41SJohan Hedberg 	struct hci_conn *conn;
830158e9218SJakub Pawlowski 	bool explicit_connect;
831195ef75eSPauli Virtanen 	/* Accessed without hdev->lock: */
832e1cff700SLinus Torvalds 	hci_conn_flags_t flags;
833853b70b5SLuiz Augusto von Dentz 	u8  privacy_mode;
83415819a70SAndre Guedes };
83515819a70SAndre Guedes 
8361da177e4SLinus Torvalds extern struct list_head hci_dev_list;
8371da177e4SLinus Torvalds extern struct list_head hci_cb_list;
8381da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock;
839fba7ecf0SJohan Hedberg extern struct mutex hci_cb_list_lock;
8401da177e4SLinus Torvalds 
841eacb44dfSMarcel Holtmann #define hci_dev_set_flag(hdev, nr)             set_bit((nr), (hdev)->dev_flags)
842eacb44dfSMarcel Holtmann #define hci_dev_clear_flag(hdev, nr)           clear_bit((nr), (hdev)->dev_flags)
843eacb44dfSMarcel Holtmann #define hci_dev_change_flag(hdev, nr)          change_bit((nr), (hdev)->dev_flags)
844eacb44dfSMarcel Holtmann #define hci_dev_test_flag(hdev, nr)            test_bit((nr), (hdev)->dev_flags)
845eacb44dfSMarcel Holtmann #define hci_dev_test_and_set_flag(hdev, nr)    test_and_set_bit((nr), (hdev)->dev_flags)
846eacb44dfSMarcel Holtmann #define hci_dev_test_and_clear_flag(hdev, nr)  test_and_clear_bit((nr), (hdev)->dev_flags)
847eacb44dfSMarcel Holtmann #define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), (hdev)->dev_flags)
848d7a5a11dSMarcel Holtmann 
849eacb44dfSMarcel Holtmann #define hci_dev_clear_volatile_flags(hdev)			\
850eacb44dfSMarcel Holtmann 	do {							\
851eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LE_SCAN);		\
852eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LE_ADV);		\
8532eb71a3aSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);\
854eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ);	\
855ae7d925bSJoseph Hwang 		hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);	\
856eacb44dfSMarcel Holtmann 	} while (0)
857516018a9SMarcel Holtmann 
8584fc9857aSLuiz Augusto von Dentz #define hci_dev_le_state_simultaneous(hdev) \
8594fc9857aSLuiz Augusto von Dentz 	(test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && \
8604fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[4] & 0x08) &&	/* Central */ \
8614fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[4] & 0x40) &&	/* Peripheral */ \
8624fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[3] & 0x10))	/* Simultaneous */
8634fc9857aSLuiz Augusto von Dentz 
864686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */
865e74e58f8SJoe Perches int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
866e74e58f8SJoe Perches int l2cap_disconn_ind(struct hci_conn *hcon);
8679b4c3336SArron Wang void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
868686ebf28SUlisses Furquim 
869ff50e8afSArron Wang #if IS_ENABLED(CONFIG_BT_BREDR)
870e74e58f8SJoe Perches int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
8719b4c3336SArron Wang void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
872ff50e8afSArron Wang #else
873ff50e8afSArron Wang static inline int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
874ff50e8afSArron Wang 				  __u8 *flags)
875ff50e8afSArron Wang {
876ff50e8afSArron Wang 	return 0;
877ff50e8afSArron Wang }
878ff50e8afSArron Wang 
879ff50e8afSArron Wang static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
880ff50e8afSArron Wang {
881ff50e8afSArron Wang }
882ff50e8afSArron Wang #endif
883686ebf28SUlisses Furquim 
884ccf74f23SLuiz Augusto von Dentz #if IS_ENABLED(CONFIG_BT_LE)
885ccf74f23SLuiz Augusto von Dentz int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
886ccf74f23SLuiz Augusto von Dentz void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
887ccf74f23SLuiz Augusto von Dentz #else
888ccf74f23SLuiz Augusto von Dentz static inline int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
889ccf74f23SLuiz Augusto von Dentz 				  __u8 *flags)
890ccf74f23SLuiz Augusto von Dentz {
891ccf74f23SLuiz Augusto von Dentz 	return 0;
892ccf74f23SLuiz Augusto von Dentz }
893ccf74f23SLuiz Augusto von Dentz static inline void iso_recv(struct hci_conn *hcon, struct sk_buff *skb,
894ccf74f23SLuiz Augusto von Dentz 			    u16 flags)
895ccf74f23SLuiz Augusto von Dentz {
896ccf74f23SLuiz Augusto von Dentz }
897ccf74f23SLuiz Augusto von Dentz #endif
898ccf74f23SLuiz Augusto von Dentz 
8991da177e4SLinus Torvalds /* ----- Inquiry cache ----- */
90070f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX   (HZ*30)   /* 30 seconds */
90170f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   /* 60 seconds */
9021da177e4SLinus Torvalds 
90330883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev)
9041da177e4SLinus Torvalds {
905ff9ef578SJohan Hedberg 	hdev->discovery.state = DISCOVERY_STOPPED;
90630883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.all);
90730883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.unknown);
90830883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.resolve);
909da25cf6aSMarcel Holtmann 	hdev->discovery.report_invalid_rssi = true;
91037eab042SJakub Pawlowski 	hdev->discovery.rssi = HCI_RSSI_INVALID;
9111da177e4SLinus Torvalds }
9121da177e4SLinus Torvalds 
9130256325eSMarcel Holtmann static inline void hci_discovery_filter_clear(struct hci_dev *hdev)
9140256325eSMarcel Holtmann {
91582f8b651SJakub Pawlowski 	hdev->discovery.result_filtering = false;
916da25cf6aSMarcel Holtmann 	hdev->discovery.report_invalid_rssi = true;
9170256325eSMarcel Holtmann 	hdev->discovery.rssi = HCI_RSSI_INVALID;
9180256325eSMarcel Holtmann 	hdev->discovery.uuid_count = 0;
9190256325eSMarcel Holtmann 	kfree(hdev->discovery.uuids);
9200256325eSMarcel Holtmann 	hdev->discovery.uuids = NULL;
9212d28cfe7SJakub Pawlowski 	hdev->discovery.scan_start = 0;
9222d28cfe7SJakub Pawlowski 	hdev->discovery.scan_duration = 0;
9230256325eSMarcel Holtmann }
9240256325eSMarcel Holtmann 
92530dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev);
92630dc78e1SJohan Hedberg 
927ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state);
928ff9ef578SJohan Hedberg 
9291da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev)
9301da177e4SLinus Torvalds {
93130883512SJohan Hedberg 	return list_empty(&hdev->discovery.all);
9321da177e4SLinus Torvalds }
9331da177e4SLinus Torvalds 
9341da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev)
9351da177e4SLinus Torvalds {
93630883512SJohan Hedberg 	struct discovery_state *c = &hdev->discovery;
9371da177e4SLinus Torvalds 	return jiffies - c->timestamp;
9381da177e4SLinus Torvalds }
9391da177e4SLinus Torvalds 
9401da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e)
9411da177e4SLinus Torvalds {
9421da177e4SLinus Torvalds 	return jiffies - e->timestamp;
9431da177e4SLinus Torvalds }
9441da177e4SLinus Torvalds 
9455a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
9465a9d0a3fSWaldemar Rymarkiewicz 					       bdaddr_t *bdaddr);
947561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
948561aafbcSJohan Hedberg 						       bdaddr_t *bdaddr);
94930dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
95030dc78e1SJohan Hedberg 						       bdaddr_t *bdaddr,
95130dc78e1SJohan Hedberg 						       int state);
952a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
953a3d4e20aSJohan Hedberg 				      struct inquiry_entry *ie);
954af58925cSMarcel Holtmann u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
955af58925cSMarcel Holtmann 			     bool name_known);
9561f9b9a5dSAndre Guedes void hci_inquiry_cache_flush(struct hci_dev *hdev);
9571da177e4SLinus Torvalds 
9581da177e4SLinus Torvalds /* ----- HCI Connections ----- */
9591da177e4SLinus Torvalds enum {
9601da177e4SLinus Torvalds 	HCI_CONN_AUTH_PEND,
9611da177e4SLinus Torvalds 	HCI_CONN_ENCRYPT_PEND,
96204837f64SMarcel Holtmann 	HCI_CONN_RSWITCH_PEND,
96304837f64SMarcel Holtmann 	HCI_CONN_MODE_CHANGE_PEND,
964e73439d8SMarcel Holtmann 	HCI_CONN_SCO_SETUP_PEND,
965b644ba33SJohan Hedberg 	HCI_CONN_MGMT_CONNECTED,
96658a681efSJohan Hedberg 	HCI_CONN_SSP_ENABLED,
967eb9a8f3fSMarcel Holtmann 	HCI_CONN_SC_ENABLED,
968abf76badSMarcel Holtmann 	HCI_CONN_AES_CCM,
96958a681efSJohan Hedberg 	HCI_CONN_POWER_SAVE,
970af6a9c32SJohan Hedberg 	HCI_CONN_FLUSH_KEY,
9714dae2798SJohan Hedberg 	HCI_CONN_ENCRYPT,
9724dae2798SJohan Hedberg 	HCI_CONN_AUTH,
9734dae2798SJohan Hedberg 	HCI_CONN_SECURE,
9744dae2798SJohan Hedberg 	HCI_CONN_FIPS,
975fe59a05fSJohan Hedberg 	HCI_CONN_STK_ENCRYPT,
976977f8fceSJohan Hedberg 	HCI_CONN_AUTH_INITIATOR,
977f94b665dSJohan Hedberg 	HCI_CONN_DROP,
978b62e7220SLuiz Augusto von Dentz 	HCI_CONN_CANCEL,
97989cbb063SAlfonso Acosta 	HCI_CONN_PARAM_REMOVAL_PEND,
980fe8bc5acSJohan Hedberg 	HCI_CONN_NEW_LINK_KEY,
981158e9218SJakub Pawlowski 	HCI_CONN_SCANNING,
982160b9251SSzymon Janc 	HCI_CONN_AUTH_FAILURE,
983eca0ae4aSLuiz Augusto von Dentz 	HCI_CONN_PER_ADV,
984a0bfde16SIulia Tanasescu 	HCI_CONN_BIG_CREATED,
9857f74563eSPauli Virtanen 	HCI_CONN_CREATE_CIS,
986f777d882SIulia Tanasescu 	HCI_CONN_BIG_SYNC,
987f777d882SIulia Tanasescu 	HCI_CONN_BIG_SYNC_FAILED,
988fbdc4bc4SIulia Tanasescu 	HCI_CONN_PA_SYNC,
989fbdc4bc4SIulia Tanasescu 	HCI_CONN_PA_SYNC_FAILED,
9901da177e4SLinus Torvalds };
9911da177e4SLinus Torvalds 
992aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
993aa64a8b5SJohan Hedberg {
994aa64a8b5SJohan Hedberg 	struct hci_dev *hdev = conn->hdev;
995d7a5a11dSMarcel Holtmann 	return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) &&
996c3c7ea65SGustavo Padovan 	       test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
997aa64a8b5SJohan Hedberg }
998aa64a8b5SJohan Hedberg 
999eb9a8f3fSMarcel Holtmann static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
1000eb9a8f3fSMarcel Holtmann {
1001eb9a8f3fSMarcel Holtmann 	struct hci_dev *hdev = conn->hdev;
1002d7a5a11dSMarcel Holtmann 	return hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
1003eb9a8f3fSMarcel Holtmann 	       test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
1004eb9a8f3fSMarcel Holtmann }
1005eb9a8f3fSMarcel Holtmann 
10061da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
10071da177e4SLinus Torvalds {
10081da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
1009d4b20f0bSLuiz Augusto von Dentz 	list_add_tail_rcu(&c->list, &h->list);
1010fcd89c09SVille Tervo 	switch (c->type) {
1011fcd89c09SVille Tervo 	case ACL_LINK:
10121da177e4SLinus Torvalds 		h->acl_num++;
1013fcd89c09SVille Tervo 		break;
1014bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1015bd1eb66bSAndrei Emeltchenko 		h->amp_num++;
1016bd1eb66bSAndrei Emeltchenko 		break;
1017fcd89c09SVille Tervo 	case LE_LINK:
1018fcd89c09SVille Tervo 		h->le_num++;
1019f8218dc6SJohan Hedberg 		if (c->role == HCI_ROLE_SLAVE)
102039bc74caSArchie Pusaka 			h->le_num_peripheral++;
1021fcd89c09SVille Tervo 		break;
1022fcd89c09SVille Tervo 	case SCO_LINK:
1023fcd89c09SVille Tervo 	case ESCO_LINK:
10241da177e4SLinus Torvalds 		h->sco_num++;
1025fcd89c09SVille Tervo 		break;
102626afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
102726afbd82SLuiz Augusto von Dentz 		h->iso_num++;
102826afbd82SLuiz Augusto von Dentz 		break;
1029fcd89c09SVille Tervo 	}
10301da177e4SLinus Torvalds }
10311da177e4SLinus Torvalds 
10321da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
10331da177e4SLinus Torvalds {
10341da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
1035bf4c6325SGustavo F. Padovan 
1036bf4c6325SGustavo F. Padovan 	list_del_rcu(&c->list);
1037bf4c6325SGustavo F. Padovan 	synchronize_rcu();
1038bf4c6325SGustavo F. Padovan 
1039fcd89c09SVille Tervo 	switch (c->type) {
1040fcd89c09SVille Tervo 	case ACL_LINK:
10411da177e4SLinus Torvalds 		h->acl_num--;
1042fcd89c09SVille Tervo 		break;
1043bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1044bd1eb66bSAndrei Emeltchenko 		h->amp_num--;
1045bd1eb66bSAndrei Emeltchenko 		break;
1046fcd89c09SVille Tervo 	case LE_LINK:
1047fcd89c09SVille Tervo 		h->le_num--;
1048f8218dc6SJohan Hedberg 		if (c->role == HCI_ROLE_SLAVE)
104939bc74caSArchie Pusaka 			h->le_num_peripheral--;
1050fcd89c09SVille Tervo 		break;
1051fcd89c09SVille Tervo 	case SCO_LINK:
1052fcd89c09SVille Tervo 	case ESCO_LINK:
10531da177e4SLinus Torvalds 		h->sco_num--;
1054fcd89c09SVille Tervo 		break;
105526afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
105626afbd82SLuiz Augusto von Dentz 		h->iso_num--;
105726afbd82SLuiz Augusto von Dentz 		break;
1058fcd89c09SVille Tervo 	}
10591da177e4SLinus Torvalds }
10601da177e4SLinus Torvalds 
106152087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
106252087a79SLuiz Augusto von Dentz {
106352087a79SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
106452087a79SLuiz Augusto von Dentz 	switch (type) {
106552087a79SLuiz Augusto von Dentz 	case ACL_LINK:
106652087a79SLuiz Augusto von Dentz 		return h->acl_num;
1067bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1068bd1eb66bSAndrei Emeltchenko 		return h->amp_num;
106952087a79SLuiz Augusto von Dentz 	case LE_LINK:
107052087a79SLuiz Augusto von Dentz 		return h->le_num;
107152087a79SLuiz Augusto von Dentz 	case SCO_LINK:
107252087a79SLuiz Augusto von Dentz 	case ESCO_LINK:
107352087a79SLuiz Augusto von Dentz 		return h->sco_num;
107426afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
107526afbd82SLuiz Augusto von Dentz 		return h->iso_num;
107652087a79SLuiz Augusto von Dentz 	default:
107752087a79SLuiz Augusto von Dentz 		return 0;
107852087a79SLuiz Augusto von Dentz 	}
107952087a79SLuiz Augusto von Dentz }
108052087a79SLuiz Augusto von Dentz 
1081f4f07505SJohan Hedberg static inline unsigned int hci_conn_count(struct hci_dev *hdev)
1082f4f07505SJohan Hedberg {
1083f4f07505SJohan Hedberg 	struct hci_conn_hash *c = &hdev->conn_hash;
1084f4f07505SJohan Hedberg 
108526afbd82SLuiz Augusto von Dentz 	return c->acl_num + c->amp_num + c->sco_num + c->le_num + c->iso_num;
1086f4f07505SJohan Hedberg }
1087f4f07505SJohan Hedberg 
1088845472e8SMarcel Holtmann static inline __u8 hci_conn_lookup_type(struct hci_dev *hdev, __u16 handle)
1089845472e8SMarcel Holtmann {
1090845472e8SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
1091845472e8SMarcel Holtmann 	struct hci_conn *c;
1092845472e8SMarcel Holtmann 	__u8 type = INVALID_LINK;
1093845472e8SMarcel Holtmann 
1094845472e8SMarcel Holtmann 	rcu_read_lock();
1095845472e8SMarcel Holtmann 
1096845472e8SMarcel Holtmann 	list_for_each_entry_rcu(c, &h->list, list) {
1097845472e8SMarcel Holtmann 		if (c->handle == handle) {
1098845472e8SMarcel Holtmann 			type = c->type;
1099845472e8SMarcel Holtmann 			break;
1100845472e8SMarcel Holtmann 		}
1101845472e8SMarcel Holtmann 	}
1102845472e8SMarcel Holtmann 
1103845472e8SMarcel Holtmann 	rcu_read_unlock();
1104845472e8SMarcel Holtmann 
1105845472e8SMarcel Holtmann 	return type;
1106845472e8SMarcel Holtmann }
1107845472e8SMarcel Holtmann 
1108eca0ae4aSLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_bis(struct hci_dev *hdev,
11096a42e9bfSIulia Tanasescu 							bdaddr_t *ba, __u8 bis)
1110eca0ae4aSLuiz Augusto von Dentz {
1111eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1112eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn  *c;
1113eca0ae4aSLuiz Augusto von Dentz 
1114eca0ae4aSLuiz Augusto von Dentz 	rcu_read_lock();
1115eca0ae4aSLuiz Augusto von Dentz 
1116eca0ae4aSLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1117eca0ae4aSLuiz Augusto von Dentz 		if (bacmp(&c->dst, ba) || c->type != ISO_LINK)
1118eca0ae4aSLuiz Augusto von Dentz 			continue;
1119eca0ae4aSLuiz Augusto von Dentz 
11206a42e9bfSIulia Tanasescu 		if (c->iso_qos.bcast.bis == bis) {
1121eca0ae4aSLuiz Augusto von Dentz 			rcu_read_unlock();
1122eca0ae4aSLuiz Augusto von Dentz 			return c;
1123eca0ae4aSLuiz Augusto von Dentz 		}
1124eca0ae4aSLuiz Augusto von Dentz 	}
1125eca0ae4aSLuiz Augusto von Dentz 	rcu_read_unlock();
1126eca0ae4aSLuiz Augusto von Dentz 
1127eca0ae4aSLuiz Augusto von Dentz 	return NULL;
1128eca0ae4aSLuiz Augusto von Dentz }
1129eca0ae4aSLuiz Augusto von Dentz 
1130a0bfde16SIulia Tanasescu static inline struct hci_conn *
1131a0bfde16SIulia Tanasescu hci_conn_hash_lookup_per_adv_bis(struct hci_dev *hdev,
1132a0bfde16SIulia Tanasescu 				 bdaddr_t *ba,
1133a0bfde16SIulia Tanasescu 				 __u8 big, __u8 bis)
1134a0bfde16SIulia Tanasescu {
1135a0bfde16SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1136a0bfde16SIulia Tanasescu 	struct hci_conn  *c;
1137a0bfde16SIulia Tanasescu 
1138a0bfde16SIulia Tanasescu 	rcu_read_lock();
1139a0bfde16SIulia Tanasescu 
1140a0bfde16SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1141a0bfde16SIulia Tanasescu 		if (bacmp(&c->dst, ba) || c->type != ISO_LINK ||
1142a0bfde16SIulia Tanasescu 			!test_bit(HCI_CONN_PER_ADV, &c->flags))
1143a0bfde16SIulia Tanasescu 			continue;
1144a0bfde16SIulia Tanasescu 
1145a0bfde16SIulia Tanasescu 		if (c->iso_qos.bcast.big == big &&
1146a0bfde16SIulia Tanasescu 		    c->iso_qos.bcast.bis == bis) {
1147a0bfde16SIulia Tanasescu 			rcu_read_unlock();
1148a0bfde16SIulia Tanasescu 			return c;
1149a0bfde16SIulia Tanasescu 		}
1150a0bfde16SIulia Tanasescu 	}
1151a0bfde16SIulia Tanasescu 	rcu_read_unlock();
1152a0bfde16SIulia Tanasescu 
1153a0bfde16SIulia Tanasescu 	return NULL;
1154a0bfde16SIulia Tanasescu }
1155a0bfde16SIulia Tanasescu 
11561da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
11571da177e4SLinus Torvalds 								__u16 handle)
11581da177e4SLinus Torvalds {
11591da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
11601da177e4SLinus Torvalds 	struct hci_conn  *c;
11611da177e4SLinus Torvalds 
1162bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1163bf4c6325SGustavo F. Padovan 
1164bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1165bf4c6325SGustavo F. Padovan 		if (c->handle == handle) {
1166bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
11671da177e4SLinus Torvalds 			return c;
11681da177e4SLinus Torvalds 		}
1169bf4c6325SGustavo F. Padovan 	}
1170bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1171bf4c6325SGustavo F. Padovan 
11721da177e4SLinus Torvalds 	return NULL;
11731da177e4SLinus Torvalds }
11741da177e4SLinus Torvalds 
11751da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
11761da177e4SLinus Torvalds 							__u8 type, bdaddr_t *ba)
11771da177e4SLinus Torvalds {
11781da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
11791da177e4SLinus Torvalds 	struct hci_conn  *c;
11801da177e4SLinus Torvalds 
1181bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1182bf4c6325SGustavo F. Padovan 
1183bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1184bf4c6325SGustavo F. Padovan 		if (c->type == type && !bacmp(&c->dst, ba)) {
1185bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
11861da177e4SLinus Torvalds 			return c;
11871da177e4SLinus Torvalds 		}
1188bf4c6325SGustavo F. Padovan 	}
1189bf4c6325SGustavo F. Padovan 
1190bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1191bf4c6325SGustavo F. Padovan 
11921da177e4SLinus Torvalds 	return NULL;
11931da177e4SLinus Torvalds }
11941da177e4SLinus Torvalds 
11951b51c7b6SJohan Hedberg static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev,
11961b51c7b6SJohan Hedberg 						       bdaddr_t *ba,
11971b51c7b6SJohan Hedberg 						       __u8 ba_type)
11981b51c7b6SJohan Hedberg {
11991b51c7b6SJohan Hedberg 	struct hci_conn_hash *h = &hdev->conn_hash;
12001b51c7b6SJohan Hedberg 	struct hci_conn  *c;
12011b51c7b6SJohan Hedberg 
12021b51c7b6SJohan Hedberg 	rcu_read_lock();
12031b51c7b6SJohan Hedberg 
12041b51c7b6SJohan Hedberg 	list_for_each_entry_rcu(c, &h->list, list) {
12051b51c7b6SJohan Hedberg 		if (c->type != LE_LINK)
12061b51c7b6SJohan Hedberg 		       continue;
12071b51c7b6SJohan Hedberg 
12081b51c7b6SJohan Hedberg 		if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) {
12091b51c7b6SJohan Hedberg 			rcu_read_unlock();
12101b51c7b6SJohan Hedberg 			return c;
12111b51c7b6SJohan Hedberg 		}
12121b51c7b6SJohan Hedberg 	}
12131b51c7b6SJohan Hedberg 
12141b51c7b6SJohan Hedberg 	rcu_read_unlock();
12151b51c7b6SJohan Hedberg 
12161b51c7b6SJohan Hedberg 	return NULL;
12171b51c7b6SJohan Hedberg }
12181b51c7b6SJohan Hedberg 
121926afbd82SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
122026afbd82SLuiz Augusto von Dentz 							bdaddr_t *ba,
1221c14516faSLuiz Augusto von Dentz 							__u8 ba_type,
1222c14516faSLuiz Augusto von Dentz 							__u8 cig,
1223c14516faSLuiz Augusto von Dentz 							__u8 id)
122426afbd82SLuiz Augusto von Dentz {
122526afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
122626afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
122726afbd82SLuiz Augusto von Dentz 
122826afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
122926afbd82SLuiz Augusto von Dentz 
123026afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1231b5793de3SPauli Virtanen 		if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
123226afbd82SLuiz Augusto von Dentz 			continue;
123326afbd82SLuiz Augusto von Dentz 
1234c14516faSLuiz Augusto von Dentz 		/* Match CIG ID if set */
1235a07a95bcSLuiz Augusto von Dentz 		if (cig != c->iso_qos.ucast.cig)
1236c14516faSLuiz Augusto von Dentz 			continue;
1237c14516faSLuiz Augusto von Dentz 
1238c14516faSLuiz Augusto von Dentz 		/* Match CIS ID if set */
1239a07a95bcSLuiz Augusto von Dentz 		if (id != c->iso_qos.ucast.cis)
1240c14516faSLuiz Augusto von Dentz 			continue;
1241c14516faSLuiz Augusto von Dentz 
124271e95884SPauli Virtanen 		/* Match destination address if set */
124371e95884SPauli Virtanen 		if (!ba || (ba_type == c->dst_type && !bacmp(&c->dst, ba))) {
124426afbd82SLuiz Augusto von Dentz 			rcu_read_unlock();
124526afbd82SLuiz Augusto von Dentz 			return c;
124626afbd82SLuiz Augusto von Dentz 		}
124726afbd82SLuiz Augusto von Dentz 	}
124826afbd82SLuiz Augusto von Dentz 
124926afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
125026afbd82SLuiz Augusto von Dentz 
125126afbd82SLuiz Augusto von Dentz 	return NULL;
125226afbd82SLuiz Augusto von Dentz }
125326afbd82SLuiz Augusto von Dentz 
125426afbd82SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_cig(struct hci_dev *hdev,
125526afbd82SLuiz Augusto von Dentz 							__u8 handle)
125626afbd82SLuiz Augusto von Dentz {
125726afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
125826afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
125926afbd82SLuiz Augusto von Dentz 
126026afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
126126afbd82SLuiz Augusto von Dentz 
126226afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1263b5793de3SPauli Virtanen 		if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
126426afbd82SLuiz Augusto von Dentz 			continue;
126526afbd82SLuiz Augusto von Dentz 
12660fe8c8d0SIulia Tanasescu 		if (handle == c->iso_qos.ucast.cig) {
126726afbd82SLuiz Augusto von Dentz 			rcu_read_unlock();
126826afbd82SLuiz Augusto von Dentz 			return c;
126926afbd82SLuiz Augusto von Dentz 		}
127026afbd82SLuiz Augusto von Dentz 	}
127126afbd82SLuiz Augusto von Dentz 
127226afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
127326afbd82SLuiz Augusto von Dentz 
127426afbd82SLuiz Augusto von Dentz 	return NULL;
127526afbd82SLuiz Augusto von Dentz }
127626afbd82SLuiz Augusto von Dentz 
1277eca0ae4aSLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,
1278eca0ae4aSLuiz Augusto von Dentz 							__u8 handle)
1279eca0ae4aSLuiz Augusto von Dentz {
1280eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1281eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn  *c;
1282eca0ae4aSLuiz Augusto von Dentz 
1283eca0ae4aSLuiz Augusto von Dentz 	rcu_read_lock();
1284eca0ae4aSLuiz Augusto von Dentz 
1285eca0ae4aSLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1286eca0ae4aSLuiz Augusto von Dentz 		if (bacmp(&c->dst, BDADDR_ANY) || c->type != ISO_LINK)
1287eca0ae4aSLuiz Augusto von Dentz 			continue;
1288eca0ae4aSLuiz Augusto von Dentz 
12890fe8c8d0SIulia Tanasescu 		if (handle == c->iso_qos.bcast.big) {
1290eca0ae4aSLuiz Augusto von Dentz 			rcu_read_unlock();
1291eca0ae4aSLuiz Augusto von Dentz 			return c;
1292eca0ae4aSLuiz Augusto von Dentz 		}
1293eca0ae4aSLuiz Augusto von Dentz 	}
1294eca0ae4aSLuiz Augusto von Dentz 
1295eca0ae4aSLuiz Augusto von Dentz 	rcu_read_unlock();
1296eca0ae4aSLuiz Augusto von Dentz 
1297eca0ae4aSLuiz Augusto von Dentz 	return NULL;
1298eca0ae4aSLuiz Augusto von Dentz }
1299eca0ae4aSLuiz Augusto von Dentz 
1300f777d882SIulia Tanasescu static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst(struct hci_dev *hdev,
1301f777d882SIulia Tanasescu 							__u8 handle)
1302f777d882SIulia Tanasescu {
1303f777d882SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1304f777d882SIulia Tanasescu 	struct hci_conn  *c;
1305f777d882SIulia Tanasescu 
1306f777d882SIulia Tanasescu 	rcu_read_lock();
1307f777d882SIulia Tanasescu 
1308f777d882SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1309f777d882SIulia Tanasescu 		if (c->type != ISO_LINK)
1310f777d882SIulia Tanasescu 			continue;
1311f777d882SIulia Tanasescu 
1312fbdc4bc4SIulia Tanasescu 		if (handle != BT_ISO_QOS_BIG_UNSET && handle == c->iso_qos.bcast.big) {
1313f777d882SIulia Tanasescu 			rcu_read_unlock();
1314f777d882SIulia Tanasescu 			return c;
1315f777d882SIulia Tanasescu 		}
1316f777d882SIulia Tanasescu 	}
1317f777d882SIulia Tanasescu 
1318f777d882SIulia Tanasescu 	rcu_read_unlock();
1319f777d882SIulia Tanasescu 
1320f777d882SIulia Tanasescu 	return NULL;
1321f777d882SIulia Tanasescu }
1322f777d882SIulia Tanasescu 
1323fbdc4bc4SIulia Tanasescu static inline struct hci_conn *
132423417475SIulia Tanasescu hci_conn_hash_lookup_pa_sync_big_handle(struct hci_dev *hdev, __u8 big)
1325fbdc4bc4SIulia Tanasescu {
1326fbdc4bc4SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1327fbdc4bc4SIulia Tanasescu 	struct hci_conn  *c;
1328fbdc4bc4SIulia Tanasescu 
1329fbdc4bc4SIulia Tanasescu 	rcu_read_lock();
1330fbdc4bc4SIulia Tanasescu 
1331fbdc4bc4SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1332fbdc4bc4SIulia Tanasescu 		if (c->type != ISO_LINK ||
1333fbdc4bc4SIulia Tanasescu 			!test_bit(HCI_CONN_PA_SYNC, &c->flags))
1334fbdc4bc4SIulia Tanasescu 			continue;
1335fbdc4bc4SIulia Tanasescu 
1336fbdc4bc4SIulia Tanasescu 		if (c->iso_qos.bcast.big == big) {
1337fbdc4bc4SIulia Tanasescu 			rcu_read_unlock();
1338fbdc4bc4SIulia Tanasescu 			return c;
1339fbdc4bc4SIulia Tanasescu 		}
1340fbdc4bc4SIulia Tanasescu 	}
1341fbdc4bc4SIulia Tanasescu 	rcu_read_unlock();
1342fbdc4bc4SIulia Tanasescu 
1343fbdc4bc4SIulia Tanasescu 	return NULL;
1344fbdc4bc4SIulia Tanasescu }
1345fbdc4bc4SIulia Tanasescu 
134623417475SIulia Tanasescu static inline struct hci_conn *
134723417475SIulia Tanasescu hci_conn_hash_lookup_pa_sync_handle(struct hci_dev *hdev, __u16 sync_handle)
134823417475SIulia Tanasescu {
134923417475SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
135023417475SIulia Tanasescu 	struct hci_conn  *c;
135123417475SIulia Tanasescu 
135223417475SIulia Tanasescu 	rcu_read_lock();
135323417475SIulia Tanasescu 
135423417475SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
135523417475SIulia Tanasescu 		if (c->type != ISO_LINK ||
135623417475SIulia Tanasescu 			!test_bit(HCI_CONN_PA_SYNC, &c->flags))
135723417475SIulia Tanasescu 			continue;
135823417475SIulia Tanasescu 
135923417475SIulia Tanasescu 		if (c->sync_handle == sync_handle) {
136023417475SIulia Tanasescu 			rcu_read_unlock();
136123417475SIulia Tanasescu 			return c;
136223417475SIulia Tanasescu 		}
136323417475SIulia Tanasescu 	}
136423417475SIulia Tanasescu 	rcu_read_unlock();
136523417475SIulia Tanasescu 
136623417475SIulia Tanasescu 	return NULL;
136723417475SIulia Tanasescu }
136823417475SIulia Tanasescu 
13694c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
13704c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
13714c67bc74SMarcel Holtmann {
13724c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
13734c67bc74SMarcel Holtmann 	struct hci_conn  *c;
13744c67bc74SMarcel Holtmann 
1375bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1376bf4c6325SGustavo F. Padovan 
1377bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1378bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
1379bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
13804c67bc74SMarcel Holtmann 			return c;
13814c67bc74SMarcel Holtmann 		}
1382bf4c6325SGustavo F. Padovan 	}
1383bf4c6325SGustavo F. Padovan 
1384bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1385bf4c6325SGustavo F. Padovan 
13864c67bc74SMarcel Holtmann 	return NULL;
13874c67bc74SMarcel Holtmann }
13884c67bc74SMarcel Holtmann 
138926afbd82SLuiz Augusto von Dentz typedef void (*hci_conn_func_t)(struct hci_conn *conn, void *data);
139026afbd82SLuiz Augusto von Dentz static inline void hci_conn_hash_list_state(struct hci_dev *hdev,
139126afbd82SLuiz Augusto von Dentz 					    hci_conn_func_t func, __u8 type,
139226afbd82SLuiz Augusto von Dentz 					    __u16 state, void *data)
139326afbd82SLuiz Augusto von Dentz {
139426afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
139526afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
139626afbd82SLuiz Augusto von Dentz 
139726afbd82SLuiz Augusto von Dentz 	if (!func)
139826afbd82SLuiz Augusto von Dentz 		return;
139926afbd82SLuiz Augusto von Dentz 
140026afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
140126afbd82SLuiz Augusto von Dentz 
140226afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
140326afbd82SLuiz Augusto von Dentz 		if (c->type == type && c->state == state)
140426afbd82SLuiz Augusto von Dentz 			func(c, data);
140526afbd82SLuiz Augusto von Dentz 	}
140626afbd82SLuiz Augusto von Dentz 
140726afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
140826afbd82SLuiz Augusto von Dentz }
140926afbd82SLuiz Augusto von Dentz 
1410e7d9ab73SJakub Pawlowski static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev)
1411e7d9ab73SJakub Pawlowski {
1412e7d9ab73SJakub Pawlowski 	struct hci_conn_hash *h = &hdev->conn_hash;
1413e7d9ab73SJakub Pawlowski 	struct hci_conn  *c;
1414e7d9ab73SJakub Pawlowski 
1415e7d9ab73SJakub Pawlowski 	rcu_read_lock();
1416e7d9ab73SJakub Pawlowski 
1417e7d9ab73SJakub Pawlowski 	list_for_each_entry_rcu(c, &h->list, list) {
1418e7d9ab73SJakub Pawlowski 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1419e7d9ab73SJakub Pawlowski 		    !test_bit(HCI_CONN_SCANNING, &c->flags)) {
1420e7d9ab73SJakub Pawlowski 			rcu_read_unlock();
1421e7d9ab73SJakub Pawlowski 			return c;
1422e7d9ab73SJakub Pawlowski 		}
1423e7d9ab73SJakub Pawlowski 	}
1424e7d9ab73SJakub Pawlowski 
1425e7d9ab73SJakub Pawlowski 	rcu_read_unlock();
1426e7d9ab73SJakub Pawlowski 
1427e7d9ab73SJakub Pawlowski 	return NULL;
1428e7d9ab73SJakub Pawlowski }
1429e7d9ab73SJakub Pawlowski 
1430f8867016SLuiz Augusto von Dentz /* Returns true if an le connection is in the scanning state */
1431f8867016SLuiz Augusto von Dentz static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev)
1432f8867016SLuiz Augusto von Dentz {
1433f8867016SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1434f8867016SLuiz Augusto von Dentz 	struct hci_conn  *c;
1435f8867016SLuiz Augusto von Dentz 
1436f8867016SLuiz Augusto von Dentz 	rcu_read_lock();
1437f8867016SLuiz Augusto von Dentz 
1438f8867016SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1439f8867016SLuiz Augusto von Dentz 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1440f8867016SLuiz Augusto von Dentz 		    test_bit(HCI_CONN_SCANNING, &c->flags)) {
1441f8867016SLuiz Augusto von Dentz 			rcu_read_unlock();
1442f8867016SLuiz Augusto von Dentz 			return true;
1443f8867016SLuiz Augusto von Dentz 		}
1444f8867016SLuiz Augusto von Dentz 	}
1445f8867016SLuiz Augusto von Dentz 
1446f8867016SLuiz Augusto von Dentz 	rcu_read_unlock();
1447f8867016SLuiz Augusto von Dentz 
1448f8867016SLuiz Augusto von Dentz 	return false;
1449f8867016SLuiz Augusto von Dentz }
1450f8867016SLuiz Augusto von Dentz 
1451e3b679d5SJohan Hedberg int hci_disconnect(struct hci_conn *conn, __u8 reason);
14522dea632fSFrédéric Dalleau bool hci_setup_sync(struct hci_conn *conn, __u16 handle);
1453e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
145426afbd82SLuiz Augusto von Dentz bool hci_iso_setup_path(struct hci_conn *conn);
14557f74563eSPauli Virtanen int hci_le_create_cis_pending(struct hci_dev *hdev);
14567f74563eSPauli Virtanen int hci_conn_check_create_cis(struct hci_conn *conn);
14571da177e4SLinus Torvalds 
1458a5c4e309SJohan Hedberg struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
145984cb0143SZiyang Xuan 			      u8 role, u16 handle);
146084cb0143SZiyang Xuan struct hci_conn *hci_conn_add_unset(struct hci_dev *hdev, int type,
146184cb0143SZiyang Xuan 				    bdaddr_t *dst, u8 role);
1462a2ac591cSRuihan Li void hci_conn_del(struct hci_conn *conn);
14631da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
1464a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
14651da177e4SLinus Torvalds 
146673d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
14679472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan);
14682c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
146942c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
147073d80debSLuiz Augusto von Dentz 
1471f75113a2SJakub Pawlowski struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
1472f75113a2SJakub Pawlowski 				     u8 dst_type, u8 sec_level,
147376b13996SManish Mandlik 				     u16 conn_timeout,
147476b13996SManish Mandlik 				     enum conn_reasons conn_reason);
147504a6c589SAndre Guedes struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1476d850bf08SLuiz Augusto von Dentz 				u8 dst_type, bool dst_resolved, u8 sec_level,
14778e8b92eeSLuiz Augusto von Dentz 				u16 conn_timeout, u8 role);
147804a6c589SAndre Guedes struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
147976b13996SManish Mandlik 				 u8 sec_level, u8 auth_type,
148076b13996SManish Mandlik 				 enum conn_reasons conn_reason);
148110c62ddcSFrédéric Dalleau struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1482b2af264aSKiran K 				 __u16 setting, struct bt_codec *codec);
148326afbd82SLuiz Augusto von Dentz struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
148426afbd82SLuiz Augusto von Dentz 			      __u8 dst_type, struct bt_iso_qos *qos);
1485a0bfde16SIulia Tanasescu struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,
1486a0bfde16SIulia Tanasescu 			      struct bt_iso_qos *qos,
1487a0bfde16SIulia Tanasescu 			      __u8 base_len, __u8 *base);
148826afbd82SLuiz Augusto von Dentz struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
148926afbd82SLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos);
1490eca0ae4aSLuiz Augusto von Dentz struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
1491eca0ae4aSLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos,
1492eca0ae4aSLuiz Augusto von Dentz 				 __u8 data_len, __u8 *data);
1493eca0ae4aSLuiz Augusto von Dentz int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type,
14940fe8c8d0SIulia Tanasescu 		       __u8 sid, struct bt_iso_qos *qos);
1495fbdc4bc4SIulia Tanasescu int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
1496fbdc4bc4SIulia Tanasescu 			   struct bt_iso_qos *qos,
1497eca0ae4aSLuiz Augusto von Dentz 			   __u16 sync_handle, __u8 num_bis, __u8 bis[]);
1498e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
1499b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
1500e7cafc45SJohan Hedberg int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type,
1501e7cafc45SJohan Hedberg 		      bool initiator);
15028c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
15031da177e4SLinus Torvalds 
150414b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
15051da177e4SLinus Torvalds 
15069b3628d7SLuiz Augusto von Dentz void hci_conn_failed(struct hci_conn *conn, u8 status);
150716e3b642SLuiz Augusto von Dentz u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle);
150806c053fbSAndre Guedes 
15098d12356fSDavid Herrmann /*
15108d12356fSDavid Herrmann  * hci_conn_get() and hci_conn_put() are used to control the life-time of an
15118d12356fSDavid Herrmann  * "hci_conn" object. They do not guarantee that the hci_conn object is running,
15128d12356fSDavid Herrmann  * working or anything else. They just guarantee that the object is available
15138d12356fSDavid Herrmann  * and can be dereferenced. So you can use its locks, local variables and any
15148d12356fSDavid Herrmann  * other constant data.
15158d12356fSDavid Herrmann  * Before accessing runtime data, you _must_ lock the object and then check that
15168d12356fSDavid Herrmann  * it is still running. As soon as you release the locks, the connection might
15178d12356fSDavid Herrmann  * get dropped, though.
15188d12356fSDavid Herrmann  *
15198d12356fSDavid Herrmann  * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control
15208d12356fSDavid Herrmann  * how long the underlying connection is held. So every channel that runs on the
15218d12356fSDavid Herrmann  * hci_conn object calls this to prevent the connection from disappearing. As
15228d12356fSDavid Herrmann  * long as you hold a device, you must also guarantee that you have a valid
15238d12356fSDavid Herrmann  * reference to the device via hci_conn_get() (or the initial reference from
15248d12356fSDavid Herrmann  * hci_conn_add()).
15258d12356fSDavid Herrmann  * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't
15268d12356fSDavid Herrmann  * break because nobody cares for that. But this means, we cannot use
15278d12356fSDavid Herrmann  * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
15288d12356fSDavid Herrmann  */
15298d12356fSDavid Herrmann 
153051bb8457SJohan Hedberg static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
15318d12356fSDavid Herrmann {
15328d12356fSDavid Herrmann 	get_device(&conn->dev);
153351bb8457SJohan Hedberg 	return conn;
15348d12356fSDavid Herrmann }
15358d12356fSDavid Herrmann 
15368d12356fSDavid Herrmann static inline void hci_conn_put(struct hci_conn *conn)
15378d12356fSDavid Herrmann {
15388d12356fSDavid Herrmann 	put_device(&conn->dev);
15398d12356fSDavid Herrmann }
15408d12356fSDavid Herrmann 
154106149746SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hold(struct hci_conn *conn)
15421da177e4SLinus Torvalds {
154371becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
154438b3fef1SAndrei Emeltchenko 
15451da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
15462f304d1eSAndre Guedes 	cancel_delayed_work(&conn->disc_work);
154706149746SLuiz Augusto von Dentz 
154806149746SLuiz Augusto von Dentz 	return conn;
15491da177e4SLinus Torvalds }
15501da177e4SLinus Torvalds 
155176a68ba0SDavid Herrmann static inline void hci_conn_drop(struct hci_conn *conn)
15521da177e4SLinus Torvalds {
155371becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
155438b3fef1SAndrei Emeltchenko 
15551da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
155604837f64SMarcel Holtmann 		unsigned long timeo;
1557716e4ab5SAndrei Emeltchenko 
1558716e4ab5SAndrei Emeltchenko 		switch (conn->type) {
1559716e4ab5SAndrei Emeltchenko 		case ACL_LINK:
1560716e4ab5SAndrei Emeltchenko 		case LE_LINK:
1561a74a84f6SJohan Hedberg 			cancel_delayed_work(&conn->idle_work);
15626ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
15635f246e89SAndrei Emeltchenko 				timeo = conn->disc_timeout;
156404837f64SMarcel Holtmann 				if (!conn->out)
1565052b30b0SMarcel Holtmann 					timeo *= 2;
15665a9d0a3fSWaldemar Rymarkiewicz 			} else {
1567eb78d7e5SJohan Hedberg 				timeo = 0;
15685a9d0a3fSWaldemar Rymarkiewicz 			}
1569716e4ab5SAndrei Emeltchenko 			break;
1570716e4ab5SAndrei Emeltchenko 
1571716e4ab5SAndrei Emeltchenko 		case AMP_LINK:
1572716e4ab5SAndrei Emeltchenko 			timeo = conn->disc_timeout;
1573716e4ab5SAndrei Emeltchenko 			break;
1574716e4ab5SAndrei Emeltchenko 
1575716e4ab5SAndrei Emeltchenko 		default:
1576eb78d7e5SJohan Hedberg 			timeo = 0;
1577716e4ab5SAndrei Emeltchenko 			break;
15785a9d0a3fSWaldemar Rymarkiewicz 		}
1579716e4ab5SAndrei Emeltchenko 
15802f304d1eSAndre Guedes 		cancel_delayed_work(&conn->disc_work);
158119c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
15821931782bSVinicius Costa Gomes 				   &conn->disc_work, timeo);
15831da177e4SLinus Torvalds 	}
15841da177e4SLinus Torvalds }
15851da177e4SLinus Torvalds 
15861da177e4SLinus Torvalds /* ----- HCI Devices ----- */
1587dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
15881da177e4SLinus Torvalds {
1589376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15902c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1591376261aeSAndrei Emeltchenko 
15924c724c71SDavid Herrmann 	put_device(&d->dev);
1593010666a1SDavid Herrmann }
15941da177e4SLinus Torvalds 
1595dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
15961da177e4SLinus Torvalds {
1597376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15982c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1599376261aeSAndrei Emeltchenko 
16004c724c71SDavid Herrmann 	get_device(&d->dev);
16011da177e4SLinus Torvalds 	return d;
16021da177e4SLinus Torvalds }
16031da177e4SLinus Torvalds 
160409fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
160509fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
16061da177e4SLinus Torvalds 
1607aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev)
16083dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev)
1609aa2b86d7SDavid Herrmann 
1610155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev)
1611155961e8SDavid Herrmann {
1612155961e8SDavid Herrmann 	return dev_get_drvdata(&hdev->dev);
1613155961e8SDavid Herrmann }
1614155961e8SDavid Herrmann 
1615155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
1616155961e8SDavid Herrmann {
1617155961e8SDavid Herrmann 	dev_set_drvdata(&hdev->dev, data);
1618155961e8SDavid Herrmann }
1619155961e8SDavid Herrmann 
16206ec56613STedd Ho-Jeong An static inline void *hci_get_priv(struct hci_dev *hdev)
16216ec56613STedd Ho-Jeong An {
16226ec56613STedd Ho-Jeong An 	return (char *)hdev + sizeof(*hdev);
16236ec56613STedd Ho-Jeong An }
16246ec56613STedd Ho-Jeong An 
16251da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
162639385cb5SJohan Hedberg struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
16271da177e4SLinus Torvalds 
16286ec56613STedd Ho-Jeong An struct hci_dev *hci_alloc_dev_priv(int sizeof_priv);
16296ec56613STedd Ho-Jeong An 
16306ec56613STedd Ho-Jeong An static inline struct hci_dev *hci_alloc_dev(void)
16316ec56613STedd Ho-Jeong An {
16326ec56613STedd Ho-Jeong An 	return hci_alloc_dev_priv(0);
16336ec56613STedd Ho-Jeong An }
16346ec56613STedd Ho-Jeong An 
16351da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
16361da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
163759735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
163858ce6d5bSTetsuo Handa void hci_release_dev(struct hci_dev *hdev);
1639359ee4f8SAbhishek Pandit-Subedi int hci_register_suspend_notifier(struct hci_dev *hdev);
1640359ee4f8SAbhishek Pandit-Subedi int hci_unregister_suspend_notifier(struct hci_dev *hdev);
16411da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
16421da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
164375e0569fSMarcel Holtmann int hci_reset_dev(struct hci_dev *hdev);
1644f962fe32SMarcel Holtmann int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
1645f962fe32SMarcel Holtmann int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
16461aabbbceSNicolas Iooss __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
16471aabbbceSNicolas Iooss __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
1648145373cbSMiao-chen Chou 
1649145373cbSMiao-chen Chou static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
1650145373cbSMiao-chen Chou {
1651145373cbSMiao-chen Chou #if IS_ENABLED(CONFIG_BT_MSFTEXT)
1652145373cbSMiao-chen Chou 	hdev->msft_opcode = opcode;
1653145373cbSMiao-chen Chou #endif
1654145373cbSMiao-chen Chou }
1655145373cbSMiao-chen Chou 
1656f67743f9SMarcel Holtmann static inline void hci_set_aosp_capable(struct hci_dev *hdev)
1657f67743f9SMarcel Holtmann {
1658f67743f9SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_AOSPEXT)
1659f67743f9SMarcel Holtmann 	hdev->aosp_capable = true;
1660f67743f9SMarcel Holtmann #endif
1661f67743f9SMarcel Holtmann }
1662f67743f9SMarcel Holtmann 
16639695ef87SAbhishek Pandit-Subedi static inline void hci_devcd_setup(struct hci_dev *hdev)
16649695ef87SAbhishek Pandit-Subedi {
16659695ef87SAbhishek Pandit-Subedi #ifdef CONFIG_DEV_COREDUMP
16669695ef87SAbhishek Pandit-Subedi 	INIT_WORK(&hdev->dump.dump_rx, hci_devcd_rx);
16679695ef87SAbhishek Pandit-Subedi 	INIT_DELAYED_WORK(&hdev->dump.dump_timeout, hci_devcd_timeout);
16689695ef87SAbhishek Pandit-Subedi 	skb_queue_head_init(&hdev->dump.dump_q);
16699695ef87SAbhishek Pandit-Subedi #endif
16709695ef87SAbhishek Pandit-Subedi }
16719695ef87SAbhishek Pandit-Subedi 
16721da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
16731da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
16746b3cc1dbSSimon Fels int hci_dev_do_close(struct hci_dev *hdev);
16751da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
16761da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
16771da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
16781da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
16791da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
16801da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
16811da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
168240be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
16831da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
16841da177e4SLinus Torvalds 
1685dcc36c16SJohan Hedberg struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list,
1686b9ee0a78SMarcel Holtmann 					   bdaddr_t *bdaddr, u8 type);
1687b950aa88SAnkit Navik struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk(
1688b950aa88SAnkit Navik 				    struct list_head *list, bdaddr_t *bdaddr,
1689b950aa88SAnkit Navik 				    u8 type);
16908baaa403SAbhishek Pandit-Subedi struct bdaddr_list_with_flags *
16918baaa403SAbhishek Pandit-Subedi hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16928baaa403SAbhishek Pandit-Subedi 				  u8 type);
1693dcc36c16SJohan Hedberg int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1694b950aa88SAnkit Navik int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1695b950aa88SAnkit Navik 				 u8 type, u8 *peer_irk, u8 *local_irk);
16968baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16978baaa403SAbhishek Pandit-Subedi 				   u8 type, u32 flags);
1698dcc36c16SJohan Hedberg int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1699b950aa88SAnkit Navik int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1700b950aa88SAnkit Navik 				 u8 type);
17018baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr,
17028baaa403SAbhishek Pandit-Subedi 				   u8 type);
1703dcc36c16SJohan Hedberg void hci_bdaddr_list_clear(struct list_head *list);
1704d2ab0ac1SMarcel Holtmann 
170515819a70SAndre Guedes struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
170615819a70SAndre Guedes 					       bdaddr_t *addr, u8 addr_type);
170751d167c0SMarcel Holtmann struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
170851d167c0SMarcel Holtmann 					    bdaddr_t *addr, u8 addr_type);
170915819a70SAndre Guedes void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
171055af49a8SJohan Hedberg void hci_conn_params_clear_disabled(struct hci_dev *hdev);
1711195ef75eSPauli Virtanen void hci_conn_params_free(struct hci_conn_params *param);
171215819a70SAndre Guedes 
1713195ef75eSPauli Virtanen void hci_pend_le_list_del_init(struct hci_conn_params *param);
1714195ef75eSPauli Virtanen void hci_pend_le_list_add(struct hci_conn_params *param,
1715195ef75eSPauli Virtanen 			  struct list_head *list);
1716501f8827SJohan Hedberg struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
1717501f8827SJohan Hedberg 						  bdaddr_t *addr,
1718501f8827SJohan Hedberg 						  u8 addr_type);
171977a77a30SAndre Guedes 
172035f7498aSJohan Hedberg void hci_uuids_clear(struct hci_dev *hdev);
17212aeb9a1aSJohan Hedberg 
172235f7498aSJohan Hedberg void hci_link_keys_clear(struct hci_dev *hdev);
172355ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
1724567fa2aaSJohan Hedberg struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
17257652ff6aSJohan Hedberg 				  bdaddr_t *bdaddr, u8 *val, u8 type,
17267652ff6aSJohan Hedberg 				  u8 pin_len, bool *persistent);
1727ca9142b8SJohan Hedberg struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
172835d70271SJohan Hedberg 			    u8 addr_type, u8 type, u8 authenticated,
1729fe39c7b2SMarcel Holtmann 			    u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
1730f3a73d97SJohan Hedberg struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1731e804d25dSJohan Hedberg 			     u8 addr_type, u8 role);
1732e0b2b27eSJohan Hedberg int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
173335f7498aSJohan Hedberg void hci_smp_ltks_clear(struct hci_dev *hdev);
173455ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
173555ed8ca1SJohan Hedberg 
1736970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa);
1737970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1738970c4e46SJohan Hedberg 				     u8 addr_type);
1739ca9142b8SJohan Hedberg struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1740ca9142b8SJohan Hedberg 			    u8 addr_type, u8 val[16], bdaddr_t *rpa);
1741a7ec7338SJohan Hedberg void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
1742600a8749SAlain Michaud bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]);
1743600a8749SAlain Michaud void hci_blocked_keys_clear(struct hci_dev *hdev);
1744970c4e46SJohan Hedberg void hci_smp_irks_clear(struct hci_dev *hdev);
1745970c4e46SJohan Hedberg 
174655e76b38SJohan Hedberg bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
174755e76b38SJohan Hedberg 
174835f7498aSJohan Hedberg void hci_remote_oob_data_clear(struct hci_dev *hdev);
17492763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
17506928a924SJohan Hedberg 					  bdaddr_t *bdaddr, u8 bdaddr_type);
17510798872eSMarcel Holtmann int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17526928a924SJohan Hedberg 			    u8 bdaddr_type, u8 *hash192, u8 *rand192,
175338da1703SJohan Hedberg 			    u8 *hash256, u8 *rand256);
17546928a924SJohan Hedberg int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17556928a924SJohan Hedberg 			       u8 bdaddr_type);
17562763eda6SSzymon Janc 
1757d2609b34SFlorian Grandel void hci_adv_instances_clear(struct hci_dev *hdev);
1758d2609b34SFlorian Grandel struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance);
1759d2609b34SFlorian Grandel struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance);
1760eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,
1761eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u16 adv_data_len, u8 *adv_data,
1762d2609b34SFlorian Grandel 				      u16 scan_rsp_len, u8 *scan_rsp_data,
17639bf9f4b6SDaniel Winkler 				      u16 timeout, u16 duration, s8 tx_power,
1764b338d917SBrian Gix 				      u32 min_interval, u32 max_interval,
1765b338d917SBrian Gix 				      u8 mesh_handle);
1766eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance,
1767eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u8 data_len, u8 *data,
1768eca0ae4aSLuiz Augusto von Dentz 				      u32 min_interval, u32 max_interval);
176931aab5c2SDaniel Winkler int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
177031aab5c2SDaniel Winkler 			 u16 adv_data_len, u8 *adv_data,
177131aab5c2SDaniel Winkler 			 u16 scan_rsp_len, u8 *scan_rsp_data);
1772d2609b34SFlorian Grandel int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);
1773a73c046aSJaganath Kanakkassery void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
177401ce70b0SLuiz Augusto von Dentz u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance);
177501ce70b0SLuiz Augusto von Dentz bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance);
1776d2609b34SFlorian Grandel 
1777e5e1e7fdSMiao-chen Chou void hci_adv_monitors_clear(struct hci_dev *hdev);
177866bd095aSArchie Pusaka void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
1779b747a836SManish Mandlik int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
17807cf5c297SManish Mandlik int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle);
17817cf5c297SManish Mandlik int hci_remove_all_adv_monitor(struct hci_dev *hdev);
17828208f5a9SMiao-chen Chou bool hci_is_adv_monitoring(struct hci_dev *hdev);
1783a2a4dedfSArchie Pusaka int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev);
1784e5e1e7fdSMiao-chen Chou 
17851da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
17861da177e4SLinus Torvalds 
17870ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
1788a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
1789b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
1790b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
17911da177e4SLinus Torvalds 
17926935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
1793294d749bSKiran K #define GET_HCIDEV_DEV(hdev) ((hdev)->dev.parent)
17941da177e4SLinus Torvalds 
17951da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
1796cad718edSJohan Hedberg #define lmp_encrypt_capable(dev)   ((dev)->features[0][0] & LMP_ENCRYPT)
1797cad718edSJohan Hedberg #define lmp_rswitch_capable(dev)   ((dev)->features[0][0] & LMP_RSWITCH)
1798cad718edSJohan Hedberg #define lmp_hold_capable(dev)      ((dev)->features[0][0] & LMP_HOLD)
1799cad718edSJohan Hedberg #define lmp_sniff_capable(dev)     ((dev)->features[0][0] & LMP_SNIFF)
1800cad718edSJohan Hedberg #define lmp_park_capable(dev)      ((dev)->features[0][1] & LMP_PARK)
1801cad718edSJohan Hedberg #define lmp_inq_rssi_capable(dev)  ((dev)->features[0][3] & LMP_RSSI_INQ)
1802cad718edSJohan Hedberg #define lmp_esco_capable(dev)      ((dev)->features[0][3] & LMP_ESCO)
1803cad718edSJohan Hedberg #define lmp_bredr_capable(dev)     (!((dev)->features[0][4] & LMP_NO_BREDR))
1804cad718edSJohan Hedberg #define lmp_le_capable(dev)        ((dev)->features[0][4] & LMP_LE)
1805cad718edSJohan Hedberg #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR)
1806cad718edSJohan Hedberg #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC)
18078b1c324cSYu Liu #define lmp_esco_2m_capable(dev)   ((dev)->features[0][5] & LMP_EDR_ESCO_2M)
1808cad718edSJohan Hedberg #define lmp_ext_inq_capable(dev)   ((dev)->features[0][6] & LMP_EXT_INQ)
1809cad718edSJohan Hedberg #define lmp_le_br_capable(dev)     (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR))
1810cad718edSJohan Hedberg #define lmp_ssp_capable(dev)       ((dev)->features[0][6] & LMP_SIMPLE_PAIR)
1811cad718edSJohan Hedberg #define lmp_no_flush_capable(dev)  ((dev)->features[0][6] & LMP_NO_FLUSH)
1812cad718edSJohan Hedberg #define lmp_lsto_capable(dev)      ((dev)->features[0][7] & LMP_LSTO)
1813cad718edSJohan Hedberg #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
1814cad718edSJohan Hedberg #define lmp_ext_feat_capable(dev)  ((dev)->features[0][7] & LMP_EXTFEATURES)
181507a5c61eSFrédéric Dalleau #define lmp_transp_capable(dev)    ((dev)->features[0][2] & LMP_TRANSPARENT)
18165075b972SJaganath Kanakkassery #define lmp_edr_2m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_2M)
18175075b972SJaganath Kanakkassery #define lmp_edr_3m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_3M)
18185075b972SJaganath Kanakkassery #define lmp_edr_3slot_capable(dev) ((dev)->features[0][4] & LMP_EDR_3SLOT)
18195075b972SJaganath Kanakkassery #define lmp_edr_5slot_capable(dev) ((dev)->features[0][5] & LMP_EDR_5SLOT)
18201da177e4SLinus Torvalds 
1821eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
18226397729bSArchie Pusaka #define lmp_cpb_central_capable(dev) ((dev)->features[2][0] & LMP_CPB_CENTRAL)
18236397729bSArchie Pusaka #define lmp_cpb_peripheral_capable(dev) ((dev)->features[2][0] & LMP_CPB_PERIPHERAL)
182453b834d2SMarcel Holtmann #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN)
182553b834d2SMarcel Holtmann #define lmp_sync_scan_capable(dev)  ((dev)->features[2][0] & LMP_SYNC_SCAN)
1826d5991585SMarcel Holtmann #define lmp_sc_capable(dev)         ((dev)->features[2][1] & LMP_SC)
1827d5991585SMarcel Holtmann #define lmp_ping_capable(dev)       ((dev)->features[2][1] & LMP_PING)
182853b834d2SMarcel Holtmann 
182953b834d2SMarcel Holtmann /* ----- Host capabilities ----- */
1830cad718edSJohan Hedberg #define lmp_host_ssp_capable(dev)  ((dev)->features[1][0] & LMP_HOST_SSP)
1831d5991585SMarcel Holtmann #define lmp_host_sc_capable(dev)   ((dev)->features[1][0] & LMP_HOST_SC)
1832cad718edSJohan Hedberg #define lmp_host_le_capable(dev)   (!!((dev)->features[1][0] & LMP_HOST_LE))
1833cad718edSJohan Hedberg #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
1834eead27daSAndre Guedes 
1835d7a5a11dSMarcel Holtmann #define hdev_is_powered(dev)   (test_bit(HCI_UP, &(dev)->flags) && \
1836d7a5a11dSMarcel Holtmann 				!hci_dev_test_flag(dev, HCI_AUTO_OFF))
183705b3c3e7SMarcel Holtmann #define bredr_sc_enabled(dev)  (lmp_sc_capable(dev) && \
1838d7a5a11dSMarcel Holtmann 				hci_dev_test_flag(dev, HCI_SC_ENABLED))
1839c45074d6SLuiz Augusto von Dentz #define rpa_valid(dev)         (bacmp(&dev->rpa, BDADDR_ANY) && \
1840c45074d6SLuiz Augusto von Dentz 				!hci_dev_test_flag(dev, HCI_RPA_EXPIRED))
1841c45074d6SLuiz Augusto von Dentz #define adv_rpa_valid(adv)     (bacmp(&adv->random_addr, BDADDR_ANY) && \
1842c45074d6SLuiz Augusto von Dentz 				!adv->rpa_expired)
1843432df05eSJohan Hedberg 
184445bdd86eSJaganath Kanakkassery #define scan_1m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_1M) || \
184545bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_1M))
184645bdd86eSJaganath Kanakkassery 
1847288c9022SLuiz Augusto von Dentz #define le_2m_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_2M))
1848288c9022SLuiz Augusto von Dentz 
184945bdd86eSJaganath Kanakkassery #define scan_2m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_2M) || \
185045bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_2M))
185145bdd86eSJaganath Kanakkassery 
1852253f3399SLuiz Augusto von Dentz #define le_coded_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_CODED) && \
1853253f3399SLuiz Augusto von Dentz 			       !test_bit(HCI_QUIRK_BROKEN_LE_CODED, \
1854253f3399SLuiz Augusto von Dentz 					 &(dev)->quirks))
1855288c9022SLuiz Augusto von Dentz 
185645bdd86eSJaganath Kanakkassery #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
185745bdd86eSJaganath Kanakkassery 			 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
185845bdd86eSJaganath Kanakkassery 
1859ad383c2cSLuiz Augusto von Dentz #define ll_privacy_capable(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1860ad383c2cSLuiz Augusto von Dentz 
1861e1d57235SMarcel Holtmann /* Use LL Privacy based address resolution if supported */
1862ad383c2cSLuiz Augusto von Dentz #define use_ll_privacy(dev) (ll_privacy_capable(dev) && \
1863ad383c2cSLuiz Augusto von Dentz 			     hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY))
1864e1d57235SMarcel Holtmann 
18656126ffabSLuiz Augusto von Dentz #define privacy_mode_capable(dev) (use_ll_privacy(dev) && \
18666126ffabSLuiz Augusto von Dentz 				   (hdev->commands[39] & 0x04))
18676126ffabSLuiz Augusto von Dentz 
186805abad85SLuiz Augusto von Dentz /* Use enhanced synchronous connection if command is supported and its quirk
186905abad85SLuiz Augusto von Dentz  * has not been set.
187005abad85SLuiz Augusto von Dentz  */
187105abad85SLuiz Augusto von Dentz #define enhanced_sync_conn_capable(dev) \
187205abad85SLuiz Augusto von Dentz 	(((dev)->commands[29] & 0x08) && \
187305abad85SLuiz Augusto von Dentz 	 !test_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &(dev)->quirks))
1874b2af264aSKiran K 
1875a2344b9eSJaganath Kanakkassery /* Use ext scanning if set ext scan param and ext scan enable is supported */
1876a2344b9eSJaganath Kanakkassery #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
1877392fca35SSven Peter 			   ((dev)->commands[37] & 0x40) && \
1878392fca35SSven Peter 			   !test_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &(dev)->quirks))
1879392fca35SSven Peter 
18804d94f95dSJaganath Kanakkassery /* Use ext create connection if command is supported */
18814d94f95dSJaganath Kanakkassery #define use_ext_conn(dev) ((dev)->commands[37] & 0x80)
1882a2344b9eSJaganath Kanakkassery 
18836b49bcb4SJaganath Kanakkassery /* Extended advertising support */
18846b49bcb4SJaganath Kanakkassery #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
18856b49bcb4SJaganath Kanakkassery 
1886112b5090SLuiz Augusto von Dentz /* Maximum advertising length */
1887112b5090SLuiz Augusto von Dentz #define max_adv_len(dev) \
1888112b5090SLuiz Augusto von Dentz 	(ext_adv_capable(dev) ? HCI_MAX_EXT_AD_LENGTH : HCI_MAX_AD_LENGTH)
1889112b5090SLuiz Augusto von Dentz 
1890a56a1138SLuiz Augusto von Dentz /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1789:
1891a56a1138SLuiz Augusto von Dentz  *
1892a56a1138SLuiz Augusto von Dentz  * C24: Mandatory if the LE Controller supports Connection State and either
1893a56a1138SLuiz Augusto von Dentz  * LE Feature (LL Privacy) or LE Feature (Extended Advertising) is supported
1894a56a1138SLuiz Augusto von Dentz  */
1895a56a1138SLuiz Augusto von Dentz #define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \
1896a56a1138SLuiz Augusto von Dentz 					 ext_adv_capable(dev))
1897a56a1138SLuiz Augusto von Dentz 
1898eca0ae4aSLuiz Augusto von Dentz /* Periodic advertising support */
1899eca0ae4aSLuiz Augusto von Dentz #define per_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_PERIODIC_ADV))
1900eca0ae4aSLuiz Augusto von Dentz 
1901eca0ae4aSLuiz Augusto von Dentz /* CIS Master/Slave and BIS support */
1902eca0ae4aSLuiz Augusto von Dentz #define iso_capable(dev) (cis_capable(dev) || bis_capable(dev))
190326afbd82SLuiz Augusto von Dentz #define cis_capable(dev) \
190426afbd82SLuiz Augusto von Dentz 	(cis_central_capable(dev) || cis_peripheral_capable(dev))
190526afbd82SLuiz Augusto von Dentz #define cis_central_capable(dev) \
190626afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_CENTRAL)
190726afbd82SLuiz Augusto von Dentz #define cis_peripheral_capable(dev) \
190826afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_PERIPHERAL)
1909eca0ae4aSLuiz Augusto von Dentz #define bis_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_BROADCASTER)
1910ae753361SClaudia Draghicescu #define sync_recv_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_SYNC_RECEIVER)
191126afbd82SLuiz Augusto von Dentz 
1912ffcb0a44SSven Peter #define mws_transport_config_capable(dev) (((dev)->commands[30] & 0x08) && \
1913ffcb0a44SSven Peter 	(!test_bit(HCI_QUIRK_BROKEN_MWS_TRANSPORT_CONFIG, &(dev)->quirks)))
1914ffcb0a44SSven Peter 
19151da177e4SLinus Torvalds /* ----- HCI protocols ----- */
191620714bfeSFrédéric Dalleau #define HCI_PROTO_DEFER             0x01
191720714bfeSFrédéric Dalleau 
19185a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
191920714bfeSFrédéric Dalleau 					__u8 type, __u8 *flags)
19201da177e4SLinus Torvalds {
1921686ebf28SUlisses Furquim 	switch (type) {
1922686ebf28SUlisses Furquim 	case ACL_LINK:
1923686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
19241da177e4SLinus Torvalds 
1925686ebf28SUlisses Furquim 	case SCO_LINK:
1926686ebf28SUlisses Furquim 	case ESCO_LINK:
192720714bfeSFrédéric Dalleau 		return sco_connect_ind(hdev, bdaddr, flags);
19281da177e4SLinus Torvalds 
192926afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
1930ccf74f23SLuiz Augusto von Dentz 		return iso_connect_ind(hdev, bdaddr, flags);
193126afbd82SLuiz Augusto von Dentz 
1932686ebf28SUlisses Furquim 	default:
1933686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
1934686ebf28SUlisses Furquim 		return -EINVAL;
1935686ebf28SUlisses Furquim 	}
19361da177e4SLinus Torvalds }
19371da177e4SLinus Torvalds 
19382950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
19392950f21aSMarcel Holtmann {
1940686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
1941686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
19422950f21aSMarcel Holtmann 
1943686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
19442950f21aSMarcel Holtmann }
19452950f21aSMarcel Holtmann 
19461da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
19471da177e4SLinus Torvalds struct hci_cb {
19481da177e4SLinus Torvalds 	struct list_head list;
19491da177e4SLinus Torvalds 
19501da177e4SLinus Torvalds 	char *name;
19511da177e4SLinus Torvalds 
1952539c496dSJohan Hedberg 	void (*connect_cfm)	(struct hci_conn *conn, __u8 status);
19533a6d576bSJohan Hedberg 	void (*disconn_cfm)	(struct hci_conn *conn, __u8 status);
19545a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
19555a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
19561da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
19571da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
19581da177e4SLinus Torvalds };
19591da177e4SLinus Torvalds 
1960539c496dSJohan Hedberg static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status)
1961539c496dSJohan Hedberg {
1962539c496dSJohan Hedberg 	struct hci_cb *cb;
1963539c496dSJohan Hedberg 
1964539c496dSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
1965539c496dSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
1966539c496dSJohan Hedberg 		if (cb->connect_cfm)
1967539c496dSJohan Hedberg 			cb->connect_cfm(conn, status);
1968539c496dSJohan Hedberg 	}
1969539c496dSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
1970539c496dSJohan Hedberg 
1971539c496dSJohan Hedberg 	if (conn->connect_cfm_cb)
1972539c496dSJohan Hedberg 		conn->connect_cfm_cb(conn, status);
1973539c496dSJohan Hedberg }
1974539c496dSJohan Hedberg 
19753a6d576bSJohan Hedberg static inline void hci_disconn_cfm(struct hci_conn *conn, __u8 reason)
19763a6d576bSJohan Hedberg {
19773a6d576bSJohan Hedberg 	struct hci_cb *cb;
19783a6d576bSJohan Hedberg 
19793a6d576bSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
19803a6d576bSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
19813a6d576bSJohan Hedberg 		if (cb->disconn_cfm)
19823a6d576bSJohan Hedberg 			cb->disconn_cfm(conn, reason);
19833a6d576bSJohan Hedberg 	}
19843a6d576bSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
19853a6d576bSJohan Hedberg 
19863a6d576bSJohan Hedberg 	if (conn->disconn_cfm_cb)
19873a6d576bSJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
19883a6d576bSJohan Hedberg }
19893a6d576bSJohan Hedberg 
19901da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
19911da177e4SLinus Torvalds {
1992711584eaSDenis Kirjanov 	struct hci_cb *cb;
19938c1b2355SMarcel Holtmann 	__u8 encrypt;
19941da177e4SLinus Torvalds 
199551a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
19968c1b2355SMarcel Holtmann 		return;
19978c1b2355SMarcel Holtmann 
19984dae2798SJohan Hedberg 	encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
19998c1b2355SMarcel Holtmann 
2000fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2001711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20028c1b2355SMarcel Holtmann 		if (cb->security_cfm)
20038c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
20041da177e4SLinus Torvalds 	}
2005fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
2006354fe804SJohan Hedberg 
2007354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
2008354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
20091da177e4SLinus Torvalds }
20101da177e4SLinus Torvalds 
20113ca44c16SLuiz Augusto von Dentz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)
20121da177e4SLinus Torvalds {
2013711584eaSDenis Kirjanov 	struct hci_cb *cb;
20143ca44c16SLuiz Augusto von Dentz 	__u8 encrypt;
20153ca44c16SLuiz Augusto von Dentz 
20163ca44c16SLuiz Augusto von Dentz 	if (conn->state == BT_CONFIG) {
2017339ddaa6SPatrick Steinhardt 		if (!status)
20183ca44c16SLuiz Augusto von Dentz 			conn->state = BT_CONNECTED;
20193ca44c16SLuiz Augusto von Dentz 
20203ca44c16SLuiz Augusto von Dentz 		hci_connect_cfm(conn, status);
20213ca44c16SLuiz Augusto von Dentz 		hci_conn_drop(conn);
20223ca44c16SLuiz Augusto von Dentz 		return;
20233ca44c16SLuiz Augusto von Dentz 	}
20243ca44c16SLuiz Augusto von Dentz 
20253ca44c16SLuiz Augusto von Dentz 	if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
20263ca44c16SLuiz Augusto von Dentz 		encrypt = 0x00;
20273ca44c16SLuiz Augusto von Dentz 	else if (test_bit(HCI_CONN_AES_CCM, &conn->flags))
20283ca44c16SLuiz Augusto von Dentz 		encrypt = 0x02;
20293ca44c16SLuiz Augusto von Dentz 	else
20303ca44c16SLuiz Augusto von Dentz 		encrypt = 0x01;
20311da177e4SLinus Torvalds 
20328746f135SLuiz Augusto von Dentz 	if (!status) {
2033435fef20SMarcel Holtmann 		if (conn->sec_level == BT_SECURITY_SDP)
2034435fef20SMarcel Holtmann 			conn->sec_level = BT_SECURITY_LOW;
2035435fef20SMarcel Holtmann 
203688167aedSVinicius Costa Gomes 		if (conn->pending_sec_level > conn->sec_level)
203788167aedSVinicius Costa Gomes 			conn->sec_level = conn->pending_sec_level;
20388746f135SLuiz Augusto von Dentz 	}
203988167aedSVinicius Costa Gomes 
2040fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2041711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20428c1b2355SMarcel Holtmann 		if (cb->security_cfm)
20438c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
20441da177e4SLinus Torvalds 	}
2045fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
2046354fe804SJohan Hedberg 
2047354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
2048354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
20491da177e4SLinus Torvalds }
20501da177e4SLinus Torvalds 
20511da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
20521da177e4SLinus Torvalds {
2053711584eaSDenis Kirjanov 	struct hci_cb *cb;
20541da177e4SLinus Torvalds 
2055fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2056711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20571da177e4SLinus Torvalds 		if (cb->key_change_cfm)
20581da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
20591da177e4SLinus Torvalds 	}
2060fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20611da177e4SLinus Torvalds }
20621da177e4SLinus Torvalds 
20635a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
20645a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
20651da177e4SLinus Torvalds {
2066711584eaSDenis Kirjanov 	struct hci_cb *cb;
20671da177e4SLinus Torvalds 
2068fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2069711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20701da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
20711da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
20721da177e4SLinus Torvalds 	}
2073fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20741da177e4SLinus Torvalds }
20751da177e4SLinus Torvalds 
2076301cb2d8SJohan Hedberg static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
2077301cb2d8SJohan Hedberg {
2078dbbfa2abSAndre Guedes 	if (addr_type != ADDR_LE_DEV_RANDOM)
2079301cb2d8SJohan Hedberg 		return false;
2080301cb2d8SJohan Hedberg 
2081301cb2d8SJohan Hedberg 	if ((bdaddr->b[5] & 0xc0) == 0x40)
2082301cb2d8SJohan Hedberg 	       return true;
2083301cb2d8SJohan Hedberg 
2084301cb2d8SJohan Hedberg 	return false;
2085301cb2d8SJohan Hedberg }
2086301cb2d8SJohan Hedberg 
2087c46245b3SJohan Hedberg static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type)
2088c46245b3SJohan Hedberg {
2089c46245b3SJohan Hedberg 	if (addr_type == ADDR_LE_DEV_PUBLIC)
2090c46245b3SJohan Hedberg 		return true;
2091c46245b3SJohan Hedberg 
2092c46245b3SJohan Hedberg 	/* Check for Random Static address type */
2093c46245b3SJohan Hedberg 	if ((addr->b[5] & 0xc0) == 0xc0)
2094c46245b3SJohan Hedberg 		return true;
2095c46245b3SJohan Hedberg 
2096c46245b3SJohan Hedberg 	return false;
2097c46245b3SJohan Hedberg }
2098c46245b3SJohan Hedberg 
20992426f3a5SJohan Hedberg static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
21002426f3a5SJohan Hedberg 					  bdaddr_t *bdaddr, u8 addr_type)
21012426f3a5SJohan Hedberg {
21022426f3a5SJohan Hedberg 	if (!hci_bdaddr_is_rpa(bdaddr, addr_type))
21032426f3a5SJohan Hedberg 		return NULL;
21042426f3a5SJohan Hedberg 
21052426f3a5SJohan Hedberg 	return hci_find_irk_by_rpa(hdev, bdaddr);
21062426f3a5SJohan Hedberg }
21072426f3a5SJohan Hedberg 
2108d4905f24SAndre Guedes static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
2109d4905f24SAndre Guedes 					u16 to_multiplier)
2110d4905f24SAndre Guedes {
2111d4905f24SAndre Guedes 	u16 max_latency;
2112d4905f24SAndre Guedes 
2113d4905f24SAndre Guedes 	if (min > max || min < 6 || max > 3200)
2114d4905f24SAndre Guedes 		return -EINVAL;
2115d4905f24SAndre Guedes 
2116d4905f24SAndre Guedes 	if (to_multiplier < 10 || to_multiplier > 3200)
2117d4905f24SAndre Guedes 		return -EINVAL;
2118d4905f24SAndre Guedes 
2119d4905f24SAndre Guedes 	if (max >= to_multiplier * 8)
2120d4905f24SAndre Guedes 		return -EINVAL;
2121d4905f24SAndre Guedes 
21228757825bSSeungyoun Ju 	max_latency = (to_multiplier * 4 / max) - 1;
2123d4905f24SAndre Guedes 	if (latency > 499 || latency > max_latency)
2124d4905f24SAndre Guedes 		return -EINVAL;
2125d4905f24SAndre Guedes 
2126d4905f24SAndre Guedes 	return 0;
2127d4905f24SAndre Guedes }
2128d4905f24SAndre Guedes 
21291da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
21301da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
21311da177e4SLinus Torvalds 
2132d6ee6ad7SLoic Poulain int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen,
2133d6ee6ad7SLoic Poulain 		   const void *param);
213475e84b7cSJohan Hedberg 
213507dc93ddSJohan Hedberg int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
213607dc93ddSJohan Hedberg 		 const void *param);
213773d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
21380d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
213926afbd82SLuiz Augusto von Dentz void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb);
21401da177e4SLinus Torvalds 
2141a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
2142dfe6d5c3SLuiz Augusto von Dentz void *hci_recv_event_data(struct hci_dev *hdev, __u8 event);
21431da177e4SLinus Torvalds 
2144eab2404bSLuiz Augusto von Dentz u32 hci_conn_get_phy(struct hci_conn *conn);
2145eab2404bSLuiz Augusto von Dentz 
21461da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
2147470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
21487129069eSJohan Hedberg void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
2149c08b1a1dSMarcel Holtmann 			 int flag, struct sock *skip_sk);
2150cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
215138ceaa00SMarcel Holtmann void hci_send_monitor_ctrl_event(struct hci_dev *hdev, u16 event,
215238ceaa00SMarcel Holtmann 				 void *data, u16 data_len, ktime_t tstamp,
215338ceaa00SMarcel Holtmann 				 int flag, struct sock *skip_sk);
21541da177e4SLinus Torvalds 
2155040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event);
2156040030efSMarcel Holtmann 
2157a958452aSMarcel Holtmann #define HCI_MGMT_VAR_LEN	BIT(0)
2158a958452aSMarcel Holtmann #define HCI_MGMT_NO_HDEV	BIT(1)
2159a958452aSMarcel Holtmann #define HCI_MGMT_UNTRUSTED	BIT(2)
2160a958452aSMarcel Holtmann #define HCI_MGMT_UNCONFIGURED	BIT(3)
2161d5cc6626SMarcel Holtmann #define HCI_MGMT_HDEV_OPTIONAL	BIT(4)
2162b9a245fbSJohan Hedberg 
2163801c1e8dSJohan Hedberg struct hci_mgmt_handler {
2164801c1e8dSJohan Hedberg 	int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
2165801c1e8dSJohan Hedberg 		     u16 data_len);
2166801c1e8dSJohan Hedberg 	size_t data_len;
2167b9a245fbSJohan Hedberg 	unsigned long flags;
2168801c1e8dSJohan Hedberg };
2169801c1e8dSJohan Hedberg 
2170801c1e8dSJohan Hedberg struct hci_mgmt_chan {
2171801c1e8dSJohan Hedberg 	struct list_head list;
2172801c1e8dSJohan Hedberg 	unsigned short channel;
2173801c1e8dSJohan Hedberg 	size_t handler_count;
2174801c1e8dSJohan Hedberg 	const struct hci_mgmt_handler *handlers;
217588b94ce9SJohan Hedberg 	void (*hdev_init) (struct sock *sk, struct hci_dev *hdev);
2176801c1e8dSJohan Hedberg };
2177801c1e8dSJohan Hedberg 
2178801c1e8dSJohan Hedberg int hci_mgmt_chan_register(struct hci_mgmt_chan *c);
2179801c1e8dSJohan Hedberg void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c);
2180801c1e8dSJohan Hedberg 
21810381101fSJohan Hedberg /* Management interface */
2182591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR		(BIT(BDADDR_BREDR))
2183591f47f3SAndre Guedes #define DISCOV_TYPE_LE			(BIT(BDADDR_LE_PUBLIC) | \
2184591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2185591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED		(BIT(BDADDR_BREDR) | \
2186591f47f3SAndre Guedes 					 BIT(BDADDR_LE_PUBLIC) | \
2187591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2188f39799f5SAndre Guedes 
21890d8cc935SAndre Guedes /* These LE scan and inquiry parameters were chosen according to LE General
21900d8cc935SAndre Guedes  * Discovery Procedure specification.
21910d8cc935SAndre Guedes  */
21920d8cc935SAndre Guedes #define DISCOV_LE_SCAN_WIN		0x12
21930d8cc935SAndre Guedes #define DISCOV_LE_SCAN_INT		0x12
21943d5a76f0SLukasz Rymanowski #define DISCOV_LE_TIMEOUT		10240	/* msec */
2195ae55f598SLukasz Rymanowski #define DISCOV_INTERLEAVED_TIMEOUT	5120	/* msec */
21960d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_INQUIRY_LEN	0x04
21970d8cc935SAndre Guedes #define DISCOV_BREDR_INQUIRY_LEN	0x08
21984b0e0cedSJakub Pawlowski #define DISCOV_LE_RESTART_DELAY		msecs_to_jiffies(200)	/* msec */
2199cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MIN	0x00A0	/* 100 msec */
2200cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MAX	0x00F0	/* 150 msec */
2201eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MIN	0x00A0	/* 200 msec */
2202eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MAX	0x00A0	/* 200 msec */
2203b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MIN		0x00A0  /* 100 msec */
2204b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MAX		0x00A0  /* 100 msec */
2205b338d917SBrian Gix #define INTERVAL_TO_MS(x)		(((x) * 10) / 0x10)
22060d8cc935SAndre Guedes 
2207dbf6811aSArchie Pusaka #define NAME_RESOLVE_DURATION		msecs_to_jiffies(10240)	/* 10.24 sec */
2208dbf6811aSArchie Pusaka 
220903c979c4SMarcel Holtmann void mgmt_fill_version_info(void *ver);
221091a668b0SJohan Hedberg int mgmt_new_settings(struct hci_dev *hdev);
2211bf6b56dbSMarcel Holtmann void mgmt_index_added(struct hci_dev *hdev);
2212bf6b56dbSMarcel Holtmann void mgmt_index_removed(struct hci_dev *hdev);
22133eec705eSMarcel Holtmann void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
22142ff13894SJohan Hedberg void mgmt_power_on(struct hci_dev *hdev, int err);
22152ff13894SJohan Hedberg void __mgmt_power_off(struct hci_dev *hdev);
2216dc4a5ee2SMarcel Holtmann void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
2217745c0ce3SVishal Agarwal 		       bool persistent);
221848ec92faSAlfonso Acosta void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
22191c6ed31bSYu Liu 			   u8 *name, u8 name_len);
22209b80ec5eSMarcel Holtmann void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
222112d4a3b2SJohan Hedberg 			      u8 link_type, u8 addr_type, u8 reason,
222212d4a3b2SJohan Hedberg 			      bool mgmt_connected);
22237892924cSMarcel Holtmann void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
222488c3df13SJohan Hedberg 			    u8 link_type, u8 addr_type, u8 status);
2225445608d0SMarcel Holtmann void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
222648264f06SJohan Hedberg 			 u8 addr_type, u8 status);
2227ce0e4a0dSMarcel Holtmann void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
2228e669cf80SMarcel Holtmann void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2229c35938b2SSzymon Janc 				  u8 status);
22303eb38528SMarcel Holtmann void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2231744cf19eSJohan Hedberg 				      u8 status);
2232744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
223339adbffeSJohan Hedberg 			      u8 link_type, u8 addr_type, u32 value,
2234272d90dfSJohan Hedberg 			      u8 confirm_hint);
2235744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2236272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2237272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2238272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
2239272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
2240272d90dfSJohan Hedberg 			      u8 link_type, u8 addr_type);
2241604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2242272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2243272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2244272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
224592a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
224692a25256SJohan Hedberg 			     u8 link_type, u8 addr_type, u32 passkey,
224792a25256SJohan Hedberg 			     u8 entered);
2248e1e930f5SJohan Hedberg void mgmt_auth_failed(struct hci_conn *conn, u8 status);
2249464996aeSMarcel Holtmann void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
22504e1b0245SMarcel Holtmann void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
22517f9a903cSMarcel Holtmann 				    u8 status);
22527667da34SMarcel Holtmann void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
2253e68f072bSJohan Hedberg void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status);
22542154d3f4SJohan Hedberg void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status);
2255901801b9SMarcel Holtmann void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2256af58925cSMarcel Holtmann 		       u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
2257b338d917SBrian Gix 		       u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len,
2258b338d917SBrian Gix 		       u64 instant);
22599cf12aeeSMarcel Holtmann void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2260b644ba33SJohan Hedberg 		      u8 addr_type, s8 rssi, u8 *name, u8 name_len);
22612f1e063bSMarcel Holtmann void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
2262346ce5b7SAbhishek Pandit-Subedi void mgmt_suspending(struct hci_dev *hdev, u8 state);
2263346ce5b7SAbhishek Pandit-Subedi void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr,
2264346ce5b7SAbhishek Pandit-Subedi 		   u8 addr_type);
226584c61d92SJohan Hedberg bool mgmt_powering_down(struct hci_dev *hdev);
226653ac6ab6SMarcel Holtmann void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
2267cad20c27SJohan Hedberg void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent);
226853ac6ab6SMarcel Holtmann void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
226953ac6ab6SMarcel Holtmann 		   bool persistent);
2270ffb5a827SAndre Guedes void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
2271f4869e2aSJohan Hedberg 			 u8 bdaddr_type, u8 store_hint, u16 min_interval,
2272f4869e2aSJohan Hedberg 			 u16 max_interval, u16 latency, u16 timeout);
2273f4a407beSJohan Hedberg void mgmt_smp_complete(struct hci_conn *conn, bool complete);
2274f2252570SJohan Hedberg bool mgmt_get_connectable(struct hci_dev *hdev);
2275f2252570SJohan Hedberg u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev);
2276f2252570SJohan Hedberg void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,
2277f2252570SJohan Hedberg 			    u8 instance);
2278f2252570SJohan Hedberg void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev,
2279f2252570SJohan Hedberg 			      u8 instance);
228066bd095aSArchie Pusaka void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle);
2281b7c23df8SJaganath Kanakkassery int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip);
22828d7f1677SManish Mandlik void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle,
22838d7f1677SManish Mandlik 				  bdaddr_t *bdaddr, u8 addr_type);
2284346af67bSVinicius Costa Gomes 
22851a942de0SBrian Gix int hci_abort_conn(struct hci_conn *conn, u8 reason);
22867d6ca693SJohan Hedberg u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
22877d6ca693SJohan Hedberg 		      u16 to_multiplier);
2288fe39c7b2SMarcel Holtmann void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
22898b76ce34SJohan Hedberg 		      __u8 ltk[16], __u8 key_size);
22902519a1fcSAndre Guedes 
2291a1f4c318SJohan Hedberg void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
2292a1f4c318SJohan Hedberg 			       u8 *bdaddr_type);
2293ebd3a747SJohan Hedberg 
22945d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_MASK       0x0003
22955d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_CVSD       0x0000
22965d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_TRANSP     0x0003
22975d4d62f6SFrédéric Dalleau 
22988961987fSKiran K #define LOCAL_CODEC_ACL_MASK	BIT(0)
22998961987fSKiran K #define LOCAL_CODEC_SCO_MASK	BIT(1)
23008961987fSKiran K 
23018961987fSKiran K #define TRANSPORT_TYPE_MAX	0x04
23028961987fSKiran K 
23031da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
2304