xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision 23417475)
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;
1924cd3928aSJohan Hedberg 	u8 type;
1937ee4ea36SMarcel Holtmann 	u8 val[16];
1947ee4ea36SMarcel Holtmann };
1957ee4ea36SMarcel Holtmann 
196b899efafSVinicius Costa Gomes struct smp_ltk {
197b899efafSVinicius Costa Gomes 	struct list_head list;
198970d0f1bSJohan Hedberg 	struct rcu_head rcu;
199b899efafSVinicius Costa Gomes 	bdaddr_t bdaddr;
200b899efafSVinicius Costa Gomes 	u8 bdaddr_type;
201b899efafSVinicius Costa Gomes 	u8 authenticated;
202b899efafSVinicius Costa Gomes 	u8 type;
203b899efafSVinicius Costa Gomes 	u8 enc_size;
204b899efafSVinicius Costa Gomes 	__le16 ediv;
205fe39c7b2SMarcel Holtmann 	__le64 rand;
206b899efafSVinicius Costa Gomes 	u8 val[16];
20703c515d7SMarcel Holtmann };
208b899efafSVinicius Costa Gomes 
209970c4e46SJohan Hedberg struct smp_irk {
210970c4e46SJohan Hedberg 	struct list_head list;
211adae20cbSJohan Hedberg 	struct rcu_head rcu;
212970c4e46SJohan Hedberg 	bdaddr_t rpa;
213970c4e46SJohan Hedberg 	bdaddr_t bdaddr;
214970c4e46SJohan Hedberg 	u8 addr_type;
215970c4e46SJohan Hedberg 	u8 val[16];
216970c4e46SJohan Hedberg };
217970c4e46SJohan Hedberg 
21855ed8ca1SJohan Hedberg struct link_key {
21955ed8ca1SJohan Hedberg 	struct list_head list;
2200378b597SJohan Hedberg 	struct rcu_head rcu;
22155ed8ca1SJohan Hedberg 	bdaddr_t bdaddr;
22255ed8ca1SJohan Hedberg 	u8 type;
2239b3b4460SAndrei Emeltchenko 	u8 val[HCI_LINK_KEY_SIZE];
22455ed8ca1SJohan Hedberg 	u8 pin_len;
22555ed8ca1SJohan Hedberg };
22655ed8ca1SJohan Hedberg 
2272763eda6SSzymon Janc struct oob_data {
2282763eda6SSzymon Janc 	struct list_head list;
2292763eda6SSzymon Janc 	bdaddr_t bdaddr;
2306928a924SJohan Hedberg 	u8 bdaddr_type;
231f7697b16SMarcel Holtmann 	u8 present;
232519ca9d0SMarcel Holtmann 	u8 hash192[16];
23338da1703SJohan Hedberg 	u8 rand192[16];
234519ca9d0SMarcel Holtmann 	u8 hash256[16];
23538da1703SJohan Hedberg 	u8 rand256[16];
2362763eda6SSzymon Janc };
2372763eda6SSzymon Janc 
238203fea01SArman Uguray struct adv_info {
239d2609b34SFlorian Grandel 	struct list_head list;
24010279313SLuiz Augusto von Dentz 	bool	enabled;
241fffd38bcSFlorian Grandel 	bool	pending;
242eca0ae4aSLuiz Augusto von Dentz 	bool	periodic;
243b338d917SBrian Gix 	__u8	mesh;
244203fea01SArman Uguray 	__u8	instance;
245203fea01SArman Uguray 	__u32	flags;
246912098a6SArman Uguray 	__u16	timeout;
2475d900e46SFlorian Grandel 	__u16	remaining_time;
248d2609b34SFlorian Grandel 	__u16	duration;
249203fea01SArman Uguray 	__u16	adv_data_len;
250c9ed0a70SLuiz Augusto von Dentz 	__u8	adv_data[HCI_MAX_EXT_AD_LENGTH];
25134a718bcSLuiz Augusto von Dentz 	bool	adv_data_changed;
252203fea01SArman Uguray 	__u16	scan_rsp_len;
253c9ed0a70SLuiz Augusto von Dentz 	__u8	scan_rsp_data[HCI_MAX_EXT_AD_LENGTH];
25434a718bcSLuiz Augusto von Dentz 	bool	scan_rsp_changed;
255eca0ae4aSLuiz Augusto von Dentz 	__u16	per_adv_data_len;
256eca0ae4aSLuiz Augusto von Dentz 	__u8	per_adv_data[HCI_MAX_PER_AD_LENGTH];
257de181e88SJaganath Kanakkassery 	__s8	tx_power;
2589bf9f4b6SDaniel Winkler 	__u32   min_interval;
2599bf9f4b6SDaniel Winkler 	__u32   max_interval;
260a73c046aSJaganath Kanakkassery 	bdaddr_t	random_addr;
261a73c046aSJaganath Kanakkassery 	bool 		rpa_expired;
262a73c046aSJaganath Kanakkassery 	struct delayed_work	rpa_expired_cb;
263203fea01SArman Uguray };
264203fea01SArman Uguray 
265db25be66SFlorian Grandel #define HCI_MAX_ADV_INSTANCES		5
266d2609b34SFlorian Grandel #define HCI_DEFAULT_ADV_DURATION	2
267d2609b34SFlorian Grandel 
26812410572SDaniel Winkler #define HCI_ADV_TX_POWER_NO_PREFERENCE 0x7F
26912410572SDaniel Winkler 
27034a718bcSLuiz Augusto von Dentz #define DATA_CMP(_d1, _l1, _d2, _l2) \
27134a718bcSLuiz Augusto von Dentz 	(_l1 == _l2 ? memcmp(_d1, _d2, _l1) : _l1 - _l2)
27234a718bcSLuiz Augusto von Dentz 
27334a718bcSLuiz Augusto von Dentz #define ADV_DATA_CMP(_adv, _data, _len) \
27434a718bcSLuiz Augusto von Dentz 	DATA_CMP((_adv)->adv_data, (_adv)->adv_data_len, _data, _len)
27534a718bcSLuiz Augusto von Dentz 
27634a718bcSLuiz Augusto von Dentz #define SCAN_RSP_CMP(_adv, _data, _len) \
27734a718bcSLuiz Augusto von Dentz 	DATA_CMP((_adv)->scan_rsp_data, (_adv)->scan_rsp_len, _data, _len)
27834a718bcSLuiz Augusto von Dentz 
2793368aa35SManish Mandlik struct monitored_device {
2803368aa35SManish Mandlik 	struct list_head list;
2813368aa35SManish Mandlik 
2823368aa35SManish Mandlik 	bdaddr_t bdaddr;
2833368aa35SManish Mandlik 	__u8     addr_type;
2843368aa35SManish Mandlik 	__u16    handle;
2853368aa35SManish Mandlik 	bool     notified;
2863368aa35SManish Mandlik };
2873368aa35SManish Mandlik 
288e5e1e7fdSMiao-chen Chou struct adv_pattern {
289e5e1e7fdSMiao-chen Chou 	struct list_head list;
290e5e1e7fdSMiao-chen Chou 	__u8 ad_type;
291e5e1e7fdSMiao-chen Chou 	__u8 offset;
292e5e1e7fdSMiao-chen Chou 	__u8 length;
293db08722fSLuiz Augusto von Dentz 	__u8 value[HCI_MAX_EXT_AD_LENGTH];
294e5e1e7fdSMiao-chen Chou };
295e5e1e7fdSMiao-chen Chou 
296b4a221eaSArchie Pusaka struct adv_rssi_thresholds {
297b4a221eaSArchie Pusaka 	__s8 low_threshold;
298b4a221eaSArchie Pusaka 	__s8 high_threshold;
299b4a221eaSArchie Pusaka 	__u16 low_threshold_timeout;
300b4a221eaSArchie Pusaka 	__u16 high_threshold_timeout;
301b4a221eaSArchie Pusaka 	__u8 sampling_period;
302b4a221eaSArchie Pusaka };
303b4a221eaSArchie Pusaka 
304e5e1e7fdSMiao-chen Chou struct adv_monitor {
305e5e1e7fdSMiao-chen Chou 	struct list_head patterns;
306b4a221eaSArchie Pusaka 	struct adv_rssi_thresholds rssi;
307e5e1e7fdSMiao-chen Chou 	__u16		handle;
308a2a4dedfSArchie Pusaka 
309a2a4dedfSArchie Pusaka 	enum {
310a2a4dedfSArchie Pusaka 		ADV_MONITOR_STATE_NOT_REGISTERED,
311a2a4dedfSArchie Pusaka 		ADV_MONITOR_STATE_REGISTERED,
312a2a4dedfSArchie Pusaka 		ADV_MONITOR_STATE_OFFLOADED
313a2a4dedfSArchie Pusaka 	} state;
314e5e1e7fdSMiao-chen Chou };
315e5e1e7fdSMiao-chen Chou 
316e5e1e7fdSMiao-chen Chou #define HCI_MIN_ADV_MONITOR_HANDLE		1
317e5e1e7fdSMiao-chen Chou #define HCI_MAX_ADV_MONITOR_NUM_HANDLES		32
318e5e1e7fdSMiao-chen Chou #define HCI_MAX_ADV_MONITOR_NUM_PATTERNS	16
319a2a4dedfSArchie Pusaka #define HCI_ADV_MONITOR_EXT_NONE		1
320a2a4dedfSArchie Pusaka #define HCI_ADV_MONITOR_EXT_MSFT		2
321e5e1e7fdSMiao-chen Chou 
322490c5babSJohan Hedberg #define HCI_MAX_SHORT_NAME_LENGTH	10
323490c5babSJohan Hedberg 
324d5ebaa7cSSoenke Huster #define HCI_CONN_HANDLE_MAX		0x0eff
3259f78191cSLuiz Augusto von Dentz #define HCI_CONN_HANDLE_UNSET(_handle)	(_handle > HCI_CONN_HANDLE_MAX)
326d5ebaa7cSSoenke Huster 
327d5bb334aSMarcel Holtmann /* Min encryption key size to match with SMP */
328d5bb334aSMarcel Holtmann #define HCI_MIN_ENC_KEY_SIZE		7
329d5bb334aSMarcel Holtmann 
330d6bfd59cSJohan Hedberg /* Default LE RPA expiry time, 15 minutes */
331d6bfd59cSJohan Hedberg #define HCI_DEFAULT_RPA_TIMEOUT		(15 * 60)
332d6bfd59cSJohan Hedberg 
33331ad1691SAndrzej Kaczmarek /* Default min/max age of connection information (1s/3s) */
33431ad1691SAndrzej Kaczmarek #define DEFAULT_CONN_INFO_MIN_AGE	1000
33531ad1691SAndrzej Kaczmarek #define DEFAULT_CONN_INFO_MAX_AGE	3000
336302975cbSSpoorthi Ravishankar Koppad /* Default authenticated payload timeout 30s */
337302975cbSSpoorthi Ravishankar Koppad #define DEFAULT_AUTH_PAYLOAD_TIMEOUT   0x0bb8
33831ad1691SAndrzej Kaczmarek 
339903e4541SAndrei Emeltchenko struct amp_assoc {
340903e4541SAndrei Emeltchenko 	__u16	len;
341903e4541SAndrei Emeltchenko 	__u16	offset;
34293c284eeSAndrei Emeltchenko 	__u16	rem_len;
34393c284eeSAndrei Emeltchenko 	__u16	len_so_far;
344903e4541SAndrei Emeltchenko 	__u8	data[HCI_MAX_AMP_ASSOC_SIZE];
345903e4541SAndrei Emeltchenko };
346903e4541SAndrei Emeltchenko 
347d2c5d77fSJohan Hedberg #define HCI_MAX_PAGES	3
348cad718edSJohan Hedberg 
3491da177e4SLinus Torvalds struct hci_dev {
3501da177e4SLinus Torvalds 	struct list_head list;
35109fd0de5SGustavo F. Padovan 	struct mutex	lock;
3521da177e4SLinus Torvalds 
353dcda1657SLuiz Augusto von Dentz 	const char	*name;
3541da177e4SLinus Torvalds 	unsigned long	flags;
3551da177e4SLinus Torvalds 	__u16		id;
356c13854ceSMarcel Holtmann 	__u8		bus;
357943da25dSMarcel Holtmann 	__u8		dev_type;
3581da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
359e30d3f5fSMarcel Holtmann 	bdaddr_t	setup_addr;
36024c457e2SMarcel Holtmann 	bdaddr_t	public_addr;
3617a4cd51dSMarcel Holtmann 	bdaddr_t	random_addr;
362d13eafceSMarcel Holtmann 	bdaddr_t	static_addr;
36356ed2cb8SJohan Hedberg 	__u8		adv_addr_type;
3641f6c6378SJohan Hedberg 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
365490c5babSJohan Hedberg 	__u8		short_name[HCI_MAX_SHORT_NAME_LENGTH];
36680a1e1dbSJohan Hedberg 	__u8		eir[HCI_MAX_EIR_LENGTH];
367c4960ecfSMichał Narajowski 	__u16		appearance;
368a9de9248SMarcel Holtmann 	__u8		dev_class[3];
3691aff6f09SJohan Hedberg 	__u8		major_class;
3701aff6f09SJohan Hedberg 	__u8		minor_class;
371d2c5d77fSJohan Hedberg 	__u8		max_page;
372cad718edSJohan Hedberg 	__u8		features[HCI_MAX_PAGES][8];
37360e77321SJohan Hedberg 	__u8		le_features[8];
3743d4f9c00SArchie Pusaka 	__u8		le_accept_list_size;
375cfdb0c2dSAnkit Navik 	__u8		le_resolv_list_size;
3766b49bcb4SJaganath Kanakkassery 	__u8		le_num_of_adv_sets;
3779b008c04SJohan Hedberg 	__u8		le_states[8];
378b338d917SBrian Gix 	__u8		mesh_ad_types[16];
379b338d917SBrian Gix 	__u8		mesh_send_ref;
380a9de9248SMarcel Holtmann 	__u8		commands[64];
3811143e5a6SMarcel Holtmann 	__u8		hci_ver;
3821143e5a6SMarcel Holtmann 	__u16		hci_rev;
383d5859e22SJohan Hedberg 	__u8		lmp_ver;
3841143e5a6SMarcel Holtmann 	__u16		manufacturer;
3857d69230cSAndrei Emeltchenko 	__u16		lmp_subver;
3861da177e4SLinus Torvalds 	__u16		voice_setting;
387b4cb9fb2SMarcel Holtmann 	__u8		num_iac;
388e88422bcSLuiz Augusto von Dentz 	__u16		stored_max_keys;
389e88422bcSLuiz Augusto von Dentz 	__u16		stored_num_keys;
39017fa4b9dSJohan Hedberg 	__u8		io_capability;
39191c4e9b1SMarcel Holtmann 	__s8		inq_tx_power;
39200bce3fbSAlain Michaud 	__u8		err_data_reporting;
393f332ec66SJohan Hedberg 	__u16		page_scan_interval;
394f332ec66SJohan Hedberg 	__u16		page_scan_window;
395f332ec66SJohan Hedberg 	__u8		page_scan_type;
3963f959d46SMarcel Holtmann 	__u8		le_adv_channel_map;
397628531c9SGeorg Lukas 	__u16		le_adv_min_interval;
398628531c9SGeorg Lukas 	__u16		le_adv_max_interval;
399533553f8SMarcel Holtmann 	__u8		le_scan_type;
400bef64738SMarcel Holtmann 	__u16		le_scan_interval;
401bef64738SMarcel Holtmann 	__u16		le_scan_window;
40210873f99SAlain Michaud 	__u16		le_scan_int_suspend;
40310873f99SAlain Michaud 	__u16		le_scan_window_suspend;
40410873f99SAlain Michaud 	__u16		le_scan_int_discovery;
40510873f99SAlain Michaud 	__u16		le_scan_window_discovery;
40610873f99SAlain Michaud 	__u16		le_scan_int_adv_monitor;
40710873f99SAlain Michaud 	__u16		le_scan_window_adv_monitor;
40810873f99SAlain Michaud 	__u16		le_scan_int_connect;
40910873f99SAlain Michaud 	__u16		le_scan_window_connect;
4104e70c7e7SMarcel Holtmann 	__u16		le_conn_min_interval;
4114e70c7e7SMarcel Holtmann 	__u16		le_conn_max_interval;
41204fb7d90SMarcel Holtmann 	__u16		le_conn_latency;
41304fb7d90SMarcel Holtmann 	__u16		le_supv_timeout;
414a8e1bfaaSMarcel Holtmann 	__u16		le_def_tx_len;
415a8e1bfaaSMarcel Holtmann 	__u16		le_def_tx_time;
416a8e1bfaaSMarcel Holtmann 	__u16		le_max_tx_len;
417a8e1bfaaSMarcel Holtmann 	__u16		le_max_tx_time;
418a8e1bfaaSMarcel Holtmann 	__u16		le_max_rx_len;
419a8e1bfaaSMarcel Holtmann 	__u16		le_max_rx_time;
42030d65e08SMatias Karhumaa 	__u8		le_max_key_size;
42130d65e08SMatias Karhumaa 	__u8		le_min_key_size;
422b9a7a61eSLukasz Rymanowski 	__u16		discov_interleaved_timeout;
42331ad1691SAndrzej Kaczmarek 	__u16		conn_info_min_age;
42431ad1691SAndrzej Kaczmarek 	__u16		conn_info_max_age;
425302975cbSSpoorthi Ravishankar Koppad 	__u16		auth_payload_timeout;
42658a96fc3SMarcel Holtmann 	__u8		min_enc_key_size;
427a4790360SMarcel Holtmann 	__u8		max_enc_key_size;
428a4790360SMarcel Holtmann 	__u8		pairing_opts;
42906f5b778SMarcel Holtmann 	__u8		ssp_debug_mode;
430c7741d16SMarcel Holtmann 	__u8		hw_error_code;
43133f35721SJohan Hedberg 	__u32		clock;
432c4f1f408SHoward Chung 	__u16		advmon_allowlist_duration;
433c4f1f408SHoward Chung 	__u16		advmon_no_filter_duration;
43480af16a3SHoward Chung 	__u8		enable_advmon_interleave_scan;
435f332ec66SJohan Hedberg 
4362b9be137SMarcel Holtmann 	__u16		devid_source;
4372b9be137SMarcel Holtmann 	__u16		devid_vendor;
4382b9be137SMarcel Holtmann 	__u16		devid_product;
4392b9be137SMarcel Holtmann 	__u16		devid_version;
4401da177e4SLinus Torvalds 
44110873f99SAlain Michaud 	__u8		def_page_scan_type;
44210873f99SAlain Michaud 	__u16		def_page_scan_int;
44310873f99SAlain Michaud 	__u16		def_page_scan_window;
44410873f99SAlain Michaud 	__u8		def_inq_scan_type;
44510873f99SAlain Michaud 	__u16		def_inq_scan_int;
44610873f99SAlain Michaud 	__u16		def_inq_scan_window;
44710873f99SAlain Michaud 	__u16		def_br_lsto;
44810873f99SAlain Michaud 	__u16		def_page_timeout;
44910873f99SAlain Michaud 	__u16		def_multi_adv_rotation_duration;
45049b020c1SAlain Michaud 	__u16		def_le_autoconnect_timeout;
4517c395ea5SDaniel Winkler 	__s8		min_le_tx_power;
4527c395ea5SDaniel Winkler 	__s8		max_le_tx_power;
45310873f99SAlain Michaud 
4541da177e4SLinus Torvalds 	__u16		pkt_type;
4555b7f9909SMarcel Holtmann 	__u16		esco_type;
4561da177e4SLinus Torvalds 	__u16		link_policy;
4571da177e4SLinus Torvalds 	__u16		link_mode;
4581da177e4SLinus Torvalds 
45904837f64SMarcel Holtmann 	__u32		idle_timeout;
46004837f64SMarcel Holtmann 	__u16		sniff_min_interval;
46104837f64SMarcel Holtmann 	__u16		sniff_max_interval;
46204837f64SMarcel Holtmann 
463928abaa7SAndrei Emeltchenko 	__u8		amp_status;
464928abaa7SAndrei Emeltchenko 	__u32		amp_total_bw;
465928abaa7SAndrei Emeltchenko 	__u32		amp_max_bw;
466928abaa7SAndrei Emeltchenko 	__u32		amp_min_latency;
467928abaa7SAndrei Emeltchenko 	__u32		amp_max_pdu;
468928abaa7SAndrei Emeltchenko 	__u8		amp_type;
469928abaa7SAndrei Emeltchenko 	__u16		amp_pal_cap;
470928abaa7SAndrei Emeltchenko 	__u16		amp_assoc_size;
471928abaa7SAndrei Emeltchenko 	__u32		amp_max_flush_to;
472928abaa7SAndrei Emeltchenko 	__u32		amp_be_flush_to;
473928abaa7SAndrei Emeltchenko 
474903e4541SAndrei Emeltchenko 	struct amp_assoc	loc_assoc;
475903e4541SAndrei Emeltchenko 
4761e89cffbSAndrei Emeltchenko 	__u8		flow_ctl_mode;
4771e89cffbSAndrei Emeltchenko 
4789f61656aSJohan Hedberg 	unsigned int	auto_accept_delay;
4799f61656aSJohan Hedberg 
4801da177e4SLinus Torvalds 	unsigned long	quirks;
4811da177e4SLinus Torvalds 
4821da177e4SLinus Torvalds 	atomic_t	cmd_cnt;
4831da177e4SLinus Torvalds 	unsigned int	acl_cnt;
4841da177e4SLinus Torvalds 	unsigned int	sco_cnt;
4856ed58ec5SVille Tervo 	unsigned int	le_cnt;
48626afbd82SLuiz Augusto von Dentz 	unsigned int	iso_cnt;
4871da177e4SLinus Torvalds 
4881da177e4SLinus Torvalds 	unsigned int	acl_mtu;
4891da177e4SLinus Torvalds 	unsigned int	sco_mtu;
4906ed58ec5SVille Tervo 	unsigned int	le_mtu;
49126afbd82SLuiz Augusto von Dentz 	unsigned int	iso_mtu;
4921da177e4SLinus Torvalds 	unsigned int	acl_pkts;
4931da177e4SLinus Torvalds 	unsigned int	sco_pkts;
4946ed58ec5SVille Tervo 	unsigned int	le_pkts;
49526afbd82SLuiz Augusto von Dentz 	unsigned int	iso_pkts;
4961da177e4SLinus Torvalds 
497350ee4cfSAndrei Emeltchenko 	__u16		block_len;
498350ee4cfSAndrei Emeltchenko 	__u16		block_mtu;
499350ee4cfSAndrei Emeltchenko 	__u16		num_blocks;
500350ee4cfSAndrei Emeltchenko 	__u16		block_cnt;
501350ee4cfSAndrei Emeltchenko 
5021da177e4SLinus Torvalds 	unsigned long	acl_last_tx;
5031da177e4SLinus Torvalds 	unsigned long	sco_last_tx;
5046ed58ec5SVille Tervo 	unsigned long	le_last_tx;
5051da177e4SLinus Torvalds 
5066decb5b4SJaganath Kanakkassery 	__u8		le_tx_def_phys;
5076decb5b4SJaganath Kanakkassery 	__u8		le_rx_def_phys;
5086decb5b4SJaganath Kanakkassery 
509f48fd9c8SMarcel Holtmann 	struct workqueue_struct	*workqueue;
5106ead1bbcSJohan Hedberg 	struct workqueue_struct	*req_workqueue;
511f48fd9c8SMarcel Holtmann 
512ab81cbf9SJohan Hedberg 	struct work_struct	power_on;
5133243553fSJohan Hedberg 	struct delayed_work	power_off;
514c7741d16SMarcel Holtmann 	struct work_struct	error_reset;
5156a98e383SMarcel Holtmann 	struct work_struct	cmd_sync_work;
5166a98e383SMarcel Holtmann 	struct list_head	cmd_sync_work_list;
5176a98e383SMarcel Holtmann 	struct mutex		cmd_sync_work_lock;
5181857c199SZhengping Jiang 	struct mutex		unregister_lock;
519744451c1SBenjamin Berg 	struct work_struct	cmd_sync_cancel_work;
520b338d917SBrian Gix 	struct work_struct	reenable_adv_work;
521ab81cbf9SJohan Hedberg 
52216ab91abSJohan Hedberg 	__u16			discov_timeout;
52316ab91abSJohan Hedberg 	struct delayed_work	discov_off;
52416ab91abSJohan Hedberg 
5257d78525dSJohan Hedberg 	struct delayed_work	service_cache;
5267d78525dSJohan Hedberg 
52765cc2b49SMarcel Holtmann 	struct delayed_work	cmd_timer;
528de75cd0dSManish Mandlik 	struct delayed_work	ncmd_timer;
529b78752ccSMarcel Holtmann 
530b78752ccSMarcel Holtmann 	struct work_struct	rx_work;
531c347b765SGustavo F. Padovan 	struct work_struct	cmd_work;
5323eff45eaSGustavo F. Padovan 	struct work_struct	tx_work;
5331da177e4SLinus Torvalds 
5347c1fbed2SJohan Hedberg 	struct delayed_work	le_scan_disable;
5357c1fbed2SJohan Hedberg 	struct delayed_work	le_scan_restart;
5362e93e53bSJohan Hedberg 
5371da177e4SLinus Torvalds 	struct sk_buff_head	rx_q;
5381da177e4SLinus Torvalds 	struct sk_buff_head	raw_q;
5391da177e4SLinus Torvalds 	struct sk_buff_head	cmd_q;
5401da177e4SLinus Torvalds 
5411da177e4SLinus Torvalds 	struct sk_buff		*sent_cmd;
542dfe6d5c3SLuiz Augusto von Dentz 	struct sk_buff		*recv_event;
5431da177e4SLinus Torvalds 
544a6a67efdSThomas Gleixner 	struct mutex		req_lock;
5451da177e4SLinus Torvalds 	wait_queue_head_t	req_wait_q;
5461da177e4SLinus Torvalds 	__u32			req_status;
5471da177e4SLinus Torvalds 	__u32			req_result;
548f60cb305SJohan Hedberg 	struct sk_buff		*req_skb;
549a5040efaSJohan Hedberg 
55070db83c4SJohan Hedberg 	void			*smp_data;
551ef8efe4bSJohan Hedberg 	void			*smp_bredr_data;
5522e58ef3eSJohan Hedberg 
55330883512SJohan Hedberg 	struct discovery_state	discovery;
5549952d90eSAbhishek Pandit-Subedi 
5554867bd00SAbhishek Pandit-Subedi 	int			discovery_old_state;
5564867bd00SAbhishek Pandit-Subedi 	bool			discovery_paused;
5574867bd00SAbhishek Pandit-Subedi 	int			advertising_old_state;
5584867bd00SAbhishek Pandit-Subedi 	bool			advertising_paused;
5594867bd00SAbhishek Pandit-Subedi 
5609952d90eSAbhishek Pandit-Subedi 	struct notifier_block	suspend_notifier;
5619952d90eSAbhishek Pandit-Subedi 	enum suspended_state	suspend_state_next;
5629952d90eSAbhishek Pandit-Subedi 	enum suspended_state	suspend_state;
5634f40afc6SAbhishek Pandit-Subedi 	bool			scanning_paused;
5644f40afc6SAbhishek Pandit-Subedi 	bool			suspended;
5652f20216cSAbhishek Pandit-Subedi 	u8			wake_reason;
5662f20216cSAbhishek Pandit-Subedi 	bdaddr_t		wake_addr;
5672f20216cSAbhishek Pandit-Subedi 	u8			wake_addr_type;
5689952d90eSAbhishek Pandit-Subedi 
5691da177e4SLinus Torvalds 	struct hci_conn_hash	conn_hash;
5705c136e90SAndre Guedes 
571b338d917SBrian Gix 	struct list_head	mesh_pending;
5725c136e90SAndre Guedes 	struct list_head	mgmt_pending;
5733d4f9c00SArchie Pusaka 	struct list_head	reject_list;
5743d4f9c00SArchie Pusaka 	struct list_head	accept_list;
5752aeb9a1aSJohan Hedberg 	struct list_head	uuids;
57655ed8ca1SJohan Hedberg 	struct list_head	link_keys;
577b899efafSVinicius Costa Gomes 	struct list_head	long_term_keys;
578970c4e46SJohan Hedberg 	struct list_head	identity_resolving_keys;
5792763eda6SSzymon Janc 	struct list_head	remote_oob_data;
5803d4f9c00SArchie Pusaka 	struct list_head	le_accept_list;
581cfdb0c2dSAnkit Navik 	struct list_head	le_resolv_list;
58215819a70SAndre Guedes 	struct list_head	le_conn_params;
58377a77a30SAndre Guedes 	struct list_head	pend_le_conns;
58466f8455aSJohan Hedberg 	struct list_head	pend_le_reports;
585600a8749SAlain Michaud 	struct list_head	blocked_keys;
5868961987fSKiran K 	struct list_head	local_codecs;
5872763eda6SSzymon Janc 
5881da177e4SLinus Torvalds 	struct hci_dev_stats	stat;
5891da177e4SLinus Torvalds 
5901da177e4SLinus Torvalds 	atomic_t		promisc;
5911da177e4SLinus Torvalds 
5925177a838SMarcel Holtmann 	const char		*hw_info;
5935177a838SMarcel Holtmann 	const char		*fw_info;
594ca325f69SMarcel Holtmann 	struct dentry		*debugfs;
595ca325f69SMarcel Holtmann 
5969695ef87SAbhishek Pandit-Subedi 	struct hci_devcoredump	dump;
5979695ef87SAbhishek Pandit-Subedi 
598a91f2e39SMarcel Holtmann 	struct device		dev;
5991da177e4SLinus Torvalds 
600611b30f7SMarcel Holtmann 	struct rfkill		*rfkill;
601611b30f7SMarcel Holtmann 
602eacb44dfSMarcel Holtmann 	DECLARE_BITMAP(dev_flags, __HCI_NUM_FLAGS);
603e1cff700SLinus Torvalds 	hci_conn_flags_t	conn_flags;
604d23264a8SAndre Guedes 
6058fa19098SJohan Hedberg 	__s8			adv_tx_power;
606c9ed0a70SLuiz Augusto von Dentz 	__u8			adv_data[HCI_MAX_EXT_AD_LENGTH];
6073f0f524bSJohan Hedberg 	__u8			adv_data_len;
608c9ed0a70SLuiz Augusto von Dentz 	__u8			scan_rsp_data[HCI_MAX_EXT_AD_LENGTH];
609f8e808bdSMarcel Holtmann 	__u8			scan_rsp_data_len;
610eca0ae4aSLuiz Augusto von Dentz 	__u8			per_adv_data[HCI_MAX_PER_AD_LENGTH];
611eca0ae4aSLuiz Augusto von Dentz 	__u8			per_adv_data_len;
6128fa19098SJohan Hedberg 
613d2609b34SFlorian Grandel 	struct list_head	adv_instances;
614d2609b34SFlorian Grandel 	unsigned int		adv_instance_cnt;
615d2609b34SFlorian Grandel 	__u8			cur_adv_instance;
6165d900e46SFlorian Grandel 	__u16			adv_instance_timeout;
6175d900e46SFlorian Grandel 	struct delayed_work	adv_instance_expire;
618203fea01SArman Uguray 
619e5e1e7fdSMiao-chen Chou 	struct idr		adv_monitors_idr;
620e5e1e7fdSMiao-chen Chou 	unsigned int		adv_monitors_cnt;
621e5e1e7fdSMiao-chen Chou 
622863efaf2SJohan Hedberg 	__u8			irk[16];
623d6bfd59cSJohan Hedberg 	__u32			rpa_timeout;
624d6bfd59cSJohan Hedberg 	struct delayed_work	rpa_expired;
6252b5224dcSMarcel Holtmann 	bdaddr_t		rpa;
626863efaf2SJohan Hedberg 
627b338d917SBrian Gix 	struct delayed_work	mesh_send_done;
628b338d917SBrian Gix 
629c4f1f408SHoward Chung 	enum {
630c4f1f408SHoward Chung 		INTERLEAVE_SCAN_NONE,
631c4f1f408SHoward Chung 		INTERLEAVE_SCAN_NO_FILTER,
632c4f1f408SHoward Chung 		INTERLEAVE_SCAN_ALLOWLIST
633c4f1f408SHoward Chung 	} interleave_scan_state;
634c4f1f408SHoward Chung 
635c4f1f408SHoward Chung 	struct delayed_work	interleave_scan;
636c4f1f408SHoward Chung 
6373368aa35SManish Mandlik 	struct list_head	monitored_devices;
6388d7f1677SManish Mandlik 	bool			advmon_pend_notify;
6393368aa35SManish Mandlik 
64053f863a6SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_LEDS)
6416d5d2ee6SHeiner Kallweit 	struct led_trigger	*power_led;
64253f863a6SMarcel Holtmann #endif
6436d5d2ee6SHeiner Kallweit 
644145373cbSMiao-chen Chou #if IS_ENABLED(CONFIG_BT_MSFTEXT)
645145373cbSMiao-chen Chou 	__u16			msft_opcode;
646145373cbSMiao-chen Chou 	void			*msft_data;
647a61d6718SMarcel Holtmann 	bool			msft_curve_validity;
648145373cbSMiao-chen Chou #endif
649145373cbSMiao-chen Chou 
650f67743f9SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_AOSPEXT)
651f67743f9SMarcel Holtmann 	bool			aosp_capable;
652749a6c59SJoseph Hwang 	bool			aosp_quality_report;
653f67743f9SMarcel Holtmann #endif
654f67743f9SMarcel Holtmann 
6551da177e4SLinus Torvalds 	int (*open)(struct hci_dev *hdev);
6561da177e4SLinus Torvalds 	int (*close)(struct hci_dev *hdev);
6571da177e4SLinus Torvalds 	int (*flush)(struct hci_dev *hdev);
658f41c70c4SMarcel Holtmann 	int (*setup)(struct hci_dev *hdev);
659a44fecbdSTedd Ho-Jeong An 	int (*shutdown)(struct hci_dev *hdev);
6607bd8f09fSMarcel Holtmann 	int (*send)(struct hci_dev *hdev, struct sk_buff *skb);
6611da177e4SLinus Torvalds 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
662c7741d16SMarcel Holtmann 	void (*hw_error)(struct hci_dev *hdev, u8 code);
66398a63aafSMarcel Holtmann 	int (*post_init)(struct hci_dev *hdev);
6644b4113d6SMarcel Holtmann 	int (*set_diag)(struct hci_dev *hdev, bool enable);
66524c457e2SMarcel Holtmann 	int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr);
666e2bef384SRajat Jain 	void (*cmd_timeout)(struct hci_dev *hdev);
667c9209b26SArchie Pusaka 	void (*reset)(struct hci_dev *hdev);
6684539ca67SLuiz Augusto von Dentz 	bool (*wakeup)(struct hci_dev *hdev);
669ae7d925bSJoseph Hwang 	int (*set_quality_report)(struct hci_dev *hdev, bool enable);
670248733e8SKiran K 	int (*get_data_path_id)(struct hci_dev *hdev, __u8 *data_path);
6719798fbdeSKiran K 	int (*get_codec_config_data)(struct hci_dev *hdev, __u8 type,
6729798fbdeSKiran K 				     struct bt_codec *codec, __u8 *vnd_len,
6739798fbdeSKiran K 				     __u8 **vnd_data);
6741da177e4SLinus Torvalds };
6751da177e4SLinus Torvalds 
67653502d69SAndrei Emeltchenko #define HCI_PHY_HANDLE(handle)	(handle & 0xff)
67753502d69SAndrei Emeltchenko 
67876b13996SManish Mandlik enum conn_reasons {
67976b13996SManish Mandlik 	CONN_REASON_PAIR_DEVICE,
68076b13996SManish Mandlik 	CONN_REASON_L2CAP_CHAN,
68176b13996SManish Mandlik 	CONN_REASON_SCO_CONNECT,
68226afbd82SLuiz Augusto von Dentz 	CONN_REASON_ISO_CONNECT,
68376b13996SManish Mandlik };
68476b13996SManish Mandlik 
6851da177e4SLinus Torvalds struct hci_conn {
6861da177e4SLinus Torvalds 	struct list_head list;
6871da177e4SLinus Torvalds 
6881da177e4SLinus Torvalds 	atomic_t	refcnt;
6891da177e4SLinus Torvalds 
6901da177e4SLinus Torvalds 	bdaddr_t	dst;
69129b7988aSAndre Guedes 	__u8		dst_type;
692662e8820SMarcel Holtmann 	bdaddr_t	src;
693e7c4096eSMarcel Holtmann 	__u8		src_type;
694cb1d68f7SJohan Hedberg 	bdaddr_t	init_addr;
695cb1d68f7SJohan Hedberg 	__u8		init_addr_type;
696cb1d68f7SJohan Hedberg 	bdaddr_t	resp_addr;
697cb1d68f7SJohan Hedberg 	__u8		resp_addr_type;
6987087c4f6SLuiz Augusto von Dentz 	__u8		adv_instance;
6991da177e4SLinus Torvalds 	__u16		handle;
700eca0ae4aSLuiz Augusto von Dentz 	__u16		sync_handle;
7011da177e4SLinus Torvalds 	__u16		state;
70204837f64SMarcel Holtmann 	__u8		mode;
7031da177e4SLinus Torvalds 	__u8		type;
70440bef302SJohan Hedberg 	__u8		role;
705a0c808b3SJohan Hedberg 	bool		out;
7064c67bc74SMarcel Holtmann 	__u8		attempt;
7071da177e4SLinus Torvalds 	__u8		dev_class[3];
708cad718edSJohan Hedberg 	__u8		features[HCI_MAX_PAGES][8];
709a8746417SMarcel Holtmann 	__u16		pkt_type;
71004837f64SMarcel Holtmann 	__u16		link_policy;
71113d39315SWaldemar Rymarkiewicz 	__u8		key_type;
71240be492fSMarcel Holtmann 	__u8		auth_type;
7138c1b2355SMarcel Holtmann 	__u8		sec_level;
714765c2a96SJohan Hedberg 	__u8		pending_sec_level;
715980e1a53SJohan Hedberg 	__u8		pin_length;
716726b4ffcSVinicius Costa Gomes 	__u8		enc_key_size;
71717fa4b9dSJohan Hedberg 	__u8		io_capability;
71892a25256SJohan Hedberg 	__u32		passkey_notify;
71992a25256SJohan Hedberg 	__u8		passkey_entered;
720052b30b0SMarcel Holtmann 	__u16		disc_timeout;
72109ae260bSJohan Hedberg 	__u16		conn_timeout;
72210c62ddcSFrédéric Dalleau 	__u16		setting;
723302975cbSSpoorthi Ravishankar Koppad 	__u16		auth_payload_timeout;
7241e406eefSAndre Guedes 	__u16		le_conn_min_interval;
7251e406eefSAndre Guedes 	__u16		le_conn_max_interval;
726e04fde60SMarcel Holtmann 	__u16		le_conn_interval;
727e04fde60SMarcel Holtmann 	__u16		le_conn_latency;
728e04fde60SMarcel Holtmann 	__u16		le_supv_timeout;
729db08722fSLuiz Augusto von Dentz 	__u8		le_adv_data[HCI_MAX_EXT_AD_LENGTH];
730fd45ada9SAlfonso Acosta 	__u8		le_adv_data_len;
731eca0ae4aSLuiz Augusto von Dentz 	__u8		le_per_adv_data[HCI_MAX_PER_AD_LENGTH];
732eca0ae4aSLuiz Augusto von Dentz 	__u8		le_per_adv_data_len;
7331efd927dSLuiz Augusto von Dentz 	__u8		le_tx_phy;
7341efd927dSLuiz Augusto von Dentz 	__u8		le_rx_phy;
7355ae76a94SAndrzej Kaczmarek 	__s8		rssi;
7365a134faeSAndrzej Kaczmarek 	__s8		tx_power;
737d0455ed9SAndrzej Kaczmarek 	__s8		max_tx_power;
73826afbd82SLuiz Augusto von Dentz 	struct bt_iso_qos iso_qos;
73951a8efd7SJohan Hedberg 	unsigned long	flags;
7401da177e4SLinus Torvalds 
74176b13996SManish Mandlik 	enum conn_reasons conn_reason;
742a13f316eSLuiz Augusto von Dentz 	__u8		abort_reason;
74376b13996SManish Mandlik 
74433f35721SJohan Hedberg 	__u32		clock;
74533f35721SJohan Hedberg 	__u16		clock_accuracy;
74633f35721SJohan Hedberg 
747dd983808SAndrzej Kaczmarek 	unsigned long	conn_info_timestamp;
748dd983808SAndrzej Kaczmarek 
74903b555e1SJohan Hedberg 	__u8		remote_cap;
75003b555e1SJohan Hedberg 	__u8		remote_auth;
7513161ae1cSAndrei Emeltchenko 	__u8		remote_id;
75203b555e1SJohan Hedberg 
7531da177e4SLinus Torvalds 	unsigned int	sent;
7541da177e4SLinus Torvalds 
7551da177e4SLinus Torvalds 	struct sk_buff_head data_q;
7562c33c06aSGustavo F. Padovan 	struct list_head chan_list;
7571da177e4SLinus Torvalds 
75819c40e3bSGustavo F. Padovan 	struct delayed_work disc_work;
7597bc18d9dSJohan Hedberg 	struct delayed_work auto_accept_work;
760a74a84f6SJohan Hedberg 	struct delayed_work idle_work;
7619489eca4SJohan Hedberg 	struct delayed_work le_conn_timeout;
7621da177e4SLinus Torvalds 
763b219e3acSMarcel Holtmann 	struct device	dev;
76423b9ceb7SMarcel Holtmann 	struct dentry	*debugfs;
765b219e3acSMarcel Holtmann 
7661da177e4SLinus Torvalds 	struct hci_dev	*hdev;
7671da177e4SLinus Torvalds 	void		*l2cap_data;
7681da177e4SLinus Torvalds 	void		*sco_data;
76926afbd82SLuiz Augusto von Dentz 	void		*iso_data;
7709740e49dSAndrei Emeltchenko 	struct amp_mgr	*amp_mgr;
7711da177e4SLinus Torvalds 
77206149746SLuiz Augusto von Dentz 	struct list_head link_list;
77306149746SLuiz Augusto von Dentz 	struct hci_conn	*parent;
77406149746SLuiz Augusto von Dentz 	struct hci_link *link;
77506149746SLuiz Augusto von Dentz 
776b2af264aSKiran K 	struct bt_codec codec;
777e9a416b5SJohan Hedberg 
778e9a416b5SJohan Hedberg 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
779e9a416b5SJohan Hedberg 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
780e9a416b5SJohan Hedberg 	void (*disconn_cfm_cb)	(struct hci_conn *conn, u8 reason);
78126afbd82SLuiz Augusto von Dentz 
78226afbd82SLuiz Augusto von Dentz 	void (*cleanup)(struct hci_conn *conn);
7831da177e4SLinus Torvalds };
7841da177e4SLinus Torvalds 
78506149746SLuiz Augusto von Dentz struct hci_link {
78606149746SLuiz Augusto von Dentz 	struct list_head list;
78706149746SLuiz Augusto von Dentz 	struct hci_conn *conn;
78806149746SLuiz Augusto von Dentz };
78906149746SLuiz Augusto von Dentz 
79073d80debSLuiz Augusto von Dentz struct hci_chan {
79173d80debSLuiz Augusto von Dentz 	struct list_head list;
79242c4e53eSAndrei Emeltchenko 	__u16 handle;
79373d80debSLuiz Augusto von Dentz 	struct hci_conn *conn;
79473d80debSLuiz Augusto von Dentz 	struct sk_buff_head data_q;
79573d80debSLuiz Augusto von Dentz 	unsigned int	sent;
796168df8e5SMat Martineau 	__u8		state;
7975c4c8c95SArchie Pusaka 	bool		amp;
79873d80debSLuiz Augusto von Dentz };
79973d80debSLuiz Augusto von Dentz 
80015819a70SAndre Guedes struct hci_conn_params {
80115819a70SAndre Guedes 	struct list_head list;
80293450c75SJohan Hedberg 	struct list_head action;
80315819a70SAndre Guedes 
80415819a70SAndre Guedes 	bdaddr_t addr;
80515819a70SAndre Guedes 	u8 addr_type;
80615819a70SAndre Guedes 
80715819a70SAndre Guedes 	u16 conn_min_interval;
80815819a70SAndre Guedes 	u16 conn_max_interval;
809f044eb05SMarcel Holtmann 	u16 conn_latency;
810f044eb05SMarcel Holtmann 	u16 supervision_timeout;
8119fcb18efSAndre Guedes 
8129fcb18efSAndre Guedes 	enum {
8139fcb18efSAndre Guedes 		HCI_AUTO_CONN_DISABLED,
814a3451d27SJohan Hedberg 		HCI_AUTO_CONN_REPORT,
8154b9e7e75SMarcel Holtmann 		HCI_AUTO_CONN_DIRECT,
8169fcb18efSAndre Guedes 		HCI_AUTO_CONN_ALWAYS,
8179fcb18efSAndre Guedes 		HCI_AUTO_CONN_LINK_LOSS,
818158e9218SJakub Pawlowski 		HCI_AUTO_CONN_EXPLICIT,
8199fcb18efSAndre Guedes 	} auto_connect;
820f161dd41SJohan Hedberg 
821f161dd41SJohan Hedberg 	struct hci_conn *conn;
822158e9218SJakub Pawlowski 	bool explicit_connect;
823195ef75eSPauli Virtanen 	/* Accessed without hdev->lock: */
824e1cff700SLinus Torvalds 	hci_conn_flags_t flags;
825853b70b5SLuiz Augusto von Dentz 	u8  privacy_mode;
82615819a70SAndre Guedes };
82715819a70SAndre Guedes 
8281da177e4SLinus Torvalds extern struct list_head hci_dev_list;
8291da177e4SLinus Torvalds extern struct list_head hci_cb_list;
8301da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock;
831fba7ecf0SJohan Hedberg extern struct mutex hci_cb_list_lock;
8321da177e4SLinus Torvalds 
833eacb44dfSMarcel Holtmann #define hci_dev_set_flag(hdev, nr)             set_bit((nr), (hdev)->dev_flags)
834eacb44dfSMarcel Holtmann #define hci_dev_clear_flag(hdev, nr)           clear_bit((nr), (hdev)->dev_flags)
835eacb44dfSMarcel Holtmann #define hci_dev_change_flag(hdev, nr)          change_bit((nr), (hdev)->dev_flags)
836eacb44dfSMarcel Holtmann #define hci_dev_test_flag(hdev, nr)            test_bit((nr), (hdev)->dev_flags)
837eacb44dfSMarcel Holtmann #define hci_dev_test_and_set_flag(hdev, nr)    test_and_set_bit((nr), (hdev)->dev_flags)
838eacb44dfSMarcel Holtmann #define hci_dev_test_and_clear_flag(hdev, nr)  test_and_clear_bit((nr), (hdev)->dev_flags)
839eacb44dfSMarcel Holtmann #define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), (hdev)->dev_flags)
840d7a5a11dSMarcel Holtmann 
841eacb44dfSMarcel Holtmann #define hci_dev_clear_volatile_flags(hdev)			\
842eacb44dfSMarcel Holtmann 	do {							\
843eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LE_SCAN);		\
844eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LE_ADV);		\
8452eb71a3aSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);\
846eacb44dfSMarcel Holtmann 		hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ);	\
847ae7d925bSJoseph Hwang 		hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT);	\
848eacb44dfSMarcel Holtmann 	} while (0)
849516018a9SMarcel Holtmann 
8504fc9857aSLuiz Augusto von Dentz #define hci_dev_le_state_simultaneous(hdev) \
8514fc9857aSLuiz Augusto von Dentz 	(test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && \
8524fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[4] & 0x08) &&	/* Central */ \
8534fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[4] & 0x40) &&	/* Peripheral */ \
8544fc9857aSLuiz Augusto von Dentz 	 (hdev->le_states[3] & 0x10))	/* Simultaneous */
8554fc9857aSLuiz Augusto von Dentz 
856686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */
857e74e58f8SJoe Perches int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
858e74e58f8SJoe Perches int l2cap_disconn_ind(struct hci_conn *hcon);
8599b4c3336SArron Wang void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
860686ebf28SUlisses Furquim 
861ff50e8afSArron Wang #if IS_ENABLED(CONFIG_BT_BREDR)
862e74e58f8SJoe Perches int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
8639b4c3336SArron Wang void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
864ff50e8afSArron Wang #else
865ff50e8afSArron Wang static inline int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
866ff50e8afSArron Wang 				  __u8 *flags)
867ff50e8afSArron Wang {
868ff50e8afSArron Wang 	return 0;
869ff50e8afSArron Wang }
870ff50e8afSArron Wang 
871ff50e8afSArron Wang static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb)
872ff50e8afSArron Wang {
873ff50e8afSArron Wang }
874ff50e8afSArron Wang #endif
875686ebf28SUlisses Furquim 
876ccf74f23SLuiz Augusto von Dentz #if IS_ENABLED(CONFIG_BT_LE)
877ccf74f23SLuiz Augusto von Dentz int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
878ccf74f23SLuiz Augusto von Dentz void iso_recv(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
879ccf74f23SLuiz Augusto von Dentz #else
880ccf74f23SLuiz Augusto von Dentz static inline int iso_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
881ccf74f23SLuiz Augusto von Dentz 				  __u8 *flags)
882ccf74f23SLuiz Augusto von Dentz {
883ccf74f23SLuiz Augusto von Dentz 	return 0;
884ccf74f23SLuiz Augusto von Dentz }
885ccf74f23SLuiz Augusto von Dentz static inline void iso_recv(struct hci_conn *hcon, struct sk_buff *skb,
886ccf74f23SLuiz Augusto von Dentz 			    u16 flags)
887ccf74f23SLuiz Augusto von Dentz {
888ccf74f23SLuiz Augusto von Dentz }
889ccf74f23SLuiz Augusto von Dentz #endif
890ccf74f23SLuiz Augusto von Dentz 
8911da177e4SLinus Torvalds /* ----- Inquiry cache ----- */
89270f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX   (HZ*30)   /* 30 seconds */
89370f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   /* 60 seconds */
8941da177e4SLinus Torvalds 
89530883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev)
8961da177e4SLinus Torvalds {
897ff9ef578SJohan Hedberg 	hdev->discovery.state = DISCOVERY_STOPPED;
89830883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.all);
89930883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.unknown);
90030883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.resolve);
901da25cf6aSMarcel Holtmann 	hdev->discovery.report_invalid_rssi = true;
90237eab042SJakub Pawlowski 	hdev->discovery.rssi = HCI_RSSI_INVALID;
9031da177e4SLinus Torvalds }
9041da177e4SLinus Torvalds 
9050256325eSMarcel Holtmann static inline void hci_discovery_filter_clear(struct hci_dev *hdev)
9060256325eSMarcel Holtmann {
90782f8b651SJakub Pawlowski 	hdev->discovery.result_filtering = false;
908da25cf6aSMarcel Holtmann 	hdev->discovery.report_invalid_rssi = true;
9090256325eSMarcel Holtmann 	hdev->discovery.rssi = HCI_RSSI_INVALID;
9100256325eSMarcel Holtmann 	hdev->discovery.uuid_count = 0;
9110256325eSMarcel Holtmann 	kfree(hdev->discovery.uuids);
9120256325eSMarcel Holtmann 	hdev->discovery.uuids = NULL;
9132d28cfe7SJakub Pawlowski 	hdev->discovery.scan_start = 0;
9142d28cfe7SJakub Pawlowski 	hdev->discovery.scan_duration = 0;
9150256325eSMarcel Holtmann }
9160256325eSMarcel Holtmann 
91730dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev);
91830dc78e1SJohan Hedberg 
919ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state);
920ff9ef578SJohan Hedberg 
9211da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev)
9221da177e4SLinus Torvalds {
92330883512SJohan Hedberg 	return list_empty(&hdev->discovery.all);
9241da177e4SLinus Torvalds }
9251da177e4SLinus Torvalds 
9261da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev)
9271da177e4SLinus Torvalds {
92830883512SJohan Hedberg 	struct discovery_state *c = &hdev->discovery;
9291da177e4SLinus Torvalds 	return jiffies - c->timestamp;
9301da177e4SLinus Torvalds }
9311da177e4SLinus Torvalds 
9321da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e)
9331da177e4SLinus Torvalds {
9341da177e4SLinus Torvalds 	return jiffies - e->timestamp;
9351da177e4SLinus Torvalds }
9361da177e4SLinus Torvalds 
9375a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
9385a9d0a3fSWaldemar Rymarkiewicz 					       bdaddr_t *bdaddr);
939561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
940561aafbcSJohan Hedberg 						       bdaddr_t *bdaddr);
94130dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
94230dc78e1SJohan Hedberg 						       bdaddr_t *bdaddr,
94330dc78e1SJohan Hedberg 						       int state);
944a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
945a3d4e20aSJohan Hedberg 				      struct inquiry_entry *ie);
946af58925cSMarcel Holtmann u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
947af58925cSMarcel Holtmann 			     bool name_known);
9481f9b9a5dSAndre Guedes void hci_inquiry_cache_flush(struct hci_dev *hdev);
9491da177e4SLinus Torvalds 
9501da177e4SLinus Torvalds /* ----- HCI Connections ----- */
9511da177e4SLinus Torvalds enum {
9521da177e4SLinus Torvalds 	HCI_CONN_AUTH_PEND,
95319f8def0SWaldemar Rymarkiewicz 	HCI_CONN_REAUTH_PEND,
9541da177e4SLinus Torvalds 	HCI_CONN_ENCRYPT_PEND,
95504837f64SMarcel Holtmann 	HCI_CONN_RSWITCH_PEND,
95604837f64SMarcel Holtmann 	HCI_CONN_MODE_CHANGE_PEND,
957e73439d8SMarcel Holtmann 	HCI_CONN_SCO_SETUP_PEND,
958b644ba33SJohan Hedberg 	HCI_CONN_MGMT_CONNECTED,
95958a681efSJohan Hedberg 	HCI_CONN_SSP_ENABLED,
960eb9a8f3fSMarcel Holtmann 	HCI_CONN_SC_ENABLED,
961abf76badSMarcel Holtmann 	HCI_CONN_AES_CCM,
96258a681efSJohan Hedberg 	HCI_CONN_POWER_SAVE,
963af6a9c32SJohan Hedberg 	HCI_CONN_FLUSH_KEY,
9644dae2798SJohan Hedberg 	HCI_CONN_ENCRYPT,
9654dae2798SJohan Hedberg 	HCI_CONN_AUTH,
9664dae2798SJohan Hedberg 	HCI_CONN_SECURE,
9674dae2798SJohan Hedberg 	HCI_CONN_FIPS,
968fe59a05fSJohan Hedberg 	HCI_CONN_STK_ENCRYPT,
969977f8fceSJohan Hedberg 	HCI_CONN_AUTH_INITIATOR,
970f94b665dSJohan Hedberg 	HCI_CONN_DROP,
971b62e7220SLuiz Augusto von Dentz 	HCI_CONN_CANCEL,
97289cbb063SAlfonso Acosta 	HCI_CONN_PARAM_REMOVAL_PEND,
973fe8bc5acSJohan Hedberg 	HCI_CONN_NEW_LINK_KEY,
974158e9218SJakub Pawlowski 	HCI_CONN_SCANNING,
975160b9251SSzymon Janc 	HCI_CONN_AUTH_FAILURE,
976eca0ae4aSLuiz Augusto von Dentz 	HCI_CONN_PER_ADV,
977a0bfde16SIulia Tanasescu 	HCI_CONN_BIG_CREATED,
9787f74563eSPauli Virtanen 	HCI_CONN_CREATE_CIS,
979f777d882SIulia Tanasescu 	HCI_CONN_BIG_SYNC,
980f777d882SIulia Tanasescu 	HCI_CONN_BIG_SYNC_FAILED,
981fbdc4bc4SIulia Tanasescu 	HCI_CONN_PA_SYNC,
982fbdc4bc4SIulia Tanasescu 	HCI_CONN_PA_SYNC_FAILED,
9831da177e4SLinus Torvalds };
9841da177e4SLinus Torvalds 
985aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
986aa64a8b5SJohan Hedberg {
987aa64a8b5SJohan Hedberg 	struct hci_dev *hdev = conn->hdev;
988d7a5a11dSMarcel Holtmann 	return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) &&
989c3c7ea65SGustavo Padovan 	       test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
990aa64a8b5SJohan Hedberg }
991aa64a8b5SJohan Hedberg 
992eb9a8f3fSMarcel Holtmann static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
993eb9a8f3fSMarcel Holtmann {
994eb9a8f3fSMarcel Holtmann 	struct hci_dev *hdev = conn->hdev;
995d7a5a11dSMarcel Holtmann 	return hci_dev_test_flag(hdev, HCI_SC_ENABLED) &&
996eb9a8f3fSMarcel Holtmann 	       test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
997eb9a8f3fSMarcel Holtmann }
998eb9a8f3fSMarcel Holtmann 
9991da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
10001da177e4SLinus Torvalds {
10011da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
1002d4b20f0bSLuiz Augusto von Dentz 	list_add_tail_rcu(&c->list, &h->list);
1003fcd89c09SVille Tervo 	switch (c->type) {
1004fcd89c09SVille Tervo 	case ACL_LINK:
10051da177e4SLinus Torvalds 		h->acl_num++;
1006fcd89c09SVille Tervo 		break;
1007bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1008bd1eb66bSAndrei Emeltchenko 		h->amp_num++;
1009bd1eb66bSAndrei Emeltchenko 		break;
1010fcd89c09SVille Tervo 	case LE_LINK:
1011fcd89c09SVille Tervo 		h->le_num++;
1012f8218dc6SJohan Hedberg 		if (c->role == HCI_ROLE_SLAVE)
101339bc74caSArchie Pusaka 			h->le_num_peripheral++;
1014fcd89c09SVille Tervo 		break;
1015fcd89c09SVille Tervo 	case SCO_LINK:
1016fcd89c09SVille Tervo 	case ESCO_LINK:
10171da177e4SLinus Torvalds 		h->sco_num++;
1018fcd89c09SVille Tervo 		break;
101926afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
102026afbd82SLuiz Augusto von Dentz 		h->iso_num++;
102126afbd82SLuiz Augusto von Dentz 		break;
1022fcd89c09SVille Tervo 	}
10231da177e4SLinus Torvalds }
10241da177e4SLinus Torvalds 
10251da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
10261da177e4SLinus Torvalds {
10271da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
1028bf4c6325SGustavo F. Padovan 
1029bf4c6325SGustavo F. Padovan 	list_del_rcu(&c->list);
1030bf4c6325SGustavo F. Padovan 	synchronize_rcu();
1031bf4c6325SGustavo F. Padovan 
1032fcd89c09SVille Tervo 	switch (c->type) {
1033fcd89c09SVille Tervo 	case ACL_LINK:
10341da177e4SLinus Torvalds 		h->acl_num--;
1035fcd89c09SVille Tervo 		break;
1036bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1037bd1eb66bSAndrei Emeltchenko 		h->amp_num--;
1038bd1eb66bSAndrei Emeltchenko 		break;
1039fcd89c09SVille Tervo 	case LE_LINK:
1040fcd89c09SVille Tervo 		h->le_num--;
1041f8218dc6SJohan Hedberg 		if (c->role == HCI_ROLE_SLAVE)
104239bc74caSArchie Pusaka 			h->le_num_peripheral--;
1043fcd89c09SVille Tervo 		break;
1044fcd89c09SVille Tervo 	case SCO_LINK:
1045fcd89c09SVille Tervo 	case ESCO_LINK:
10461da177e4SLinus Torvalds 		h->sco_num--;
1047fcd89c09SVille Tervo 		break;
104826afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
104926afbd82SLuiz Augusto von Dentz 		h->iso_num--;
105026afbd82SLuiz Augusto von Dentz 		break;
1051fcd89c09SVille Tervo 	}
10521da177e4SLinus Torvalds }
10531da177e4SLinus Torvalds 
105452087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
105552087a79SLuiz Augusto von Dentz {
105652087a79SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
105752087a79SLuiz Augusto von Dentz 	switch (type) {
105852087a79SLuiz Augusto von Dentz 	case ACL_LINK:
105952087a79SLuiz Augusto von Dentz 		return h->acl_num;
1060bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
1061bd1eb66bSAndrei Emeltchenko 		return h->amp_num;
106252087a79SLuiz Augusto von Dentz 	case LE_LINK:
106352087a79SLuiz Augusto von Dentz 		return h->le_num;
106452087a79SLuiz Augusto von Dentz 	case SCO_LINK:
106552087a79SLuiz Augusto von Dentz 	case ESCO_LINK:
106652087a79SLuiz Augusto von Dentz 		return h->sco_num;
106726afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
106826afbd82SLuiz Augusto von Dentz 		return h->iso_num;
106952087a79SLuiz Augusto von Dentz 	default:
107052087a79SLuiz Augusto von Dentz 		return 0;
107152087a79SLuiz Augusto von Dentz 	}
107252087a79SLuiz Augusto von Dentz }
107352087a79SLuiz Augusto von Dentz 
1074f4f07505SJohan Hedberg static inline unsigned int hci_conn_count(struct hci_dev *hdev)
1075f4f07505SJohan Hedberg {
1076f4f07505SJohan Hedberg 	struct hci_conn_hash *c = &hdev->conn_hash;
1077f4f07505SJohan Hedberg 
107826afbd82SLuiz Augusto von Dentz 	return c->acl_num + c->amp_num + c->sco_num + c->le_num + c->iso_num;
1079f4f07505SJohan Hedberg }
1080f4f07505SJohan Hedberg 
1081845472e8SMarcel Holtmann static inline __u8 hci_conn_lookup_type(struct hci_dev *hdev, __u16 handle)
1082845472e8SMarcel Holtmann {
1083845472e8SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
1084845472e8SMarcel Holtmann 	struct hci_conn *c;
1085845472e8SMarcel Holtmann 	__u8 type = INVALID_LINK;
1086845472e8SMarcel Holtmann 
1087845472e8SMarcel Holtmann 	rcu_read_lock();
1088845472e8SMarcel Holtmann 
1089845472e8SMarcel Holtmann 	list_for_each_entry_rcu(c, &h->list, list) {
1090845472e8SMarcel Holtmann 		if (c->handle == handle) {
1091845472e8SMarcel Holtmann 			type = c->type;
1092845472e8SMarcel Holtmann 			break;
1093845472e8SMarcel Holtmann 		}
1094845472e8SMarcel Holtmann 	}
1095845472e8SMarcel Holtmann 
1096845472e8SMarcel Holtmann 	rcu_read_unlock();
1097845472e8SMarcel Holtmann 
1098845472e8SMarcel Holtmann 	return type;
1099845472e8SMarcel Holtmann }
1100845472e8SMarcel Holtmann 
1101eca0ae4aSLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_bis(struct hci_dev *hdev,
11026a42e9bfSIulia Tanasescu 							bdaddr_t *ba, __u8 bis)
1103eca0ae4aSLuiz Augusto von Dentz {
1104eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1105eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn  *c;
1106eca0ae4aSLuiz Augusto von Dentz 
1107eca0ae4aSLuiz Augusto von Dentz 	rcu_read_lock();
1108eca0ae4aSLuiz Augusto von Dentz 
1109eca0ae4aSLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1110eca0ae4aSLuiz Augusto von Dentz 		if (bacmp(&c->dst, ba) || c->type != ISO_LINK)
1111eca0ae4aSLuiz Augusto von Dentz 			continue;
1112eca0ae4aSLuiz Augusto von Dentz 
11136a42e9bfSIulia Tanasescu 		if (c->iso_qos.bcast.bis == bis) {
1114eca0ae4aSLuiz Augusto von Dentz 			rcu_read_unlock();
1115eca0ae4aSLuiz Augusto von Dentz 			return c;
1116eca0ae4aSLuiz Augusto von Dentz 		}
1117eca0ae4aSLuiz Augusto von Dentz 	}
1118eca0ae4aSLuiz Augusto von Dentz 	rcu_read_unlock();
1119eca0ae4aSLuiz Augusto von Dentz 
1120eca0ae4aSLuiz Augusto von Dentz 	return NULL;
1121eca0ae4aSLuiz Augusto von Dentz }
1122eca0ae4aSLuiz Augusto von Dentz 
1123a0bfde16SIulia Tanasescu static inline struct hci_conn *
1124a0bfde16SIulia Tanasescu hci_conn_hash_lookup_per_adv_bis(struct hci_dev *hdev,
1125a0bfde16SIulia Tanasescu 				 bdaddr_t *ba,
1126a0bfde16SIulia Tanasescu 				 __u8 big, __u8 bis)
1127a0bfde16SIulia Tanasescu {
1128a0bfde16SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1129a0bfde16SIulia Tanasescu 	struct hci_conn  *c;
1130a0bfde16SIulia Tanasescu 
1131a0bfde16SIulia Tanasescu 	rcu_read_lock();
1132a0bfde16SIulia Tanasescu 
1133a0bfde16SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1134a0bfde16SIulia Tanasescu 		if (bacmp(&c->dst, ba) || c->type != ISO_LINK ||
1135a0bfde16SIulia Tanasescu 			!test_bit(HCI_CONN_PER_ADV, &c->flags))
1136a0bfde16SIulia Tanasescu 			continue;
1137a0bfde16SIulia Tanasescu 
1138a0bfde16SIulia Tanasescu 		if (c->iso_qos.bcast.big == big &&
1139a0bfde16SIulia Tanasescu 		    c->iso_qos.bcast.bis == bis) {
1140a0bfde16SIulia Tanasescu 			rcu_read_unlock();
1141a0bfde16SIulia Tanasescu 			return c;
1142a0bfde16SIulia Tanasescu 		}
1143a0bfde16SIulia Tanasescu 	}
1144a0bfde16SIulia Tanasescu 	rcu_read_unlock();
1145a0bfde16SIulia Tanasescu 
1146a0bfde16SIulia Tanasescu 	return NULL;
1147a0bfde16SIulia Tanasescu }
1148a0bfde16SIulia Tanasescu 
11491da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
11501da177e4SLinus Torvalds 								__u16 handle)
11511da177e4SLinus Torvalds {
11521da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
11531da177e4SLinus Torvalds 	struct hci_conn  *c;
11541da177e4SLinus Torvalds 
1155bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1156bf4c6325SGustavo F. Padovan 
1157bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1158bf4c6325SGustavo F. Padovan 		if (c->handle == handle) {
1159bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
11601da177e4SLinus Torvalds 			return c;
11611da177e4SLinus Torvalds 		}
1162bf4c6325SGustavo F. Padovan 	}
1163bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1164bf4c6325SGustavo F. Padovan 
11651da177e4SLinus Torvalds 	return NULL;
11661da177e4SLinus Torvalds }
11671da177e4SLinus Torvalds 
11681da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
11691da177e4SLinus Torvalds 							__u8 type, bdaddr_t *ba)
11701da177e4SLinus Torvalds {
11711da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
11721da177e4SLinus Torvalds 	struct hci_conn  *c;
11731da177e4SLinus Torvalds 
1174bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1175bf4c6325SGustavo F. Padovan 
1176bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1177bf4c6325SGustavo F. Padovan 		if (c->type == type && !bacmp(&c->dst, ba)) {
1178bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
11791da177e4SLinus Torvalds 			return c;
11801da177e4SLinus Torvalds 		}
1181bf4c6325SGustavo F. Padovan 	}
1182bf4c6325SGustavo F. Padovan 
1183bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1184bf4c6325SGustavo F. Padovan 
11851da177e4SLinus Torvalds 	return NULL;
11861da177e4SLinus Torvalds }
11871da177e4SLinus Torvalds 
11881b51c7b6SJohan Hedberg static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev,
11891b51c7b6SJohan Hedberg 						       bdaddr_t *ba,
11901b51c7b6SJohan Hedberg 						       __u8 ba_type)
11911b51c7b6SJohan Hedberg {
11921b51c7b6SJohan Hedberg 	struct hci_conn_hash *h = &hdev->conn_hash;
11931b51c7b6SJohan Hedberg 	struct hci_conn  *c;
11941b51c7b6SJohan Hedberg 
11951b51c7b6SJohan Hedberg 	rcu_read_lock();
11961b51c7b6SJohan Hedberg 
11971b51c7b6SJohan Hedberg 	list_for_each_entry_rcu(c, &h->list, list) {
11981b51c7b6SJohan Hedberg 		if (c->type != LE_LINK)
11991b51c7b6SJohan Hedberg 		       continue;
12001b51c7b6SJohan Hedberg 
12011b51c7b6SJohan Hedberg 		if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) {
12021b51c7b6SJohan Hedberg 			rcu_read_unlock();
12031b51c7b6SJohan Hedberg 			return c;
12041b51c7b6SJohan Hedberg 		}
12051b51c7b6SJohan Hedberg 	}
12061b51c7b6SJohan Hedberg 
12071b51c7b6SJohan Hedberg 	rcu_read_unlock();
12081b51c7b6SJohan Hedberg 
12091b51c7b6SJohan Hedberg 	return NULL;
12101b51c7b6SJohan Hedberg }
12111b51c7b6SJohan Hedberg 
121226afbd82SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_cis(struct hci_dev *hdev,
121326afbd82SLuiz Augusto von Dentz 							bdaddr_t *ba,
1214c14516faSLuiz Augusto von Dentz 							__u8 ba_type,
1215c14516faSLuiz Augusto von Dentz 							__u8 cig,
1216c14516faSLuiz Augusto von Dentz 							__u8 id)
121726afbd82SLuiz Augusto von Dentz {
121826afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
121926afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
122026afbd82SLuiz Augusto von Dentz 
122126afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
122226afbd82SLuiz Augusto von Dentz 
122326afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1224b5793de3SPauli Virtanen 		if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
122526afbd82SLuiz Augusto von Dentz 			continue;
122626afbd82SLuiz Augusto von Dentz 
1227c14516faSLuiz Augusto von Dentz 		/* Match CIG ID if set */
1228c14516faSLuiz Augusto von Dentz 		if (cig != BT_ISO_QOS_CIG_UNSET && cig != c->iso_qos.ucast.cig)
1229c14516faSLuiz Augusto von Dentz 			continue;
1230c14516faSLuiz Augusto von Dentz 
1231c14516faSLuiz Augusto von Dentz 		/* Match CIS ID if set */
1232c14516faSLuiz Augusto von Dentz 		if (id != BT_ISO_QOS_CIS_UNSET && id != c->iso_qos.ucast.cis)
1233c14516faSLuiz Augusto von Dentz 			continue;
1234c14516faSLuiz Augusto von Dentz 
123571e95884SPauli Virtanen 		/* Match destination address if set */
123671e95884SPauli Virtanen 		if (!ba || (ba_type == c->dst_type && !bacmp(&c->dst, ba))) {
123726afbd82SLuiz Augusto von Dentz 			rcu_read_unlock();
123826afbd82SLuiz Augusto von Dentz 			return c;
123926afbd82SLuiz Augusto von Dentz 		}
124026afbd82SLuiz Augusto von Dentz 	}
124126afbd82SLuiz Augusto von Dentz 
124226afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
124326afbd82SLuiz Augusto von Dentz 
124426afbd82SLuiz Augusto von Dentz 	return NULL;
124526afbd82SLuiz Augusto von Dentz }
124626afbd82SLuiz Augusto von Dentz 
124726afbd82SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_cig(struct hci_dev *hdev,
124826afbd82SLuiz Augusto von Dentz 							__u8 handle)
124926afbd82SLuiz Augusto von Dentz {
125026afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
125126afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
125226afbd82SLuiz Augusto von Dentz 
125326afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
125426afbd82SLuiz Augusto von Dentz 
125526afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1256b5793de3SPauli Virtanen 		if (c->type != ISO_LINK || !bacmp(&c->dst, BDADDR_ANY))
125726afbd82SLuiz Augusto von Dentz 			continue;
125826afbd82SLuiz Augusto von Dentz 
12590fe8c8d0SIulia Tanasescu 		if (handle == c->iso_qos.ucast.cig) {
126026afbd82SLuiz Augusto von Dentz 			rcu_read_unlock();
126126afbd82SLuiz Augusto von Dentz 			return c;
126226afbd82SLuiz Augusto von Dentz 		}
126326afbd82SLuiz Augusto von Dentz 	}
126426afbd82SLuiz Augusto von Dentz 
126526afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
126626afbd82SLuiz Augusto von Dentz 
126726afbd82SLuiz Augusto von Dentz 	return NULL;
126826afbd82SLuiz Augusto von Dentz }
126926afbd82SLuiz Augusto von Dentz 
1270eca0ae4aSLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hash_lookup_big(struct hci_dev *hdev,
1271eca0ae4aSLuiz Augusto von Dentz 							__u8 handle)
1272eca0ae4aSLuiz Augusto von Dentz {
1273eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1274eca0ae4aSLuiz Augusto von Dentz 	struct hci_conn  *c;
1275eca0ae4aSLuiz Augusto von Dentz 
1276eca0ae4aSLuiz Augusto von Dentz 	rcu_read_lock();
1277eca0ae4aSLuiz Augusto von Dentz 
1278eca0ae4aSLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1279eca0ae4aSLuiz Augusto von Dentz 		if (bacmp(&c->dst, BDADDR_ANY) || c->type != ISO_LINK)
1280eca0ae4aSLuiz Augusto von Dentz 			continue;
1281eca0ae4aSLuiz Augusto von Dentz 
12820fe8c8d0SIulia Tanasescu 		if (handle == c->iso_qos.bcast.big) {
1283eca0ae4aSLuiz Augusto von Dentz 			rcu_read_unlock();
1284eca0ae4aSLuiz Augusto von Dentz 			return c;
1285eca0ae4aSLuiz Augusto von Dentz 		}
1286eca0ae4aSLuiz Augusto von Dentz 	}
1287eca0ae4aSLuiz Augusto von Dentz 
1288eca0ae4aSLuiz Augusto von Dentz 	rcu_read_unlock();
1289eca0ae4aSLuiz Augusto von Dentz 
1290eca0ae4aSLuiz Augusto von Dentz 	return NULL;
1291eca0ae4aSLuiz Augusto von Dentz }
1292eca0ae4aSLuiz Augusto von Dentz 
1293f777d882SIulia Tanasescu static inline struct hci_conn *hci_conn_hash_lookup_big_any_dst(struct hci_dev *hdev,
1294f777d882SIulia Tanasescu 							__u8 handle)
1295f777d882SIulia Tanasescu {
1296f777d882SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1297f777d882SIulia Tanasescu 	struct hci_conn  *c;
1298f777d882SIulia Tanasescu 
1299f777d882SIulia Tanasescu 	rcu_read_lock();
1300f777d882SIulia Tanasescu 
1301f777d882SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1302f777d882SIulia Tanasescu 		if (c->type != ISO_LINK)
1303f777d882SIulia Tanasescu 			continue;
1304f777d882SIulia Tanasescu 
1305fbdc4bc4SIulia Tanasescu 		if (handle != BT_ISO_QOS_BIG_UNSET && handle == c->iso_qos.bcast.big) {
1306f777d882SIulia Tanasescu 			rcu_read_unlock();
1307f777d882SIulia Tanasescu 			return c;
1308f777d882SIulia Tanasescu 		}
1309f777d882SIulia Tanasescu 	}
1310f777d882SIulia Tanasescu 
1311f777d882SIulia Tanasescu 	rcu_read_unlock();
1312f777d882SIulia Tanasescu 
1313f777d882SIulia Tanasescu 	return NULL;
1314f777d882SIulia Tanasescu }
1315f777d882SIulia Tanasescu 
1316fbdc4bc4SIulia Tanasescu static inline struct hci_conn *
1317*23417475SIulia Tanasescu hci_conn_hash_lookup_pa_sync_big_handle(struct hci_dev *hdev, __u8 big)
1318fbdc4bc4SIulia Tanasescu {
1319fbdc4bc4SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1320fbdc4bc4SIulia Tanasescu 	struct hci_conn  *c;
1321fbdc4bc4SIulia Tanasescu 
1322fbdc4bc4SIulia Tanasescu 	rcu_read_lock();
1323fbdc4bc4SIulia Tanasescu 
1324fbdc4bc4SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1325fbdc4bc4SIulia Tanasescu 		if (c->type != ISO_LINK ||
1326fbdc4bc4SIulia Tanasescu 			!test_bit(HCI_CONN_PA_SYNC, &c->flags))
1327fbdc4bc4SIulia Tanasescu 			continue;
1328fbdc4bc4SIulia Tanasescu 
1329fbdc4bc4SIulia Tanasescu 		if (c->iso_qos.bcast.big == big) {
1330fbdc4bc4SIulia Tanasescu 			rcu_read_unlock();
1331fbdc4bc4SIulia Tanasescu 			return c;
1332fbdc4bc4SIulia Tanasescu 		}
1333fbdc4bc4SIulia Tanasescu 	}
1334fbdc4bc4SIulia Tanasescu 	rcu_read_unlock();
1335fbdc4bc4SIulia Tanasescu 
1336fbdc4bc4SIulia Tanasescu 	return NULL;
1337fbdc4bc4SIulia Tanasescu }
1338fbdc4bc4SIulia Tanasescu 
1339*23417475SIulia Tanasescu static inline struct hci_conn *
1340*23417475SIulia Tanasescu hci_conn_hash_lookup_pa_sync_handle(struct hci_dev *hdev, __u16 sync_handle)
1341*23417475SIulia Tanasescu {
1342*23417475SIulia Tanasescu 	struct hci_conn_hash *h = &hdev->conn_hash;
1343*23417475SIulia Tanasescu 	struct hci_conn  *c;
1344*23417475SIulia Tanasescu 
1345*23417475SIulia Tanasescu 	rcu_read_lock();
1346*23417475SIulia Tanasescu 
1347*23417475SIulia Tanasescu 	list_for_each_entry_rcu(c, &h->list, list) {
1348*23417475SIulia Tanasescu 		if (c->type != ISO_LINK ||
1349*23417475SIulia Tanasescu 			!test_bit(HCI_CONN_PA_SYNC, &c->flags))
1350*23417475SIulia Tanasescu 			continue;
1351*23417475SIulia Tanasescu 
1352*23417475SIulia Tanasescu 		if (c->sync_handle == sync_handle) {
1353*23417475SIulia Tanasescu 			rcu_read_unlock();
1354*23417475SIulia Tanasescu 			return c;
1355*23417475SIulia Tanasescu 		}
1356*23417475SIulia Tanasescu 	}
1357*23417475SIulia Tanasescu 	rcu_read_unlock();
1358*23417475SIulia Tanasescu 
1359*23417475SIulia Tanasescu 	return NULL;
1360*23417475SIulia Tanasescu }
1361*23417475SIulia Tanasescu 
13624c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
13634c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
13644c67bc74SMarcel Holtmann {
13654c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
13664c67bc74SMarcel Holtmann 	struct hci_conn  *c;
13674c67bc74SMarcel Holtmann 
1368bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1369bf4c6325SGustavo F. Padovan 
1370bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1371bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
1372bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
13734c67bc74SMarcel Holtmann 			return c;
13744c67bc74SMarcel Holtmann 		}
1375bf4c6325SGustavo F. Padovan 	}
1376bf4c6325SGustavo F. Padovan 
1377bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1378bf4c6325SGustavo F. Padovan 
13794c67bc74SMarcel Holtmann 	return NULL;
13804c67bc74SMarcel Holtmann }
13814c67bc74SMarcel Holtmann 
138226afbd82SLuiz Augusto von Dentz typedef void (*hci_conn_func_t)(struct hci_conn *conn, void *data);
138326afbd82SLuiz Augusto von Dentz static inline void hci_conn_hash_list_state(struct hci_dev *hdev,
138426afbd82SLuiz Augusto von Dentz 					    hci_conn_func_t func, __u8 type,
138526afbd82SLuiz Augusto von Dentz 					    __u16 state, void *data)
138626afbd82SLuiz Augusto von Dentz {
138726afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
138826afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
138926afbd82SLuiz Augusto von Dentz 
139026afbd82SLuiz Augusto von Dentz 	if (!func)
139126afbd82SLuiz Augusto von Dentz 		return;
139226afbd82SLuiz Augusto von Dentz 
139326afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
139426afbd82SLuiz Augusto von Dentz 
139526afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
139626afbd82SLuiz Augusto von Dentz 		if (c->type == type && c->state == state)
139726afbd82SLuiz Augusto von Dentz 			func(c, data);
139826afbd82SLuiz Augusto von Dentz 	}
139926afbd82SLuiz Augusto von Dentz 
140026afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
140126afbd82SLuiz Augusto von Dentz }
140226afbd82SLuiz Augusto von Dentz 
1403e7d9ab73SJakub Pawlowski static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev)
1404e7d9ab73SJakub Pawlowski {
1405e7d9ab73SJakub Pawlowski 	struct hci_conn_hash *h = &hdev->conn_hash;
1406e7d9ab73SJakub Pawlowski 	struct hci_conn  *c;
1407e7d9ab73SJakub Pawlowski 
1408e7d9ab73SJakub Pawlowski 	rcu_read_lock();
1409e7d9ab73SJakub Pawlowski 
1410e7d9ab73SJakub Pawlowski 	list_for_each_entry_rcu(c, &h->list, list) {
1411e7d9ab73SJakub Pawlowski 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1412e7d9ab73SJakub Pawlowski 		    !test_bit(HCI_CONN_SCANNING, &c->flags)) {
1413e7d9ab73SJakub Pawlowski 			rcu_read_unlock();
1414e7d9ab73SJakub Pawlowski 			return c;
1415e7d9ab73SJakub Pawlowski 		}
1416e7d9ab73SJakub Pawlowski 	}
1417e7d9ab73SJakub Pawlowski 
1418e7d9ab73SJakub Pawlowski 	rcu_read_unlock();
1419e7d9ab73SJakub Pawlowski 
1420e7d9ab73SJakub Pawlowski 	return NULL;
1421e7d9ab73SJakub Pawlowski }
1422e7d9ab73SJakub Pawlowski 
1423f8867016SLuiz Augusto von Dentz /* Returns true if an le connection is in the scanning state */
1424f8867016SLuiz Augusto von Dentz static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev)
1425f8867016SLuiz Augusto von Dentz {
1426f8867016SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1427f8867016SLuiz Augusto von Dentz 	struct hci_conn  *c;
1428f8867016SLuiz Augusto von Dentz 
1429f8867016SLuiz Augusto von Dentz 	rcu_read_lock();
1430f8867016SLuiz Augusto von Dentz 
1431f8867016SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1432f8867016SLuiz Augusto von Dentz 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1433f8867016SLuiz Augusto von Dentz 		    test_bit(HCI_CONN_SCANNING, &c->flags)) {
1434f8867016SLuiz Augusto von Dentz 			rcu_read_unlock();
1435f8867016SLuiz Augusto von Dentz 			return true;
1436f8867016SLuiz Augusto von Dentz 		}
1437f8867016SLuiz Augusto von Dentz 	}
1438f8867016SLuiz Augusto von Dentz 
1439f8867016SLuiz Augusto von Dentz 	rcu_read_unlock();
1440f8867016SLuiz Augusto von Dentz 
1441f8867016SLuiz Augusto von Dentz 	return false;
1442f8867016SLuiz Augusto von Dentz }
1443f8867016SLuiz Augusto von Dentz 
1444e3b679d5SJohan Hedberg int hci_disconnect(struct hci_conn *conn, __u8 reason);
14452dea632fSFrédéric Dalleau bool hci_setup_sync(struct hci_conn *conn, __u16 handle);
1446e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
144726afbd82SLuiz Augusto von Dentz bool hci_iso_setup_path(struct hci_conn *conn);
14487f74563eSPauli Virtanen int hci_le_create_cis_pending(struct hci_dev *hdev);
14497f74563eSPauli Virtanen int hci_conn_check_create_cis(struct hci_conn *conn);
14501da177e4SLinus Torvalds 
1451a5c4e309SJohan Hedberg struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
1452a5c4e309SJohan Hedberg 			      u8 role);
1453a2ac591cSRuihan Li void hci_conn_del(struct hci_conn *conn);
14541da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
1455a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
14561da177e4SLinus Torvalds 
145773d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
14589472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan);
14592c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
146042c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
146173d80debSLuiz Augusto von Dentz 
1462f75113a2SJakub Pawlowski struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
1463f75113a2SJakub Pawlowski 				     u8 dst_type, u8 sec_level,
146476b13996SManish Mandlik 				     u16 conn_timeout,
146576b13996SManish Mandlik 				     enum conn_reasons conn_reason);
146604a6c589SAndre Guedes struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1467d850bf08SLuiz Augusto von Dentz 				u8 dst_type, bool dst_resolved, u8 sec_level,
14688e8b92eeSLuiz Augusto von Dentz 				u16 conn_timeout, u8 role);
146904a6c589SAndre Guedes struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
147076b13996SManish Mandlik 				 u8 sec_level, u8 auth_type,
147176b13996SManish Mandlik 				 enum conn_reasons conn_reason);
147210c62ddcSFrédéric Dalleau struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1473b2af264aSKiran K 				 __u16 setting, struct bt_codec *codec);
147426afbd82SLuiz Augusto von Dentz struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
147526afbd82SLuiz Augusto von Dentz 			      __u8 dst_type, struct bt_iso_qos *qos);
1476a0bfde16SIulia Tanasescu struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,
1477a0bfde16SIulia Tanasescu 			      struct bt_iso_qos *qos,
1478a0bfde16SIulia Tanasescu 			      __u8 base_len, __u8 *base);
147926afbd82SLuiz Augusto von Dentz struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
148026afbd82SLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos);
1481eca0ae4aSLuiz Augusto von Dentz struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
1482eca0ae4aSLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos,
1483eca0ae4aSLuiz Augusto von Dentz 				 __u8 data_len, __u8 *data);
1484eca0ae4aSLuiz Augusto von Dentz int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type,
14850fe8c8d0SIulia Tanasescu 		       __u8 sid, struct bt_iso_qos *qos);
1486fbdc4bc4SIulia Tanasescu int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
1487fbdc4bc4SIulia Tanasescu 			   struct bt_iso_qos *qos,
1488eca0ae4aSLuiz Augusto von Dentz 			   __u16 sync_handle, __u8 num_bis, __u8 bis[]);
1489e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
1490b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
1491e7cafc45SJohan Hedberg int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type,
1492e7cafc45SJohan Hedberg 		      bool initiator);
14938c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
14941da177e4SLinus Torvalds 
149514b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
14961da177e4SLinus Torvalds 
14979b3628d7SLuiz Augusto von Dentz void hci_conn_failed(struct hci_conn *conn, u8 status);
149816e3b642SLuiz Augusto von Dentz u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle);
149906c053fbSAndre Guedes 
15008d12356fSDavid Herrmann /*
15018d12356fSDavid Herrmann  * hci_conn_get() and hci_conn_put() are used to control the life-time of an
15028d12356fSDavid Herrmann  * "hci_conn" object. They do not guarantee that the hci_conn object is running,
15038d12356fSDavid Herrmann  * working or anything else. They just guarantee that the object is available
15048d12356fSDavid Herrmann  * and can be dereferenced. So you can use its locks, local variables and any
15058d12356fSDavid Herrmann  * other constant data.
15068d12356fSDavid Herrmann  * Before accessing runtime data, you _must_ lock the object and then check that
15078d12356fSDavid Herrmann  * it is still running. As soon as you release the locks, the connection might
15088d12356fSDavid Herrmann  * get dropped, though.
15098d12356fSDavid Herrmann  *
15108d12356fSDavid Herrmann  * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control
15118d12356fSDavid Herrmann  * how long the underlying connection is held. So every channel that runs on the
15128d12356fSDavid Herrmann  * hci_conn object calls this to prevent the connection from disappearing. As
15138d12356fSDavid Herrmann  * long as you hold a device, you must also guarantee that you have a valid
15148d12356fSDavid Herrmann  * reference to the device via hci_conn_get() (or the initial reference from
15158d12356fSDavid Herrmann  * hci_conn_add()).
15168d12356fSDavid Herrmann  * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't
15178d12356fSDavid Herrmann  * break because nobody cares for that. But this means, we cannot use
15188d12356fSDavid Herrmann  * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
15198d12356fSDavid Herrmann  */
15208d12356fSDavid Herrmann 
152151bb8457SJohan Hedberg static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
15228d12356fSDavid Herrmann {
15238d12356fSDavid Herrmann 	get_device(&conn->dev);
152451bb8457SJohan Hedberg 	return conn;
15258d12356fSDavid Herrmann }
15268d12356fSDavid Herrmann 
15278d12356fSDavid Herrmann static inline void hci_conn_put(struct hci_conn *conn)
15288d12356fSDavid Herrmann {
15298d12356fSDavid Herrmann 	put_device(&conn->dev);
15308d12356fSDavid Herrmann }
15318d12356fSDavid Herrmann 
153206149746SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hold(struct hci_conn *conn)
15331da177e4SLinus Torvalds {
153471becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
153538b3fef1SAndrei Emeltchenko 
15361da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
15372f304d1eSAndre Guedes 	cancel_delayed_work(&conn->disc_work);
153806149746SLuiz Augusto von Dentz 
153906149746SLuiz Augusto von Dentz 	return conn;
15401da177e4SLinus Torvalds }
15411da177e4SLinus Torvalds 
154276a68ba0SDavid Herrmann static inline void hci_conn_drop(struct hci_conn *conn)
15431da177e4SLinus Torvalds {
154471becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
154538b3fef1SAndrei Emeltchenko 
15461da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
154704837f64SMarcel Holtmann 		unsigned long timeo;
1548716e4ab5SAndrei Emeltchenko 
1549716e4ab5SAndrei Emeltchenko 		switch (conn->type) {
1550716e4ab5SAndrei Emeltchenko 		case ACL_LINK:
1551716e4ab5SAndrei Emeltchenko 		case LE_LINK:
1552a74a84f6SJohan Hedberg 			cancel_delayed_work(&conn->idle_work);
15536ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
15545f246e89SAndrei Emeltchenko 				timeo = conn->disc_timeout;
155504837f64SMarcel Holtmann 				if (!conn->out)
1556052b30b0SMarcel Holtmann 					timeo *= 2;
15575a9d0a3fSWaldemar Rymarkiewicz 			} else {
1558eb78d7e5SJohan Hedberg 				timeo = 0;
15595a9d0a3fSWaldemar Rymarkiewicz 			}
1560716e4ab5SAndrei Emeltchenko 			break;
1561716e4ab5SAndrei Emeltchenko 
1562716e4ab5SAndrei Emeltchenko 		case AMP_LINK:
1563716e4ab5SAndrei Emeltchenko 			timeo = conn->disc_timeout;
1564716e4ab5SAndrei Emeltchenko 			break;
1565716e4ab5SAndrei Emeltchenko 
1566716e4ab5SAndrei Emeltchenko 		default:
1567eb78d7e5SJohan Hedberg 			timeo = 0;
1568716e4ab5SAndrei Emeltchenko 			break;
15695a9d0a3fSWaldemar Rymarkiewicz 		}
1570716e4ab5SAndrei Emeltchenko 
15712f304d1eSAndre Guedes 		cancel_delayed_work(&conn->disc_work);
157219c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
15731931782bSVinicius Costa Gomes 				   &conn->disc_work, timeo);
15741da177e4SLinus Torvalds 	}
15751da177e4SLinus Torvalds }
15761da177e4SLinus Torvalds 
15771da177e4SLinus Torvalds /* ----- HCI Devices ----- */
1578dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
15791da177e4SLinus Torvalds {
1580376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15812c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1582376261aeSAndrei Emeltchenko 
15834c724c71SDavid Herrmann 	put_device(&d->dev);
1584010666a1SDavid Herrmann }
15851da177e4SLinus Torvalds 
1586dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
15871da177e4SLinus Torvalds {
1588376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15892c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1590376261aeSAndrei Emeltchenko 
15914c724c71SDavid Herrmann 	get_device(&d->dev);
15921da177e4SLinus Torvalds 	return d;
15931da177e4SLinus Torvalds }
15941da177e4SLinus Torvalds 
159509fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
159609fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
15971da177e4SLinus Torvalds 
1598aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev)
15993dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev)
1600aa2b86d7SDavid Herrmann 
1601155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev)
1602155961e8SDavid Herrmann {
1603155961e8SDavid Herrmann 	return dev_get_drvdata(&hdev->dev);
1604155961e8SDavid Herrmann }
1605155961e8SDavid Herrmann 
1606155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
1607155961e8SDavid Herrmann {
1608155961e8SDavid Herrmann 	dev_set_drvdata(&hdev->dev, data);
1609155961e8SDavid Herrmann }
1610155961e8SDavid Herrmann 
16116ec56613STedd Ho-Jeong An static inline void *hci_get_priv(struct hci_dev *hdev)
16126ec56613STedd Ho-Jeong An {
16136ec56613STedd Ho-Jeong An 	return (char *)hdev + sizeof(*hdev);
16146ec56613STedd Ho-Jeong An }
16156ec56613STedd Ho-Jeong An 
16161da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
161739385cb5SJohan Hedberg struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
16181da177e4SLinus Torvalds 
16196ec56613STedd Ho-Jeong An struct hci_dev *hci_alloc_dev_priv(int sizeof_priv);
16206ec56613STedd Ho-Jeong An 
16216ec56613STedd Ho-Jeong An static inline struct hci_dev *hci_alloc_dev(void)
16226ec56613STedd Ho-Jeong An {
16236ec56613STedd Ho-Jeong An 	return hci_alloc_dev_priv(0);
16246ec56613STedd Ho-Jeong An }
16256ec56613STedd Ho-Jeong An 
16261da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
16271da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
162859735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
162958ce6d5bSTetsuo Handa void hci_release_dev(struct hci_dev *hdev);
1630359ee4f8SAbhishek Pandit-Subedi int hci_register_suspend_notifier(struct hci_dev *hdev);
1631359ee4f8SAbhishek Pandit-Subedi int hci_unregister_suspend_notifier(struct hci_dev *hdev);
16321da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
16331da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
163475e0569fSMarcel Holtmann int hci_reset_dev(struct hci_dev *hdev);
1635f962fe32SMarcel Holtmann int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
1636f962fe32SMarcel Holtmann int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
16371aabbbceSNicolas Iooss __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
16381aabbbceSNicolas Iooss __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
1639145373cbSMiao-chen Chou 
1640145373cbSMiao-chen Chou static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
1641145373cbSMiao-chen Chou {
1642145373cbSMiao-chen Chou #if IS_ENABLED(CONFIG_BT_MSFTEXT)
1643145373cbSMiao-chen Chou 	hdev->msft_opcode = opcode;
1644145373cbSMiao-chen Chou #endif
1645145373cbSMiao-chen Chou }
1646145373cbSMiao-chen Chou 
1647f67743f9SMarcel Holtmann static inline void hci_set_aosp_capable(struct hci_dev *hdev)
1648f67743f9SMarcel Holtmann {
1649f67743f9SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_AOSPEXT)
1650f67743f9SMarcel Holtmann 	hdev->aosp_capable = true;
1651f67743f9SMarcel Holtmann #endif
1652f67743f9SMarcel Holtmann }
1653f67743f9SMarcel Holtmann 
16549695ef87SAbhishek Pandit-Subedi static inline void hci_devcd_setup(struct hci_dev *hdev)
16559695ef87SAbhishek Pandit-Subedi {
16569695ef87SAbhishek Pandit-Subedi #ifdef CONFIG_DEV_COREDUMP
16579695ef87SAbhishek Pandit-Subedi 	INIT_WORK(&hdev->dump.dump_rx, hci_devcd_rx);
16589695ef87SAbhishek Pandit-Subedi 	INIT_DELAYED_WORK(&hdev->dump.dump_timeout, hci_devcd_timeout);
16599695ef87SAbhishek Pandit-Subedi 	skb_queue_head_init(&hdev->dump.dump_q);
16609695ef87SAbhishek Pandit-Subedi #endif
16619695ef87SAbhishek Pandit-Subedi }
16629695ef87SAbhishek Pandit-Subedi 
16631da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
16641da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
16656b3cc1dbSSimon Fels int hci_dev_do_close(struct hci_dev *hdev);
16661da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
16671da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
16681da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
16691da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
16701da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
16711da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
16721da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
167340be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
16741da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
16751da177e4SLinus Torvalds 
1676dcc36c16SJohan Hedberg struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list,
1677b9ee0a78SMarcel Holtmann 					   bdaddr_t *bdaddr, u8 type);
1678b950aa88SAnkit Navik struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk(
1679b950aa88SAnkit Navik 				    struct list_head *list, bdaddr_t *bdaddr,
1680b950aa88SAnkit Navik 				    u8 type);
16818baaa403SAbhishek Pandit-Subedi struct bdaddr_list_with_flags *
16828baaa403SAbhishek Pandit-Subedi hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16838baaa403SAbhishek Pandit-Subedi 				  u8 type);
1684dcc36c16SJohan Hedberg int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1685b950aa88SAnkit Navik int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1686b950aa88SAnkit Navik 				 u8 type, u8 *peer_irk, u8 *local_irk);
16878baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16888baaa403SAbhishek Pandit-Subedi 				   u8 type, u32 flags);
1689dcc36c16SJohan Hedberg int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1690b950aa88SAnkit Navik int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1691b950aa88SAnkit Navik 				 u8 type);
16928baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16938baaa403SAbhishek Pandit-Subedi 				   u8 type);
1694dcc36c16SJohan Hedberg void hci_bdaddr_list_clear(struct list_head *list);
1695d2ab0ac1SMarcel Holtmann 
169615819a70SAndre Guedes struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
169715819a70SAndre Guedes 					       bdaddr_t *addr, u8 addr_type);
169851d167c0SMarcel Holtmann struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
169951d167c0SMarcel Holtmann 					    bdaddr_t *addr, u8 addr_type);
170015819a70SAndre Guedes void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
170155af49a8SJohan Hedberg void hci_conn_params_clear_disabled(struct hci_dev *hdev);
1702195ef75eSPauli Virtanen void hci_conn_params_free(struct hci_conn_params *param);
170315819a70SAndre Guedes 
1704195ef75eSPauli Virtanen void hci_pend_le_list_del_init(struct hci_conn_params *param);
1705195ef75eSPauli Virtanen void hci_pend_le_list_add(struct hci_conn_params *param,
1706195ef75eSPauli Virtanen 			  struct list_head *list);
1707501f8827SJohan Hedberg struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
1708501f8827SJohan Hedberg 						  bdaddr_t *addr,
1709501f8827SJohan Hedberg 						  u8 addr_type);
171077a77a30SAndre Guedes 
171135f7498aSJohan Hedberg void hci_uuids_clear(struct hci_dev *hdev);
17122aeb9a1aSJohan Hedberg 
171335f7498aSJohan Hedberg void hci_link_keys_clear(struct hci_dev *hdev);
171455ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
1715567fa2aaSJohan Hedberg struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
17167652ff6aSJohan Hedberg 				  bdaddr_t *bdaddr, u8 *val, u8 type,
17177652ff6aSJohan Hedberg 				  u8 pin_len, bool *persistent);
1718ca9142b8SJohan Hedberg struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
171935d70271SJohan Hedberg 			    u8 addr_type, u8 type, u8 authenticated,
1720fe39c7b2SMarcel Holtmann 			    u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
1721f3a73d97SJohan Hedberg struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1722e804d25dSJohan Hedberg 			     u8 addr_type, u8 role);
1723e0b2b27eSJohan Hedberg int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
172435f7498aSJohan Hedberg void hci_smp_ltks_clear(struct hci_dev *hdev);
172555ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
172655ed8ca1SJohan Hedberg 
1727970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa);
1728970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1729970c4e46SJohan Hedberg 				     u8 addr_type);
1730ca9142b8SJohan Hedberg struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1731ca9142b8SJohan Hedberg 			    u8 addr_type, u8 val[16], bdaddr_t *rpa);
1732a7ec7338SJohan Hedberg void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
1733600a8749SAlain Michaud bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]);
1734600a8749SAlain Michaud void hci_blocked_keys_clear(struct hci_dev *hdev);
1735970c4e46SJohan Hedberg void hci_smp_irks_clear(struct hci_dev *hdev);
1736970c4e46SJohan Hedberg 
173755e76b38SJohan Hedberg bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
173855e76b38SJohan Hedberg 
173935f7498aSJohan Hedberg void hci_remote_oob_data_clear(struct hci_dev *hdev);
17402763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
17416928a924SJohan Hedberg 					  bdaddr_t *bdaddr, u8 bdaddr_type);
17420798872eSMarcel Holtmann int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17436928a924SJohan Hedberg 			    u8 bdaddr_type, u8 *hash192, u8 *rand192,
174438da1703SJohan Hedberg 			    u8 *hash256, u8 *rand256);
17456928a924SJohan Hedberg int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17466928a924SJohan Hedberg 			       u8 bdaddr_type);
17472763eda6SSzymon Janc 
1748d2609b34SFlorian Grandel void hci_adv_instances_clear(struct hci_dev *hdev);
1749d2609b34SFlorian Grandel struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance);
1750d2609b34SFlorian Grandel struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance);
1751eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,
1752eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u16 adv_data_len, u8 *adv_data,
1753d2609b34SFlorian Grandel 				      u16 scan_rsp_len, u8 *scan_rsp_data,
17549bf9f4b6SDaniel Winkler 				      u16 timeout, u16 duration, s8 tx_power,
1755b338d917SBrian Gix 				      u32 min_interval, u32 max_interval,
1756b338d917SBrian Gix 				      u8 mesh_handle);
1757eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance,
1758eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u8 data_len, u8 *data,
1759eca0ae4aSLuiz Augusto von Dentz 				      u32 min_interval, u32 max_interval);
176031aab5c2SDaniel Winkler int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
176131aab5c2SDaniel Winkler 			 u16 adv_data_len, u8 *adv_data,
176231aab5c2SDaniel Winkler 			 u16 scan_rsp_len, u8 *scan_rsp_data);
1763d2609b34SFlorian Grandel int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);
1764a73c046aSJaganath Kanakkassery void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
176501ce70b0SLuiz Augusto von Dentz u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance);
176601ce70b0SLuiz Augusto von Dentz bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance);
1767d2609b34SFlorian Grandel 
1768e5e1e7fdSMiao-chen Chou void hci_adv_monitors_clear(struct hci_dev *hdev);
176966bd095aSArchie Pusaka void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
1770b747a836SManish Mandlik int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
17717cf5c297SManish Mandlik int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle);
17727cf5c297SManish Mandlik int hci_remove_all_adv_monitor(struct hci_dev *hdev);
17738208f5a9SMiao-chen Chou bool hci_is_adv_monitoring(struct hci_dev *hdev);
1774a2a4dedfSArchie Pusaka int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev);
1775e5e1e7fdSMiao-chen Chou 
17761da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
17771da177e4SLinus Torvalds 
17780ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
1779a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
1780b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
1781b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
17821da177e4SLinus Torvalds 
17836935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
1784294d749bSKiran K #define GET_HCIDEV_DEV(hdev) ((hdev)->dev.parent)
17851da177e4SLinus Torvalds 
17861da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
1787cad718edSJohan Hedberg #define lmp_encrypt_capable(dev)   ((dev)->features[0][0] & LMP_ENCRYPT)
1788cad718edSJohan Hedberg #define lmp_rswitch_capable(dev)   ((dev)->features[0][0] & LMP_RSWITCH)
1789cad718edSJohan Hedberg #define lmp_hold_capable(dev)      ((dev)->features[0][0] & LMP_HOLD)
1790cad718edSJohan Hedberg #define lmp_sniff_capable(dev)     ((dev)->features[0][0] & LMP_SNIFF)
1791cad718edSJohan Hedberg #define lmp_park_capable(dev)      ((dev)->features[0][1] & LMP_PARK)
1792cad718edSJohan Hedberg #define lmp_inq_rssi_capable(dev)  ((dev)->features[0][3] & LMP_RSSI_INQ)
1793cad718edSJohan Hedberg #define lmp_esco_capable(dev)      ((dev)->features[0][3] & LMP_ESCO)
1794cad718edSJohan Hedberg #define lmp_bredr_capable(dev)     (!((dev)->features[0][4] & LMP_NO_BREDR))
1795cad718edSJohan Hedberg #define lmp_le_capable(dev)        ((dev)->features[0][4] & LMP_LE)
1796cad718edSJohan Hedberg #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR)
1797cad718edSJohan Hedberg #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC)
17988b1c324cSYu Liu #define lmp_esco_2m_capable(dev)   ((dev)->features[0][5] & LMP_EDR_ESCO_2M)
1799cad718edSJohan Hedberg #define lmp_ext_inq_capable(dev)   ((dev)->features[0][6] & LMP_EXT_INQ)
1800cad718edSJohan Hedberg #define lmp_le_br_capable(dev)     (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR))
1801cad718edSJohan Hedberg #define lmp_ssp_capable(dev)       ((dev)->features[0][6] & LMP_SIMPLE_PAIR)
1802cad718edSJohan Hedberg #define lmp_no_flush_capable(dev)  ((dev)->features[0][6] & LMP_NO_FLUSH)
1803cad718edSJohan Hedberg #define lmp_lsto_capable(dev)      ((dev)->features[0][7] & LMP_LSTO)
1804cad718edSJohan Hedberg #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
1805cad718edSJohan Hedberg #define lmp_ext_feat_capable(dev)  ((dev)->features[0][7] & LMP_EXTFEATURES)
180607a5c61eSFrédéric Dalleau #define lmp_transp_capable(dev)    ((dev)->features[0][2] & LMP_TRANSPARENT)
18075075b972SJaganath Kanakkassery #define lmp_edr_2m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_2M)
18085075b972SJaganath Kanakkassery #define lmp_edr_3m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_3M)
18095075b972SJaganath Kanakkassery #define lmp_edr_3slot_capable(dev) ((dev)->features[0][4] & LMP_EDR_3SLOT)
18105075b972SJaganath Kanakkassery #define lmp_edr_5slot_capable(dev) ((dev)->features[0][5] & LMP_EDR_5SLOT)
18111da177e4SLinus Torvalds 
1812eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
18136397729bSArchie Pusaka #define lmp_cpb_central_capable(dev) ((dev)->features[2][0] & LMP_CPB_CENTRAL)
18146397729bSArchie Pusaka #define lmp_cpb_peripheral_capable(dev) ((dev)->features[2][0] & LMP_CPB_PERIPHERAL)
181553b834d2SMarcel Holtmann #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN)
181653b834d2SMarcel Holtmann #define lmp_sync_scan_capable(dev)  ((dev)->features[2][0] & LMP_SYNC_SCAN)
1817d5991585SMarcel Holtmann #define lmp_sc_capable(dev)         ((dev)->features[2][1] & LMP_SC)
1818d5991585SMarcel Holtmann #define lmp_ping_capable(dev)       ((dev)->features[2][1] & LMP_PING)
181953b834d2SMarcel Holtmann 
182053b834d2SMarcel Holtmann /* ----- Host capabilities ----- */
1821cad718edSJohan Hedberg #define lmp_host_ssp_capable(dev)  ((dev)->features[1][0] & LMP_HOST_SSP)
1822d5991585SMarcel Holtmann #define lmp_host_sc_capable(dev)   ((dev)->features[1][0] & LMP_HOST_SC)
1823cad718edSJohan Hedberg #define lmp_host_le_capable(dev)   (!!((dev)->features[1][0] & LMP_HOST_LE))
1824cad718edSJohan Hedberg #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
1825eead27daSAndre Guedes 
1826d7a5a11dSMarcel Holtmann #define hdev_is_powered(dev)   (test_bit(HCI_UP, &(dev)->flags) && \
1827d7a5a11dSMarcel Holtmann 				!hci_dev_test_flag(dev, HCI_AUTO_OFF))
182805b3c3e7SMarcel Holtmann #define bredr_sc_enabled(dev)  (lmp_sc_capable(dev) && \
1829d7a5a11dSMarcel Holtmann 				hci_dev_test_flag(dev, HCI_SC_ENABLED))
1830c45074d6SLuiz Augusto von Dentz #define rpa_valid(dev)         (bacmp(&dev->rpa, BDADDR_ANY) && \
1831c45074d6SLuiz Augusto von Dentz 				!hci_dev_test_flag(dev, HCI_RPA_EXPIRED))
1832c45074d6SLuiz Augusto von Dentz #define adv_rpa_valid(adv)     (bacmp(&adv->random_addr, BDADDR_ANY) && \
1833c45074d6SLuiz Augusto von Dentz 				!adv->rpa_expired)
1834432df05eSJohan Hedberg 
183545bdd86eSJaganath Kanakkassery #define scan_1m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_1M) || \
183645bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_1M))
183745bdd86eSJaganath Kanakkassery 
1838288c9022SLuiz Augusto von Dentz #define le_2m_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_2M))
1839288c9022SLuiz Augusto von Dentz 
184045bdd86eSJaganath Kanakkassery #define scan_2m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_2M) || \
184145bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_2M))
184245bdd86eSJaganath Kanakkassery 
1843253f3399SLuiz Augusto von Dentz #define le_coded_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_CODED) && \
1844253f3399SLuiz Augusto von Dentz 			       !test_bit(HCI_QUIRK_BROKEN_LE_CODED, \
1845253f3399SLuiz Augusto von Dentz 					 &(dev)->quirks))
1846288c9022SLuiz Augusto von Dentz 
184745bdd86eSJaganath Kanakkassery #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
184845bdd86eSJaganath Kanakkassery 			 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
184945bdd86eSJaganath Kanakkassery 
1850ad383c2cSLuiz Augusto von Dentz #define ll_privacy_capable(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1851ad383c2cSLuiz Augusto von Dentz 
1852e1d57235SMarcel Holtmann /* Use LL Privacy based address resolution if supported */
1853ad383c2cSLuiz Augusto von Dentz #define use_ll_privacy(dev) (ll_privacy_capable(dev) && \
1854ad383c2cSLuiz Augusto von Dentz 			     hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY))
1855e1d57235SMarcel Holtmann 
18566126ffabSLuiz Augusto von Dentz #define privacy_mode_capable(dev) (use_ll_privacy(dev) && \
18576126ffabSLuiz Augusto von Dentz 				   (hdev->commands[39] & 0x04))
18586126ffabSLuiz Augusto von Dentz 
185905abad85SLuiz Augusto von Dentz /* Use enhanced synchronous connection if command is supported and its quirk
186005abad85SLuiz Augusto von Dentz  * has not been set.
186105abad85SLuiz Augusto von Dentz  */
186205abad85SLuiz Augusto von Dentz #define enhanced_sync_conn_capable(dev) \
186305abad85SLuiz Augusto von Dentz 	(((dev)->commands[29] & 0x08) && \
186405abad85SLuiz Augusto von Dentz 	 !test_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &(dev)->quirks))
1865b2af264aSKiran K 
1866a2344b9eSJaganath Kanakkassery /* Use ext scanning if set ext scan param and ext scan enable is supported */
1867a2344b9eSJaganath Kanakkassery #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
1868392fca35SSven Peter 			   ((dev)->commands[37] & 0x40) && \
1869392fca35SSven Peter 			   !test_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &(dev)->quirks))
1870392fca35SSven Peter 
18714d94f95dSJaganath Kanakkassery /* Use ext create connection if command is supported */
18724d94f95dSJaganath Kanakkassery #define use_ext_conn(dev) ((dev)->commands[37] & 0x80)
1873a2344b9eSJaganath Kanakkassery 
18746b49bcb4SJaganath Kanakkassery /* Extended advertising support */
18756b49bcb4SJaganath Kanakkassery #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
18766b49bcb4SJaganath Kanakkassery 
1877112b5090SLuiz Augusto von Dentz /* Maximum advertising length */
1878112b5090SLuiz Augusto von Dentz #define max_adv_len(dev) \
1879112b5090SLuiz Augusto von Dentz 	(ext_adv_capable(dev) ? HCI_MAX_EXT_AD_LENGTH : HCI_MAX_AD_LENGTH)
1880112b5090SLuiz Augusto von Dentz 
1881a56a1138SLuiz Augusto von Dentz /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1789:
1882a56a1138SLuiz Augusto von Dentz  *
1883a56a1138SLuiz Augusto von Dentz  * C24: Mandatory if the LE Controller supports Connection State and either
1884a56a1138SLuiz Augusto von Dentz  * LE Feature (LL Privacy) or LE Feature (Extended Advertising) is supported
1885a56a1138SLuiz Augusto von Dentz  */
1886a56a1138SLuiz Augusto von Dentz #define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \
1887a56a1138SLuiz Augusto von Dentz 					 ext_adv_capable(dev))
1888a56a1138SLuiz Augusto von Dentz 
1889eca0ae4aSLuiz Augusto von Dentz /* Periodic advertising support */
1890eca0ae4aSLuiz Augusto von Dentz #define per_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_PERIODIC_ADV))
1891eca0ae4aSLuiz Augusto von Dentz 
1892eca0ae4aSLuiz Augusto von Dentz /* CIS Master/Slave and BIS support */
1893eca0ae4aSLuiz Augusto von Dentz #define iso_capable(dev) (cis_capable(dev) || bis_capable(dev))
189426afbd82SLuiz Augusto von Dentz #define cis_capable(dev) \
189526afbd82SLuiz Augusto von Dentz 	(cis_central_capable(dev) || cis_peripheral_capable(dev))
189626afbd82SLuiz Augusto von Dentz #define cis_central_capable(dev) \
189726afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_CENTRAL)
189826afbd82SLuiz Augusto von Dentz #define cis_peripheral_capable(dev) \
189926afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_PERIPHERAL)
1900eca0ae4aSLuiz Augusto von Dentz #define bis_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_BROADCASTER)
1901ae753361SClaudia Draghicescu #define sync_recv_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_SYNC_RECEIVER)
190226afbd82SLuiz Augusto von Dentz 
1903ffcb0a44SSven Peter #define mws_transport_config_capable(dev) (((dev)->commands[30] & 0x08) && \
1904ffcb0a44SSven Peter 	(!test_bit(HCI_QUIRK_BROKEN_MWS_TRANSPORT_CONFIG, &(dev)->quirks)))
1905ffcb0a44SSven Peter 
19061da177e4SLinus Torvalds /* ----- HCI protocols ----- */
190720714bfeSFrédéric Dalleau #define HCI_PROTO_DEFER             0x01
190820714bfeSFrédéric Dalleau 
19095a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
191020714bfeSFrédéric Dalleau 					__u8 type, __u8 *flags)
19111da177e4SLinus Torvalds {
1912686ebf28SUlisses Furquim 	switch (type) {
1913686ebf28SUlisses Furquim 	case ACL_LINK:
1914686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
19151da177e4SLinus Torvalds 
1916686ebf28SUlisses Furquim 	case SCO_LINK:
1917686ebf28SUlisses Furquim 	case ESCO_LINK:
191820714bfeSFrédéric Dalleau 		return sco_connect_ind(hdev, bdaddr, flags);
19191da177e4SLinus Torvalds 
192026afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
1921ccf74f23SLuiz Augusto von Dentz 		return iso_connect_ind(hdev, bdaddr, flags);
192226afbd82SLuiz Augusto von Dentz 
1923686ebf28SUlisses Furquim 	default:
1924686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
1925686ebf28SUlisses Furquim 		return -EINVAL;
1926686ebf28SUlisses Furquim 	}
19271da177e4SLinus Torvalds }
19281da177e4SLinus Torvalds 
19292950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
19302950f21aSMarcel Holtmann {
1931686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
1932686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
19332950f21aSMarcel Holtmann 
1934686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
19352950f21aSMarcel Holtmann }
19362950f21aSMarcel Holtmann 
19371da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
19381da177e4SLinus Torvalds struct hci_cb {
19391da177e4SLinus Torvalds 	struct list_head list;
19401da177e4SLinus Torvalds 
19411da177e4SLinus Torvalds 	char *name;
19421da177e4SLinus Torvalds 
1943539c496dSJohan Hedberg 	void (*connect_cfm)	(struct hci_conn *conn, __u8 status);
19443a6d576bSJohan Hedberg 	void (*disconn_cfm)	(struct hci_conn *conn, __u8 status);
19455a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
19465a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
19471da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
19481da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
19491da177e4SLinus Torvalds };
19501da177e4SLinus Torvalds 
1951539c496dSJohan Hedberg static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status)
1952539c496dSJohan Hedberg {
1953539c496dSJohan Hedberg 	struct hci_cb *cb;
1954539c496dSJohan Hedberg 
1955539c496dSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
1956539c496dSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
1957539c496dSJohan Hedberg 		if (cb->connect_cfm)
1958539c496dSJohan Hedberg 			cb->connect_cfm(conn, status);
1959539c496dSJohan Hedberg 	}
1960539c496dSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
1961539c496dSJohan Hedberg 
1962539c496dSJohan Hedberg 	if (conn->connect_cfm_cb)
1963539c496dSJohan Hedberg 		conn->connect_cfm_cb(conn, status);
1964539c496dSJohan Hedberg }
1965539c496dSJohan Hedberg 
19663a6d576bSJohan Hedberg static inline void hci_disconn_cfm(struct hci_conn *conn, __u8 reason)
19673a6d576bSJohan Hedberg {
19683a6d576bSJohan Hedberg 	struct hci_cb *cb;
19693a6d576bSJohan Hedberg 
19703a6d576bSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
19713a6d576bSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
19723a6d576bSJohan Hedberg 		if (cb->disconn_cfm)
19733a6d576bSJohan Hedberg 			cb->disconn_cfm(conn, reason);
19743a6d576bSJohan Hedberg 	}
19753a6d576bSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
19763a6d576bSJohan Hedberg 
19773a6d576bSJohan Hedberg 	if (conn->disconn_cfm_cb)
19783a6d576bSJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
19793a6d576bSJohan Hedberg }
19803a6d576bSJohan Hedberg 
19811da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
19821da177e4SLinus Torvalds {
1983711584eaSDenis Kirjanov 	struct hci_cb *cb;
19848c1b2355SMarcel Holtmann 	__u8 encrypt;
19851da177e4SLinus Torvalds 
198651a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
19878c1b2355SMarcel Holtmann 		return;
19888c1b2355SMarcel Holtmann 
19894dae2798SJohan Hedberg 	encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
19908c1b2355SMarcel Holtmann 
1991fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
1992711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
19938c1b2355SMarcel Holtmann 		if (cb->security_cfm)
19948c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
19951da177e4SLinus Torvalds 	}
1996fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
1997354fe804SJohan Hedberg 
1998354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
1999354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
20001da177e4SLinus Torvalds }
20011da177e4SLinus Torvalds 
20023ca44c16SLuiz Augusto von Dentz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)
20031da177e4SLinus Torvalds {
2004711584eaSDenis Kirjanov 	struct hci_cb *cb;
20053ca44c16SLuiz Augusto von Dentz 	__u8 encrypt;
20063ca44c16SLuiz Augusto von Dentz 
20073ca44c16SLuiz Augusto von Dentz 	if (conn->state == BT_CONFIG) {
2008339ddaa6SPatrick Steinhardt 		if (!status)
20093ca44c16SLuiz Augusto von Dentz 			conn->state = BT_CONNECTED;
20103ca44c16SLuiz Augusto von Dentz 
20113ca44c16SLuiz Augusto von Dentz 		hci_connect_cfm(conn, status);
20123ca44c16SLuiz Augusto von Dentz 		hci_conn_drop(conn);
20133ca44c16SLuiz Augusto von Dentz 		return;
20143ca44c16SLuiz Augusto von Dentz 	}
20153ca44c16SLuiz Augusto von Dentz 
20163ca44c16SLuiz Augusto von Dentz 	if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
20173ca44c16SLuiz Augusto von Dentz 		encrypt = 0x00;
20183ca44c16SLuiz Augusto von Dentz 	else if (test_bit(HCI_CONN_AES_CCM, &conn->flags))
20193ca44c16SLuiz Augusto von Dentz 		encrypt = 0x02;
20203ca44c16SLuiz Augusto von Dentz 	else
20213ca44c16SLuiz Augusto von Dentz 		encrypt = 0x01;
20221da177e4SLinus Torvalds 
20238746f135SLuiz Augusto von Dentz 	if (!status) {
2024435fef20SMarcel Holtmann 		if (conn->sec_level == BT_SECURITY_SDP)
2025435fef20SMarcel Holtmann 			conn->sec_level = BT_SECURITY_LOW;
2026435fef20SMarcel Holtmann 
202788167aedSVinicius Costa Gomes 		if (conn->pending_sec_level > conn->sec_level)
202888167aedSVinicius Costa Gomes 			conn->sec_level = conn->pending_sec_level;
20298746f135SLuiz Augusto von Dentz 	}
203088167aedSVinicius Costa Gomes 
2031fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2032711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20338c1b2355SMarcel Holtmann 		if (cb->security_cfm)
20348c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
20351da177e4SLinus Torvalds 	}
2036fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
2037354fe804SJohan Hedberg 
2038354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
2039354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
20401da177e4SLinus Torvalds }
20411da177e4SLinus Torvalds 
20421da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
20431da177e4SLinus Torvalds {
2044711584eaSDenis Kirjanov 	struct hci_cb *cb;
20451da177e4SLinus Torvalds 
2046fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2047711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20481da177e4SLinus Torvalds 		if (cb->key_change_cfm)
20491da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
20501da177e4SLinus Torvalds 	}
2051fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20521da177e4SLinus Torvalds }
20531da177e4SLinus Torvalds 
20545a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
20555a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
20561da177e4SLinus Torvalds {
2057711584eaSDenis Kirjanov 	struct hci_cb *cb;
20581da177e4SLinus Torvalds 
2059fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2060711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20611da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
20621da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
20631da177e4SLinus Torvalds 	}
2064fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20651da177e4SLinus Torvalds }
20661da177e4SLinus Torvalds 
2067301cb2d8SJohan Hedberg static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
2068301cb2d8SJohan Hedberg {
2069dbbfa2abSAndre Guedes 	if (addr_type != ADDR_LE_DEV_RANDOM)
2070301cb2d8SJohan Hedberg 		return false;
2071301cb2d8SJohan Hedberg 
2072301cb2d8SJohan Hedberg 	if ((bdaddr->b[5] & 0xc0) == 0x40)
2073301cb2d8SJohan Hedberg 	       return true;
2074301cb2d8SJohan Hedberg 
2075301cb2d8SJohan Hedberg 	return false;
2076301cb2d8SJohan Hedberg }
2077301cb2d8SJohan Hedberg 
2078c46245b3SJohan Hedberg static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type)
2079c46245b3SJohan Hedberg {
2080c46245b3SJohan Hedberg 	if (addr_type == ADDR_LE_DEV_PUBLIC)
2081c46245b3SJohan Hedberg 		return true;
2082c46245b3SJohan Hedberg 
2083c46245b3SJohan Hedberg 	/* Check for Random Static address type */
2084c46245b3SJohan Hedberg 	if ((addr->b[5] & 0xc0) == 0xc0)
2085c46245b3SJohan Hedberg 		return true;
2086c46245b3SJohan Hedberg 
2087c46245b3SJohan Hedberg 	return false;
2088c46245b3SJohan Hedberg }
2089c46245b3SJohan Hedberg 
20902426f3a5SJohan Hedberg static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
20912426f3a5SJohan Hedberg 					  bdaddr_t *bdaddr, u8 addr_type)
20922426f3a5SJohan Hedberg {
20932426f3a5SJohan Hedberg 	if (!hci_bdaddr_is_rpa(bdaddr, addr_type))
20942426f3a5SJohan Hedberg 		return NULL;
20952426f3a5SJohan Hedberg 
20962426f3a5SJohan Hedberg 	return hci_find_irk_by_rpa(hdev, bdaddr);
20972426f3a5SJohan Hedberg }
20982426f3a5SJohan Hedberg 
2099d4905f24SAndre Guedes static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
2100d4905f24SAndre Guedes 					u16 to_multiplier)
2101d4905f24SAndre Guedes {
2102d4905f24SAndre Guedes 	u16 max_latency;
2103d4905f24SAndre Guedes 
2104d4905f24SAndre Guedes 	if (min > max || min < 6 || max > 3200)
2105d4905f24SAndre Guedes 		return -EINVAL;
2106d4905f24SAndre Guedes 
2107d4905f24SAndre Guedes 	if (to_multiplier < 10 || to_multiplier > 3200)
2108d4905f24SAndre Guedes 		return -EINVAL;
2109d4905f24SAndre Guedes 
2110d4905f24SAndre Guedes 	if (max >= to_multiplier * 8)
2111d4905f24SAndre Guedes 		return -EINVAL;
2112d4905f24SAndre Guedes 
21138757825bSSeungyoun Ju 	max_latency = (to_multiplier * 4 / max) - 1;
2114d4905f24SAndre Guedes 	if (latency > 499 || latency > max_latency)
2115d4905f24SAndre Guedes 		return -EINVAL;
2116d4905f24SAndre Guedes 
2117d4905f24SAndre Guedes 	return 0;
2118d4905f24SAndre Guedes }
2119d4905f24SAndre Guedes 
21201da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
21211da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
21221da177e4SLinus Torvalds 
2123d6ee6ad7SLoic Poulain int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen,
2124d6ee6ad7SLoic Poulain 		   const void *param);
212575e84b7cSJohan Hedberg 
212607dc93ddSJohan Hedberg int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
212707dc93ddSJohan Hedberg 		 const void *param);
212873d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
21290d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
213026afbd82SLuiz Augusto von Dentz void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb);
21311da177e4SLinus Torvalds 
2132a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
2133dfe6d5c3SLuiz Augusto von Dentz void *hci_recv_event_data(struct hci_dev *hdev, __u8 event);
21341da177e4SLinus Torvalds 
2135eab2404bSLuiz Augusto von Dentz u32 hci_conn_get_phy(struct hci_conn *conn);
2136eab2404bSLuiz Augusto von Dentz 
21371da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
2138470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
21397129069eSJohan Hedberg void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
2140c08b1a1dSMarcel Holtmann 			 int flag, struct sock *skip_sk);
2141cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
214238ceaa00SMarcel Holtmann void hci_send_monitor_ctrl_event(struct hci_dev *hdev, u16 event,
214338ceaa00SMarcel Holtmann 				 void *data, u16 data_len, ktime_t tstamp,
214438ceaa00SMarcel Holtmann 				 int flag, struct sock *skip_sk);
21451da177e4SLinus Torvalds 
2146040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event);
2147040030efSMarcel Holtmann 
2148a958452aSMarcel Holtmann #define HCI_MGMT_VAR_LEN	BIT(0)
2149a958452aSMarcel Holtmann #define HCI_MGMT_NO_HDEV	BIT(1)
2150a958452aSMarcel Holtmann #define HCI_MGMT_UNTRUSTED	BIT(2)
2151a958452aSMarcel Holtmann #define HCI_MGMT_UNCONFIGURED	BIT(3)
2152d5cc6626SMarcel Holtmann #define HCI_MGMT_HDEV_OPTIONAL	BIT(4)
2153b9a245fbSJohan Hedberg 
2154801c1e8dSJohan Hedberg struct hci_mgmt_handler {
2155801c1e8dSJohan Hedberg 	int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
2156801c1e8dSJohan Hedberg 		     u16 data_len);
2157801c1e8dSJohan Hedberg 	size_t data_len;
2158b9a245fbSJohan Hedberg 	unsigned long flags;
2159801c1e8dSJohan Hedberg };
2160801c1e8dSJohan Hedberg 
2161801c1e8dSJohan Hedberg struct hci_mgmt_chan {
2162801c1e8dSJohan Hedberg 	struct list_head list;
2163801c1e8dSJohan Hedberg 	unsigned short channel;
2164801c1e8dSJohan Hedberg 	size_t handler_count;
2165801c1e8dSJohan Hedberg 	const struct hci_mgmt_handler *handlers;
216688b94ce9SJohan Hedberg 	void (*hdev_init) (struct sock *sk, struct hci_dev *hdev);
2167801c1e8dSJohan Hedberg };
2168801c1e8dSJohan Hedberg 
2169801c1e8dSJohan Hedberg int hci_mgmt_chan_register(struct hci_mgmt_chan *c);
2170801c1e8dSJohan Hedberg void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c);
2171801c1e8dSJohan Hedberg 
21720381101fSJohan Hedberg /* Management interface */
2173591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR		(BIT(BDADDR_BREDR))
2174591f47f3SAndre Guedes #define DISCOV_TYPE_LE			(BIT(BDADDR_LE_PUBLIC) | \
2175591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2176591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED		(BIT(BDADDR_BREDR) | \
2177591f47f3SAndre Guedes 					 BIT(BDADDR_LE_PUBLIC) | \
2178591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2179f39799f5SAndre Guedes 
21800d8cc935SAndre Guedes /* These LE scan and inquiry parameters were chosen according to LE General
21810d8cc935SAndre Guedes  * Discovery Procedure specification.
21820d8cc935SAndre Guedes  */
21830d8cc935SAndre Guedes #define DISCOV_LE_SCAN_WIN		0x12
21840d8cc935SAndre Guedes #define DISCOV_LE_SCAN_INT		0x12
21853d5a76f0SLukasz Rymanowski #define DISCOV_LE_TIMEOUT		10240	/* msec */
2186ae55f598SLukasz Rymanowski #define DISCOV_INTERLEAVED_TIMEOUT	5120	/* msec */
21870d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_INQUIRY_LEN	0x04
21880d8cc935SAndre Guedes #define DISCOV_BREDR_INQUIRY_LEN	0x08
21894b0e0cedSJakub Pawlowski #define DISCOV_LE_RESTART_DELAY		msecs_to_jiffies(200)	/* msec */
2190cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MIN	0x00A0	/* 100 msec */
2191cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MAX	0x00F0	/* 150 msec */
2192eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MIN	0x00A0	/* 200 msec */
2193eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MAX	0x00A0	/* 200 msec */
2194b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MIN		0x00A0  /* 100 msec */
2195b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MAX		0x00A0  /* 100 msec */
2196b338d917SBrian Gix #define INTERVAL_TO_MS(x)		(((x) * 10) / 0x10)
21970d8cc935SAndre Guedes 
2198dbf6811aSArchie Pusaka #define NAME_RESOLVE_DURATION		msecs_to_jiffies(10240)	/* 10.24 sec */
2199dbf6811aSArchie Pusaka 
220003c979c4SMarcel Holtmann void mgmt_fill_version_info(void *ver);
220191a668b0SJohan Hedberg int mgmt_new_settings(struct hci_dev *hdev);
2202bf6b56dbSMarcel Holtmann void mgmt_index_added(struct hci_dev *hdev);
2203bf6b56dbSMarcel Holtmann void mgmt_index_removed(struct hci_dev *hdev);
22043eec705eSMarcel Holtmann void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
22052ff13894SJohan Hedberg void mgmt_power_on(struct hci_dev *hdev, int err);
22062ff13894SJohan Hedberg void __mgmt_power_off(struct hci_dev *hdev);
2207dc4a5ee2SMarcel Holtmann void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
2208745c0ce3SVishal Agarwal 		       bool persistent);
220948ec92faSAlfonso Acosta void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
22101c6ed31bSYu Liu 			   u8 *name, u8 name_len);
22119b80ec5eSMarcel Holtmann void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
221212d4a3b2SJohan Hedberg 			      u8 link_type, u8 addr_type, u8 reason,
221312d4a3b2SJohan Hedberg 			      bool mgmt_connected);
22147892924cSMarcel Holtmann void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
221588c3df13SJohan Hedberg 			    u8 link_type, u8 addr_type, u8 status);
2216445608d0SMarcel Holtmann void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
221748264f06SJohan Hedberg 			 u8 addr_type, u8 status);
2218ce0e4a0dSMarcel Holtmann void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
2219e669cf80SMarcel Holtmann void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2220c35938b2SSzymon Janc 				  u8 status);
22213eb38528SMarcel Holtmann void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2222744cf19eSJohan Hedberg 				      u8 status);
2223744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
222439adbffeSJohan Hedberg 			      u8 link_type, u8 addr_type, u32 value,
2225272d90dfSJohan Hedberg 			      u8 confirm_hint);
2226744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2227272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2228272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2229272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
2230272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
2231272d90dfSJohan Hedberg 			      u8 link_type, u8 addr_type);
2232604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2233272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2234272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2235272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
223692a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
223792a25256SJohan Hedberg 			     u8 link_type, u8 addr_type, u32 passkey,
223892a25256SJohan Hedberg 			     u8 entered);
2239e1e930f5SJohan Hedberg void mgmt_auth_failed(struct hci_conn *conn, u8 status);
2240464996aeSMarcel Holtmann void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
22414e1b0245SMarcel Holtmann void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
22427f9a903cSMarcel Holtmann 				    u8 status);
22437667da34SMarcel Holtmann void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
2244e68f072bSJohan Hedberg void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status);
22452154d3f4SJohan Hedberg void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status);
2246901801b9SMarcel Holtmann void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2247af58925cSMarcel Holtmann 		       u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
2248b338d917SBrian Gix 		       u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len,
2249b338d917SBrian Gix 		       u64 instant);
22509cf12aeeSMarcel Holtmann void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2251b644ba33SJohan Hedberg 		      u8 addr_type, s8 rssi, u8 *name, u8 name_len);
22522f1e063bSMarcel Holtmann void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
2253346ce5b7SAbhishek Pandit-Subedi void mgmt_suspending(struct hci_dev *hdev, u8 state);
2254346ce5b7SAbhishek Pandit-Subedi void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr,
2255346ce5b7SAbhishek Pandit-Subedi 		   u8 addr_type);
225684c61d92SJohan Hedberg bool mgmt_powering_down(struct hci_dev *hdev);
225753ac6ab6SMarcel Holtmann void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
2258cad20c27SJohan Hedberg void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent);
225953ac6ab6SMarcel Holtmann void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
226053ac6ab6SMarcel Holtmann 		   bool persistent);
2261ffb5a827SAndre Guedes void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
2262f4869e2aSJohan Hedberg 			 u8 bdaddr_type, u8 store_hint, u16 min_interval,
2263f4869e2aSJohan Hedberg 			 u16 max_interval, u16 latency, u16 timeout);
2264f4a407beSJohan Hedberg void mgmt_smp_complete(struct hci_conn *conn, bool complete);
2265f2252570SJohan Hedberg bool mgmt_get_connectable(struct hci_dev *hdev);
2266f2252570SJohan Hedberg u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev);
2267f2252570SJohan Hedberg void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,
2268f2252570SJohan Hedberg 			    u8 instance);
2269f2252570SJohan Hedberg void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev,
2270f2252570SJohan Hedberg 			      u8 instance);
227166bd095aSArchie Pusaka void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle);
2272b7c23df8SJaganath Kanakkassery int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip);
22738d7f1677SManish Mandlik void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle,
22748d7f1677SManish Mandlik 				  bdaddr_t *bdaddr, u8 addr_type);
2275346af67bSVinicius Costa Gomes 
22761a942de0SBrian Gix int hci_abort_conn(struct hci_conn *conn, u8 reason);
22777d6ca693SJohan Hedberg u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
22787d6ca693SJohan Hedberg 		      u16 to_multiplier);
2279fe39c7b2SMarcel Holtmann void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
22808b76ce34SJohan Hedberg 		      __u8 ltk[16], __u8 key_size);
22812519a1fcSAndre Guedes 
2282a1f4c318SJohan Hedberg void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
2283a1f4c318SJohan Hedberg 			       u8 *bdaddr_type);
2284ebd3a747SJohan Hedberg 
22855d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_MASK       0x0003
22865d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_CVSD       0x0000
22875d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_TRANSP     0x0003
22885d4d62f6SFrédéric Dalleau 
22898961987fSKiran K #define LOCAL_CODEC_ACL_MASK	BIT(0)
22908961987fSKiran K #define LOCAL_CODEC_SCO_MASK	BIT(1)
22918961987fSKiran K 
22928961987fSKiran K #define TRANSPORT_TYPE_MAX	0x04
22938961987fSKiran K 
22941da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
2295