xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision dcda1657)
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 
353*dcda1657SLuiz 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 *
1317fbdc4bc4SIulia Tanasescu hci_conn_hash_lookup_pa_sync(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 
13394c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
13404c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
13414c67bc74SMarcel Holtmann {
13424c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
13434c67bc74SMarcel Holtmann 	struct hci_conn  *c;
13444c67bc74SMarcel Holtmann 
1345bf4c6325SGustavo F. Padovan 	rcu_read_lock();
1346bf4c6325SGustavo F. Padovan 
1347bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
1348bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
1349bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
13504c67bc74SMarcel Holtmann 			return c;
13514c67bc74SMarcel Holtmann 		}
1352bf4c6325SGustavo F. Padovan 	}
1353bf4c6325SGustavo F. Padovan 
1354bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
1355bf4c6325SGustavo F. Padovan 
13564c67bc74SMarcel Holtmann 	return NULL;
13574c67bc74SMarcel Holtmann }
13584c67bc74SMarcel Holtmann 
135926afbd82SLuiz Augusto von Dentz typedef void (*hci_conn_func_t)(struct hci_conn *conn, void *data);
136026afbd82SLuiz Augusto von Dentz static inline void hci_conn_hash_list_state(struct hci_dev *hdev,
136126afbd82SLuiz Augusto von Dentz 					    hci_conn_func_t func, __u8 type,
136226afbd82SLuiz Augusto von Dentz 					    __u16 state, void *data)
136326afbd82SLuiz Augusto von Dentz {
136426afbd82SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
136526afbd82SLuiz Augusto von Dentz 	struct hci_conn  *c;
136626afbd82SLuiz Augusto von Dentz 
136726afbd82SLuiz Augusto von Dentz 	if (!func)
136826afbd82SLuiz Augusto von Dentz 		return;
136926afbd82SLuiz Augusto von Dentz 
137026afbd82SLuiz Augusto von Dentz 	rcu_read_lock();
137126afbd82SLuiz Augusto von Dentz 
137226afbd82SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
137326afbd82SLuiz Augusto von Dentz 		if (c->type == type && c->state == state)
137426afbd82SLuiz Augusto von Dentz 			func(c, data);
137526afbd82SLuiz Augusto von Dentz 	}
137626afbd82SLuiz Augusto von Dentz 
137726afbd82SLuiz Augusto von Dentz 	rcu_read_unlock();
137826afbd82SLuiz Augusto von Dentz }
137926afbd82SLuiz Augusto von Dentz 
1380e7d9ab73SJakub Pawlowski static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev)
1381e7d9ab73SJakub Pawlowski {
1382e7d9ab73SJakub Pawlowski 	struct hci_conn_hash *h = &hdev->conn_hash;
1383e7d9ab73SJakub Pawlowski 	struct hci_conn  *c;
1384e7d9ab73SJakub Pawlowski 
1385e7d9ab73SJakub Pawlowski 	rcu_read_lock();
1386e7d9ab73SJakub Pawlowski 
1387e7d9ab73SJakub Pawlowski 	list_for_each_entry_rcu(c, &h->list, list) {
1388e7d9ab73SJakub Pawlowski 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1389e7d9ab73SJakub Pawlowski 		    !test_bit(HCI_CONN_SCANNING, &c->flags)) {
1390e7d9ab73SJakub Pawlowski 			rcu_read_unlock();
1391e7d9ab73SJakub Pawlowski 			return c;
1392e7d9ab73SJakub Pawlowski 		}
1393e7d9ab73SJakub Pawlowski 	}
1394e7d9ab73SJakub Pawlowski 
1395e7d9ab73SJakub Pawlowski 	rcu_read_unlock();
1396e7d9ab73SJakub Pawlowski 
1397e7d9ab73SJakub Pawlowski 	return NULL;
1398e7d9ab73SJakub Pawlowski }
1399e7d9ab73SJakub Pawlowski 
1400f8867016SLuiz Augusto von Dentz /* Returns true if an le connection is in the scanning state */
1401f8867016SLuiz Augusto von Dentz static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev)
1402f8867016SLuiz Augusto von Dentz {
1403f8867016SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
1404f8867016SLuiz Augusto von Dentz 	struct hci_conn  *c;
1405f8867016SLuiz Augusto von Dentz 
1406f8867016SLuiz Augusto von Dentz 	rcu_read_lock();
1407f8867016SLuiz Augusto von Dentz 
1408f8867016SLuiz Augusto von Dentz 	list_for_each_entry_rcu(c, &h->list, list) {
1409f8867016SLuiz Augusto von Dentz 		if (c->type == LE_LINK && c->state == BT_CONNECT &&
1410f8867016SLuiz Augusto von Dentz 		    test_bit(HCI_CONN_SCANNING, &c->flags)) {
1411f8867016SLuiz Augusto von Dentz 			rcu_read_unlock();
1412f8867016SLuiz Augusto von Dentz 			return true;
1413f8867016SLuiz Augusto von Dentz 		}
1414f8867016SLuiz Augusto von Dentz 	}
1415f8867016SLuiz Augusto von Dentz 
1416f8867016SLuiz Augusto von Dentz 	rcu_read_unlock();
1417f8867016SLuiz Augusto von Dentz 
1418f8867016SLuiz Augusto von Dentz 	return false;
1419f8867016SLuiz Augusto von Dentz }
1420f8867016SLuiz Augusto von Dentz 
1421e3b679d5SJohan Hedberg int hci_disconnect(struct hci_conn *conn, __u8 reason);
14222dea632fSFrédéric Dalleau bool hci_setup_sync(struct hci_conn *conn, __u16 handle);
1423e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
142426afbd82SLuiz Augusto von Dentz bool hci_iso_setup_path(struct hci_conn *conn);
14257f74563eSPauli Virtanen int hci_le_create_cis_pending(struct hci_dev *hdev);
14267f74563eSPauli Virtanen int hci_conn_check_create_cis(struct hci_conn *conn);
14271da177e4SLinus Torvalds 
1428a5c4e309SJohan Hedberg struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst,
1429a5c4e309SJohan Hedberg 			      u8 role);
1430a2ac591cSRuihan Li void hci_conn_del(struct hci_conn *conn);
14311da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
1432a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
14331da177e4SLinus Torvalds 
143473d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
14359472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan);
14362c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
143742c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
143873d80debSLuiz Augusto von Dentz 
1439f75113a2SJakub Pawlowski struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,
1440f75113a2SJakub Pawlowski 				     u8 dst_type, u8 sec_level,
144176b13996SManish Mandlik 				     u16 conn_timeout,
144276b13996SManish Mandlik 				     enum conn_reasons conn_reason);
144304a6c589SAndre Guedes struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
1444d850bf08SLuiz Augusto von Dentz 				u8 dst_type, bool dst_resolved, u8 sec_level,
14458e8b92eeSLuiz Augusto von Dentz 				u16 conn_timeout, u8 role);
144604a6c589SAndre Guedes struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
144776b13996SManish Mandlik 				 u8 sec_level, u8 auth_type,
144876b13996SManish Mandlik 				 enum conn_reasons conn_reason);
144910c62ddcSFrédéric Dalleau struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
1450b2af264aSKiran K 				 __u16 setting, struct bt_codec *codec);
145126afbd82SLuiz Augusto von Dentz struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
145226afbd82SLuiz Augusto von Dentz 			      __u8 dst_type, struct bt_iso_qos *qos);
1453a0bfde16SIulia Tanasescu struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,
1454a0bfde16SIulia Tanasescu 			      struct bt_iso_qos *qos,
1455a0bfde16SIulia Tanasescu 			      __u8 base_len, __u8 *base);
145626afbd82SLuiz Augusto von Dentz struct hci_conn *hci_connect_cis(struct hci_dev *hdev, bdaddr_t *dst,
145726afbd82SLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos);
1458eca0ae4aSLuiz Augusto von Dentz struct hci_conn *hci_connect_bis(struct hci_dev *hdev, bdaddr_t *dst,
1459eca0ae4aSLuiz Augusto von Dentz 				 __u8 dst_type, struct bt_iso_qos *qos,
1460eca0ae4aSLuiz Augusto von Dentz 				 __u8 data_len, __u8 *data);
1461eca0ae4aSLuiz Augusto von Dentz int hci_pa_create_sync(struct hci_dev *hdev, bdaddr_t *dst, __u8 dst_type,
14620fe8c8d0SIulia Tanasescu 		       __u8 sid, struct bt_iso_qos *qos);
1463fbdc4bc4SIulia Tanasescu int hci_le_big_create_sync(struct hci_dev *hdev, struct hci_conn *hcon,
1464fbdc4bc4SIulia Tanasescu 			   struct bt_iso_qos *qos,
1465eca0ae4aSLuiz Augusto von Dentz 			   __u16 sync_handle, __u8 num_bis, __u8 bis[]);
1466e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
1467b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
1468e7cafc45SJohan Hedberg int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type,
1469e7cafc45SJohan Hedberg 		      bool initiator);
14708c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
14711da177e4SLinus Torvalds 
147214b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
14731da177e4SLinus Torvalds 
14749b3628d7SLuiz Augusto von Dentz void hci_conn_failed(struct hci_conn *conn, u8 status);
147516e3b642SLuiz Augusto von Dentz u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle);
147606c053fbSAndre Guedes 
14778d12356fSDavid Herrmann /*
14788d12356fSDavid Herrmann  * hci_conn_get() and hci_conn_put() are used to control the life-time of an
14798d12356fSDavid Herrmann  * "hci_conn" object. They do not guarantee that the hci_conn object is running,
14808d12356fSDavid Herrmann  * working or anything else. They just guarantee that the object is available
14818d12356fSDavid Herrmann  * and can be dereferenced. So you can use its locks, local variables and any
14828d12356fSDavid Herrmann  * other constant data.
14838d12356fSDavid Herrmann  * Before accessing runtime data, you _must_ lock the object and then check that
14848d12356fSDavid Herrmann  * it is still running. As soon as you release the locks, the connection might
14858d12356fSDavid Herrmann  * get dropped, though.
14868d12356fSDavid Herrmann  *
14878d12356fSDavid Herrmann  * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control
14888d12356fSDavid Herrmann  * how long the underlying connection is held. So every channel that runs on the
14898d12356fSDavid Herrmann  * hci_conn object calls this to prevent the connection from disappearing. As
14908d12356fSDavid Herrmann  * long as you hold a device, you must also guarantee that you have a valid
14918d12356fSDavid Herrmann  * reference to the device via hci_conn_get() (or the initial reference from
14928d12356fSDavid Herrmann  * hci_conn_add()).
14938d12356fSDavid Herrmann  * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't
14948d12356fSDavid Herrmann  * break because nobody cares for that. But this means, we cannot use
14958d12356fSDavid Herrmann  * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
14968d12356fSDavid Herrmann  */
14978d12356fSDavid Herrmann 
149851bb8457SJohan Hedberg static inline struct hci_conn *hci_conn_get(struct hci_conn *conn)
14998d12356fSDavid Herrmann {
15008d12356fSDavid Herrmann 	get_device(&conn->dev);
150151bb8457SJohan Hedberg 	return conn;
15028d12356fSDavid Herrmann }
15038d12356fSDavid Herrmann 
15048d12356fSDavid Herrmann static inline void hci_conn_put(struct hci_conn *conn)
15058d12356fSDavid Herrmann {
15068d12356fSDavid Herrmann 	put_device(&conn->dev);
15078d12356fSDavid Herrmann }
15088d12356fSDavid Herrmann 
150906149746SLuiz Augusto von Dentz static inline struct hci_conn *hci_conn_hold(struct hci_conn *conn)
15101da177e4SLinus Torvalds {
151171becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
151238b3fef1SAndrei Emeltchenko 
15131da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
15142f304d1eSAndre Guedes 	cancel_delayed_work(&conn->disc_work);
151506149746SLuiz Augusto von Dentz 
151606149746SLuiz Augusto von Dentz 	return conn;
15171da177e4SLinus Torvalds }
15181da177e4SLinus Torvalds 
151976a68ba0SDavid Herrmann static inline void hci_conn_drop(struct hci_conn *conn)
15201da177e4SLinus Torvalds {
152171becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
152238b3fef1SAndrei Emeltchenko 
15231da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
152404837f64SMarcel Holtmann 		unsigned long timeo;
1525716e4ab5SAndrei Emeltchenko 
1526716e4ab5SAndrei Emeltchenko 		switch (conn->type) {
1527716e4ab5SAndrei Emeltchenko 		case ACL_LINK:
1528716e4ab5SAndrei Emeltchenko 		case LE_LINK:
1529a74a84f6SJohan Hedberg 			cancel_delayed_work(&conn->idle_work);
15306ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
15315f246e89SAndrei Emeltchenko 				timeo = conn->disc_timeout;
153204837f64SMarcel Holtmann 				if (!conn->out)
1533052b30b0SMarcel Holtmann 					timeo *= 2;
15345a9d0a3fSWaldemar Rymarkiewicz 			} else {
1535eb78d7e5SJohan Hedberg 				timeo = 0;
15365a9d0a3fSWaldemar Rymarkiewicz 			}
1537716e4ab5SAndrei Emeltchenko 			break;
1538716e4ab5SAndrei Emeltchenko 
1539716e4ab5SAndrei Emeltchenko 		case AMP_LINK:
1540716e4ab5SAndrei Emeltchenko 			timeo = conn->disc_timeout;
1541716e4ab5SAndrei Emeltchenko 			break;
1542716e4ab5SAndrei Emeltchenko 
1543716e4ab5SAndrei Emeltchenko 		default:
1544eb78d7e5SJohan Hedberg 			timeo = 0;
1545716e4ab5SAndrei Emeltchenko 			break;
15465a9d0a3fSWaldemar Rymarkiewicz 		}
1547716e4ab5SAndrei Emeltchenko 
15482f304d1eSAndre Guedes 		cancel_delayed_work(&conn->disc_work);
154919c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
15501931782bSVinicius Costa Gomes 				   &conn->disc_work, timeo);
15511da177e4SLinus Torvalds 	}
15521da177e4SLinus Torvalds }
15531da177e4SLinus Torvalds 
15541da177e4SLinus Torvalds /* ----- HCI Devices ----- */
1555dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
15561da177e4SLinus Torvalds {
1557376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15582c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1559376261aeSAndrei Emeltchenko 
15604c724c71SDavid Herrmann 	put_device(&d->dev);
1561010666a1SDavid Herrmann }
15621da177e4SLinus Torvalds 
1563dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
15641da177e4SLinus Torvalds {
1565376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
15662c935bc5SPeter Zijlstra 	       kref_read(&d->dev.kobj.kref));
1567376261aeSAndrei Emeltchenko 
15684c724c71SDavid Herrmann 	get_device(&d->dev);
15691da177e4SLinus Torvalds 	return d;
15701da177e4SLinus Torvalds }
15711da177e4SLinus Torvalds 
157209fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
157309fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
15741da177e4SLinus Torvalds 
1575aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev)
15763dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev)
1577aa2b86d7SDavid Herrmann 
1578155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev)
1579155961e8SDavid Herrmann {
1580155961e8SDavid Herrmann 	return dev_get_drvdata(&hdev->dev);
1581155961e8SDavid Herrmann }
1582155961e8SDavid Herrmann 
1583155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
1584155961e8SDavid Herrmann {
1585155961e8SDavid Herrmann 	dev_set_drvdata(&hdev->dev, data);
1586155961e8SDavid Herrmann }
1587155961e8SDavid Herrmann 
15886ec56613STedd Ho-Jeong An static inline void *hci_get_priv(struct hci_dev *hdev)
15896ec56613STedd Ho-Jeong An {
15906ec56613STedd Ho-Jeong An 	return (char *)hdev + sizeof(*hdev);
15916ec56613STedd Ho-Jeong An }
15926ec56613STedd Ho-Jeong An 
15931da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
159439385cb5SJohan Hedberg struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type);
15951da177e4SLinus Torvalds 
15966ec56613STedd Ho-Jeong An struct hci_dev *hci_alloc_dev_priv(int sizeof_priv);
15976ec56613STedd Ho-Jeong An 
15986ec56613STedd Ho-Jeong An static inline struct hci_dev *hci_alloc_dev(void)
15996ec56613STedd Ho-Jeong An {
16006ec56613STedd Ho-Jeong An 	return hci_alloc_dev_priv(0);
16016ec56613STedd Ho-Jeong An }
16026ec56613STedd Ho-Jeong An 
16031da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
16041da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
160559735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
160658ce6d5bSTetsuo Handa void hci_release_dev(struct hci_dev *hdev);
1607359ee4f8SAbhishek Pandit-Subedi int hci_register_suspend_notifier(struct hci_dev *hdev);
1608359ee4f8SAbhishek Pandit-Subedi int hci_unregister_suspend_notifier(struct hci_dev *hdev);
16091da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
16101da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
161175e0569fSMarcel Holtmann int hci_reset_dev(struct hci_dev *hdev);
1612f962fe32SMarcel Holtmann int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
1613f962fe32SMarcel Holtmann int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
16141aabbbceSNicolas Iooss __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
16151aabbbceSNicolas Iooss __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
1616145373cbSMiao-chen Chou 
1617145373cbSMiao-chen Chou static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
1618145373cbSMiao-chen Chou {
1619145373cbSMiao-chen Chou #if IS_ENABLED(CONFIG_BT_MSFTEXT)
1620145373cbSMiao-chen Chou 	hdev->msft_opcode = opcode;
1621145373cbSMiao-chen Chou #endif
1622145373cbSMiao-chen Chou }
1623145373cbSMiao-chen Chou 
1624f67743f9SMarcel Holtmann static inline void hci_set_aosp_capable(struct hci_dev *hdev)
1625f67743f9SMarcel Holtmann {
1626f67743f9SMarcel Holtmann #if IS_ENABLED(CONFIG_BT_AOSPEXT)
1627f67743f9SMarcel Holtmann 	hdev->aosp_capable = true;
1628f67743f9SMarcel Holtmann #endif
1629f67743f9SMarcel Holtmann }
1630f67743f9SMarcel Holtmann 
16319695ef87SAbhishek Pandit-Subedi static inline void hci_devcd_setup(struct hci_dev *hdev)
16329695ef87SAbhishek Pandit-Subedi {
16339695ef87SAbhishek Pandit-Subedi #ifdef CONFIG_DEV_COREDUMP
16349695ef87SAbhishek Pandit-Subedi 	INIT_WORK(&hdev->dump.dump_rx, hci_devcd_rx);
16359695ef87SAbhishek Pandit-Subedi 	INIT_DELAYED_WORK(&hdev->dump.dump_timeout, hci_devcd_timeout);
16369695ef87SAbhishek Pandit-Subedi 	skb_queue_head_init(&hdev->dump.dump_q);
16379695ef87SAbhishek Pandit-Subedi #endif
16389695ef87SAbhishek Pandit-Subedi }
16399695ef87SAbhishek Pandit-Subedi 
16401da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
16411da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
16426b3cc1dbSSimon Fels int hci_dev_do_close(struct hci_dev *hdev);
16431da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
16441da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
16451da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
16461da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
16471da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
16481da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
16491da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
165040be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
16511da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
16521da177e4SLinus Torvalds 
1653dcc36c16SJohan Hedberg struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list,
1654b9ee0a78SMarcel Holtmann 					   bdaddr_t *bdaddr, u8 type);
1655b950aa88SAnkit Navik struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk(
1656b950aa88SAnkit Navik 				    struct list_head *list, bdaddr_t *bdaddr,
1657b950aa88SAnkit Navik 				    u8 type);
16588baaa403SAbhishek Pandit-Subedi struct bdaddr_list_with_flags *
16598baaa403SAbhishek Pandit-Subedi hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16608baaa403SAbhishek Pandit-Subedi 				  u8 type);
1661dcc36c16SJohan Hedberg int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1662b950aa88SAnkit Navik int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1663b950aa88SAnkit Navik 				 u8 type, u8 *peer_irk, u8 *local_irk);
16648baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16658baaa403SAbhishek Pandit-Subedi 				   u8 type, u32 flags);
1666dcc36c16SJohan Hedberg int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type);
1667b950aa88SAnkit Navik int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr,
1668b950aa88SAnkit Navik 				 u8 type);
16698baaa403SAbhishek Pandit-Subedi int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr,
16708baaa403SAbhishek Pandit-Subedi 				   u8 type);
1671dcc36c16SJohan Hedberg void hci_bdaddr_list_clear(struct list_head *list);
1672d2ab0ac1SMarcel Holtmann 
167315819a70SAndre Guedes struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
167415819a70SAndre Guedes 					       bdaddr_t *addr, u8 addr_type);
167551d167c0SMarcel Holtmann struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
167651d167c0SMarcel Holtmann 					    bdaddr_t *addr, u8 addr_type);
167715819a70SAndre Guedes void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
167855af49a8SJohan Hedberg void hci_conn_params_clear_disabled(struct hci_dev *hdev);
1679195ef75eSPauli Virtanen void hci_conn_params_free(struct hci_conn_params *param);
168015819a70SAndre Guedes 
1681195ef75eSPauli Virtanen void hci_pend_le_list_del_init(struct hci_conn_params *param);
1682195ef75eSPauli Virtanen void hci_pend_le_list_add(struct hci_conn_params *param,
1683195ef75eSPauli Virtanen 			  struct list_head *list);
1684501f8827SJohan Hedberg struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list,
1685501f8827SJohan Hedberg 						  bdaddr_t *addr,
1686501f8827SJohan Hedberg 						  u8 addr_type);
168777a77a30SAndre Guedes 
168835f7498aSJohan Hedberg void hci_uuids_clear(struct hci_dev *hdev);
16892aeb9a1aSJohan Hedberg 
169035f7498aSJohan Hedberg void hci_link_keys_clear(struct hci_dev *hdev);
169155ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
1692567fa2aaSJohan Hedberg struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
16937652ff6aSJohan Hedberg 				  bdaddr_t *bdaddr, u8 *val, u8 type,
16947652ff6aSJohan Hedberg 				  u8 pin_len, bool *persistent);
1695ca9142b8SJohan Hedberg struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
169635d70271SJohan Hedberg 			    u8 addr_type, u8 type, u8 authenticated,
1697fe39c7b2SMarcel Holtmann 			    u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
1698f3a73d97SJohan Hedberg struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1699e804d25dSJohan Hedberg 			     u8 addr_type, u8 role);
1700e0b2b27eSJohan Hedberg int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
170135f7498aSJohan Hedberg void hci_smp_ltks_clear(struct hci_dev *hdev);
170255ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
170355ed8ca1SJohan Hedberg 
1704970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa);
1705970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1706970c4e46SJohan Hedberg 				     u8 addr_type);
1707ca9142b8SJohan Hedberg struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1708ca9142b8SJohan Hedberg 			    u8 addr_type, u8 val[16], bdaddr_t *rpa);
1709a7ec7338SJohan Hedberg void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
1710600a8749SAlain Michaud bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]);
1711600a8749SAlain Michaud void hci_blocked_keys_clear(struct hci_dev *hdev);
1712970c4e46SJohan Hedberg void hci_smp_irks_clear(struct hci_dev *hdev);
1713970c4e46SJohan Hedberg 
171455e76b38SJohan Hedberg bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
171555e76b38SJohan Hedberg 
171635f7498aSJohan Hedberg void hci_remote_oob_data_clear(struct hci_dev *hdev);
17172763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
17186928a924SJohan Hedberg 					  bdaddr_t *bdaddr, u8 bdaddr_type);
17190798872eSMarcel Holtmann int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17206928a924SJohan Hedberg 			    u8 bdaddr_type, u8 *hash192, u8 *rand192,
172138da1703SJohan Hedberg 			    u8 *hash256, u8 *rand256);
17226928a924SJohan Hedberg int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
17236928a924SJohan Hedberg 			       u8 bdaddr_type);
17242763eda6SSzymon Janc 
1725d2609b34SFlorian Grandel void hci_adv_instances_clear(struct hci_dev *hdev);
1726d2609b34SFlorian Grandel struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance);
1727d2609b34SFlorian Grandel struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance);
1728eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,
1729eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u16 adv_data_len, u8 *adv_data,
1730d2609b34SFlorian Grandel 				      u16 scan_rsp_len, u8 *scan_rsp_data,
17319bf9f4b6SDaniel Winkler 				      u16 timeout, u16 duration, s8 tx_power,
1732b338d917SBrian Gix 				      u32 min_interval, u32 max_interval,
1733b338d917SBrian Gix 				      u8 mesh_handle);
1734eca0ae4aSLuiz Augusto von Dentz struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance,
1735eca0ae4aSLuiz Augusto von Dentz 				      u32 flags, u8 data_len, u8 *data,
1736eca0ae4aSLuiz Augusto von Dentz 				      u32 min_interval, u32 max_interval);
173731aab5c2SDaniel Winkler int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
173831aab5c2SDaniel Winkler 			 u16 adv_data_len, u8 *adv_data,
173931aab5c2SDaniel Winkler 			 u16 scan_rsp_len, u8 *scan_rsp_data);
1740d2609b34SFlorian Grandel int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance);
1741a73c046aSJaganath Kanakkassery void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired);
174201ce70b0SLuiz Augusto von Dentz u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance);
174301ce70b0SLuiz Augusto von Dentz bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance);
1744d2609b34SFlorian Grandel 
1745e5e1e7fdSMiao-chen Chou void hci_adv_monitors_clear(struct hci_dev *hdev);
174666bd095aSArchie Pusaka void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
1747b747a836SManish Mandlik int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor);
17487cf5c297SManish Mandlik int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle);
17497cf5c297SManish Mandlik int hci_remove_all_adv_monitor(struct hci_dev *hdev);
17508208f5a9SMiao-chen Chou bool hci_is_adv_monitoring(struct hci_dev *hdev);
1751a2a4dedfSArchie Pusaka int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev);
1752e5e1e7fdSMiao-chen Chou 
17531da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
17541da177e4SLinus Torvalds 
17550ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
1756a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
1757b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
1758b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
17591da177e4SLinus Torvalds 
17606935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
1761294d749bSKiran K #define GET_HCIDEV_DEV(hdev) ((hdev)->dev.parent)
17621da177e4SLinus Torvalds 
17631da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
1764cad718edSJohan Hedberg #define lmp_encrypt_capable(dev)   ((dev)->features[0][0] & LMP_ENCRYPT)
1765cad718edSJohan Hedberg #define lmp_rswitch_capable(dev)   ((dev)->features[0][0] & LMP_RSWITCH)
1766cad718edSJohan Hedberg #define lmp_hold_capable(dev)      ((dev)->features[0][0] & LMP_HOLD)
1767cad718edSJohan Hedberg #define lmp_sniff_capable(dev)     ((dev)->features[0][0] & LMP_SNIFF)
1768cad718edSJohan Hedberg #define lmp_park_capable(dev)      ((dev)->features[0][1] & LMP_PARK)
1769cad718edSJohan Hedberg #define lmp_inq_rssi_capable(dev)  ((dev)->features[0][3] & LMP_RSSI_INQ)
1770cad718edSJohan Hedberg #define lmp_esco_capable(dev)      ((dev)->features[0][3] & LMP_ESCO)
1771cad718edSJohan Hedberg #define lmp_bredr_capable(dev)     (!((dev)->features[0][4] & LMP_NO_BREDR))
1772cad718edSJohan Hedberg #define lmp_le_capable(dev)        ((dev)->features[0][4] & LMP_LE)
1773cad718edSJohan Hedberg #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR)
1774cad718edSJohan Hedberg #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC)
17758b1c324cSYu Liu #define lmp_esco_2m_capable(dev)   ((dev)->features[0][5] & LMP_EDR_ESCO_2M)
1776cad718edSJohan Hedberg #define lmp_ext_inq_capable(dev)   ((dev)->features[0][6] & LMP_EXT_INQ)
1777cad718edSJohan Hedberg #define lmp_le_br_capable(dev)     (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR))
1778cad718edSJohan Hedberg #define lmp_ssp_capable(dev)       ((dev)->features[0][6] & LMP_SIMPLE_PAIR)
1779cad718edSJohan Hedberg #define lmp_no_flush_capable(dev)  ((dev)->features[0][6] & LMP_NO_FLUSH)
1780cad718edSJohan Hedberg #define lmp_lsto_capable(dev)      ((dev)->features[0][7] & LMP_LSTO)
1781cad718edSJohan Hedberg #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
1782cad718edSJohan Hedberg #define lmp_ext_feat_capable(dev)  ((dev)->features[0][7] & LMP_EXTFEATURES)
178307a5c61eSFrédéric Dalleau #define lmp_transp_capable(dev)    ((dev)->features[0][2] & LMP_TRANSPARENT)
17845075b972SJaganath Kanakkassery #define lmp_edr_2m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_2M)
17855075b972SJaganath Kanakkassery #define lmp_edr_3m_capable(dev)    ((dev)->features[0][3] & LMP_EDR_3M)
17865075b972SJaganath Kanakkassery #define lmp_edr_3slot_capable(dev) ((dev)->features[0][4] & LMP_EDR_3SLOT)
17875075b972SJaganath Kanakkassery #define lmp_edr_5slot_capable(dev) ((dev)->features[0][5] & LMP_EDR_5SLOT)
17881da177e4SLinus Torvalds 
1789eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
17906397729bSArchie Pusaka #define lmp_cpb_central_capable(dev) ((dev)->features[2][0] & LMP_CPB_CENTRAL)
17916397729bSArchie Pusaka #define lmp_cpb_peripheral_capable(dev) ((dev)->features[2][0] & LMP_CPB_PERIPHERAL)
179253b834d2SMarcel Holtmann #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN)
179353b834d2SMarcel Holtmann #define lmp_sync_scan_capable(dev)  ((dev)->features[2][0] & LMP_SYNC_SCAN)
1794d5991585SMarcel Holtmann #define lmp_sc_capable(dev)         ((dev)->features[2][1] & LMP_SC)
1795d5991585SMarcel Holtmann #define lmp_ping_capable(dev)       ((dev)->features[2][1] & LMP_PING)
179653b834d2SMarcel Holtmann 
179753b834d2SMarcel Holtmann /* ----- Host capabilities ----- */
1798cad718edSJohan Hedberg #define lmp_host_ssp_capable(dev)  ((dev)->features[1][0] & LMP_HOST_SSP)
1799d5991585SMarcel Holtmann #define lmp_host_sc_capable(dev)   ((dev)->features[1][0] & LMP_HOST_SC)
1800cad718edSJohan Hedberg #define lmp_host_le_capable(dev)   (!!((dev)->features[1][0] & LMP_HOST_LE))
1801cad718edSJohan Hedberg #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
1802eead27daSAndre Guedes 
1803d7a5a11dSMarcel Holtmann #define hdev_is_powered(dev)   (test_bit(HCI_UP, &(dev)->flags) && \
1804d7a5a11dSMarcel Holtmann 				!hci_dev_test_flag(dev, HCI_AUTO_OFF))
180505b3c3e7SMarcel Holtmann #define bredr_sc_enabled(dev)  (lmp_sc_capable(dev) && \
1806d7a5a11dSMarcel Holtmann 				hci_dev_test_flag(dev, HCI_SC_ENABLED))
1807c45074d6SLuiz Augusto von Dentz #define rpa_valid(dev)         (bacmp(&dev->rpa, BDADDR_ANY) && \
1808c45074d6SLuiz Augusto von Dentz 				!hci_dev_test_flag(dev, HCI_RPA_EXPIRED))
1809c45074d6SLuiz Augusto von Dentz #define adv_rpa_valid(adv)     (bacmp(&adv->random_addr, BDADDR_ANY) && \
1810c45074d6SLuiz Augusto von Dentz 				!adv->rpa_expired)
1811432df05eSJohan Hedberg 
181245bdd86eSJaganath Kanakkassery #define scan_1m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_1M) || \
181345bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_1M))
181445bdd86eSJaganath Kanakkassery 
1815288c9022SLuiz Augusto von Dentz #define le_2m_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_2M))
1816288c9022SLuiz Augusto von Dentz 
181745bdd86eSJaganath Kanakkassery #define scan_2m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_2M) || \
181845bdd86eSJaganath Kanakkassery 		      ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_2M))
181945bdd86eSJaganath Kanakkassery 
1820253f3399SLuiz Augusto von Dentz #define le_coded_capable(dev) (((dev)->le_features[1] & HCI_LE_PHY_CODED) && \
1821253f3399SLuiz Augusto von Dentz 			       !test_bit(HCI_QUIRK_BROKEN_LE_CODED, \
1822253f3399SLuiz Augusto von Dentz 					 &(dev)->quirks))
1823288c9022SLuiz Augusto von Dentz 
182445bdd86eSJaganath Kanakkassery #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \
182545bdd86eSJaganath Kanakkassery 			 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED))
182645bdd86eSJaganath Kanakkassery 
1827ad383c2cSLuiz Augusto von Dentz #define ll_privacy_capable(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY)
1828ad383c2cSLuiz Augusto von Dentz 
1829e1d57235SMarcel Holtmann /* Use LL Privacy based address resolution if supported */
1830ad383c2cSLuiz Augusto von Dentz #define use_ll_privacy(dev) (ll_privacy_capable(dev) && \
1831ad383c2cSLuiz Augusto von Dentz 			     hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY))
1832e1d57235SMarcel Holtmann 
18336126ffabSLuiz Augusto von Dentz #define privacy_mode_capable(dev) (use_ll_privacy(dev) && \
18346126ffabSLuiz Augusto von Dentz 				   (hdev->commands[39] & 0x04))
18356126ffabSLuiz Augusto von Dentz 
183605abad85SLuiz Augusto von Dentz /* Use enhanced synchronous connection if command is supported and its quirk
183705abad85SLuiz Augusto von Dentz  * has not been set.
183805abad85SLuiz Augusto von Dentz  */
183905abad85SLuiz Augusto von Dentz #define enhanced_sync_conn_capable(dev) \
184005abad85SLuiz Augusto von Dentz 	(((dev)->commands[29] & 0x08) && \
184105abad85SLuiz Augusto von Dentz 	 !test_bit(HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN, &(dev)->quirks))
1842b2af264aSKiran K 
1843a2344b9eSJaganath Kanakkassery /* Use ext scanning if set ext scan param and ext scan enable is supported */
1844a2344b9eSJaganath Kanakkassery #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \
1845392fca35SSven Peter 			   ((dev)->commands[37] & 0x40) && \
1846392fca35SSven Peter 			   !test_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &(dev)->quirks))
1847392fca35SSven Peter 
18484d94f95dSJaganath Kanakkassery /* Use ext create connection if command is supported */
18494d94f95dSJaganath Kanakkassery #define use_ext_conn(dev) ((dev)->commands[37] & 0x80)
1850a2344b9eSJaganath Kanakkassery 
18516b49bcb4SJaganath Kanakkassery /* Extended advertising support */
18526b49bcb4SJaganath Kanakkassery #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV))
18536b49bcb4SJaganath Kanakkassery 
1854112b5090SLuiz Augusto von Dentz /* Maximum advertising length */
1855112b5090SLuiz Augusto von Dentz #define max_adv_len(dev) \
1856112b5090SLuiz Augusto von Dentz 	(ext_adv_capable(dev) ? HCI_MAX_EXT_AD_LENGTH : HCI_MAX_AD_LENGTH)
1857112b5090SLuiz Augusto von Dentz 
1858a56a1138SLuiz Augusto von Dentz /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1789:
1859a56a1138SLuiz Augusto von Dentz  *
1860a56a1138SLuiz Augusto von Dentz  * C24: Mandatory if the LE Controller supports Connection State and either
1861a56a1138SLuiz Augusto von Dentz  * LE Feature (LL Privacy) or LE Feature (Extended Advertising) is supported
1862a56a1138SLuiz Augusto von Dentz  */
1863a56a1138SLuiz Augusto von Dentz #define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \
1864a56a1138SLuiz Augusto von Dentz 					 ext_adv_capable(dev))
1865a56a1138SLuiz Augusto von Dentz 
1866eca0ae4aSLuiz Augusto von Dentz /* Periodic advertising support */
1867eca0ae4aSLuiz Augusto von Dentz #define per_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_PERIODIC_ADV))
1868eca0ae4aSLuiz Augusto von Dentz 
1869eca0ae4aSLuiz Augusto von Dentz /* CIS Master/Slave and BIS support */
1870eca0ae4aSLuiz Augusto von Dentz #define iso_capable(dev) (cis_capable(dev) || bis_capable(dev))
187126afbd82SLuiz Augusto von Dentz #define cis_capable(dev) \
187226afbd82SLuiz Augusto von Dentz 	(cis_central_capable(dev) || cis_peripheral_capable(dev))
187326afbd82SLuiz Augusto von Dentz #define cis_central_capable(dev) \
187426afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_CENTRAL)
187526afbd82SLuiz Augusto von Dentz #define cis_peripheral_capable(dev) \
187626afbd82SLuiz Augusto von Dentz 	((dev)->le_features[3] & HCI_LE_CIS_PERIPHERAL)
1877eca0ae4aSLuiz Augusto von Dentz #define bis_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_BROADCASTER)
1878ae753361SClaudia Draghicescu #define sync_recv_capable(dev) ((dev)->le_features[3] & HCI_LE_ISO_SYNC_RECEIVER)
187926afbd82SLuiz Augusto von Dentz 
1880ffcb0a44SSven Peter #define mws_transport_config_capable(dev) (((dev)->commands[30] & 0x08) && \
1881ffcb0a44SSven Peter 	(!test_bit(HCI_QUIRK_BROKEN_MWS_TRANSPORT_CONFIG, &(dev)->quirks)))
1882ffcb0a44SSven Peter 
18831da177e4SLinus Torvalds /* ----- HCI protocols ----- */
188420714bfeSFrédéric Dalleau #define HCI_PROTO_DEFER             0x01
188520714bfeSFrédéric Dalleau 
18865a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
188720714bfeSFrédéric Dalleau 					__u8 type, __u8 *flags)
18881da177e4SLinus Torvalds {
1889686ebf28SUlisses Furquim 	switch (type) {
1890686ebf28SUlisses Furquim 	case ACL_LINK:
1891686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
18921da177e4SLinus Torvalds 
1893686ebf28SUlisses Furquim 	case SCO_LINK:
1894686ebf28SUlisses Furquim 	case ESCO_LINK:
189520714bfeSFrédéric Dalleau 		return sco_connect_ind(hdev, bdaddr, flags);
18961da177e4SLinus Torvalds 
189726afbd82SLuiz Augusto von Dentz 	case ISO_LINK:
1898ccf74f23SLuiz Augusto von Dentz 		return iso_connect_ind(hdev, bdaddr, flags);
189926afbd82SLuiz Augusto von Dentz 
1900686ebf28SUlisses Furquim 	default:
1901686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
1902686ebf28SUlisses Furquim 		return -EINVAL;
1903686ebf28SUlisses Furquim 	}
19041da177e4SLinus Torvalds }
19051da177e4SLinus Torvalds 
19062950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
19072950f21aSMarcel Holtmann {
1908686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
1909686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
19102950f21aSMarcel Holtmann 
1911686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
19122950f21aSMarcel Holtmann }
19132950f21aSMarcel Holtmann 
19141da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
19151da177e4SLinus Torvalds struct hci_cb {
19161da177e4SLinus Torvalds 	struct list_head list;
19171da177e4SLinus Torvalds 
19181da177e4SLinus Torvalds 	char *name;
19191da177e4SLinus Torvalds 
1920539c496dSJohan Hedberg 	void (*connect_cfm)	(struct hci_conn *conn, __u8 status);
19213a6d576bSJohan Hedberg 	void (*disconn_cfm)	(struct hci_conn *conn, __u8 status);
19225a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
19235a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
19241da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
19251da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
19261da177e4SLinus Torvalds };
19271da177e4SLinus Torvalds 
1928539c496dSJohan Hedberg static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status)
1929539c496dSJohan Hedberg {
1930539c496dSJohan Hedberg 	struct hci_cb *cb;
1931539c496dSJohan Hedberg 
1932539c496dSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
1933539c496dSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
1934539c496dSJohan Hedberg 		if (cb->connect_cfm)
1935539c496dSJohan Hedberg 			cb->connect_cfm(conn, status);
1936539c496dSJohan Hedberg 	}
1937539c496dSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
1938539c496dSJohan Hedberg 
1939539c496dSJohan Hedberg 	if (conn->connect_cfm_cb)
1940539c496dSJohan Hedberg 		conn->connect_cfm_cb(conn, status);
1941539c496dSJohan Hedberg }
1942539c496dSJohan Hedberg 
19433a6d576bSJohan Hedberg static inline void hci_disconn_cfm(struct hci_conn *conn, __u8 reason)
19443a6d576bSJohan Hedberg {
19453a6d576bSJohan Hedberg 	struct hci_cb *cb;
19463a6d576bSJohan Hedberg 
19473a6d576bSJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
19483a6d576bSJohan Hedberg 	list_for_each_entry(cb, &hci_cb_list, list) {
19493a6d576bSJohan Hedberg 		if (cb->disconn_cfm)
19503a6d576bSJohan Hedberg 			cb->disconn_cfm(conn, reason);
19513a6d576bSJohan Hedberg 	}
19523a6d576bSJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
19533a6d576bSJohan Hedberg 
19543a6d576bSJohan Hedberg 	if (conn->disconn_cfm_cb)
19553a6d576bSJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
19563a6d576bSJohan Hedberg }
19573a6d576bSJohan Hedberg 
19581da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
19591da177e4SLinus Torvalds {
1960711584eaSDenis Kirjanov 	struct hci_cb *cb;
19618c1b2355SMarcel Holtmann 	__u8 encrypt;
19621da177e4SLinus Torvalds 
196351a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
19648c1b2355SMarcel Holtmann 		return;
19658c1b2355SMarcel Holtmann 
19664dae2798SJohan Hedberg 	encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00;
19678c1b2355SMarcel Holtmann 
1968fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
1969711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
19708c1b2355SMarcel Holtmann 		if (cb->security_cfm)
19718c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
19721da177e4SLinus Torvalds 	}
1973fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
1974354fe804SJohan Hedberg 
1975354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
1976354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
19771da177e4SLinus Torvalds }
19781da177e4SLinus Torvalds 
19793ca44c16SLuiz Augusto von Dentz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status)
19801da177e4SLinus Torvalds {
1981711584eaSDenis Kirjanov 	struct hci_cb *cb;
19823ca44c16SLuiz Augusto von Dentz 	__u8 encrypt;
19833ca44c16SLuiz Augusto von Dentz 
19843ca44c16SLuiz Augusto von Dentz 	if (conn->state == BT_CONFIG) {
1985339ddaa6SPatrick Steinhardt 		if (!status)
19863ca44c16SLuiz Augusto von Dentz 			conn->state = BT_CONNECTED;
19873ca44c16SLuiz Augusto von Dentz 
19883ca44c16SLuiz Augusto von Dentz 		hci_connect_cfm(conn, status);
19893ca44c16SLuiz Augusto von Dentz 		hci_conn_drop(conn);
19903ca44c16SLuiz Augusto von Dentz 		return;
19913ca44c16SLuiz Augusto von Dentz 	}
19923ca44c16SLuiz Augusto von Dentz 
19933ca44c16SLuiz Augusto von Dentz 	if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags))
19943ca44c16SLuiz Augusto von Dentz 		encrypt = 0x00;
19953ca44c16SLuiz Augusto von Dentz 	else if (test_bit(HCI_CONN_AES_CCM, &conn->flags))
19963ca44c16SLuiz Augusto von Dentz 		encrypt = 0x02;
19973ca44c16SLuiz Augusto von Dentz 	else
19983ca44c16SLuiz Augusto von Dentz 		encrypt = 0x01;
19991da177e4SLinus Torvalds 
20008746f135SLuiz Augusto von Dentz 	if (!status) {
2001435fef20SMarcel Holtmann 		if (conn->sec_level == BT_SECURITY_SDP)
2002435fef20SMarcel Holtmann 			conn->sec_level = BT_SECURITY_LOW;
2003435fef20SMarcel Holtmann 
200488167aedSVinicius Costa Gomes 		if (conn->pending_sec_level > conn->sec_level)
200588167aedSVinicius Costa Gomes 			conn->sec_level = conn->pending_sec_level;
20068746f135SLuiz Augusto von Dentz 	}
200788167aedSVinicius Costa Gomes 
2008fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2009711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20108c1b2355SMarcel Holtmann 		if (cb->security_cfm)
20118c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
20121da177e4SLinus Torvalds 	}
2013fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
2014354fe804SJohan Hedberg 
2015354fe804SJohan Hedberg 	if (conn->security_cfm_cb)
2016354fe804SJohan Hedberg 		conn->security_cfm_cb(conn, status);
20171da177e4SLinus Torvalds }
20181da177e4SLinus Torvalds 
20191da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
20201da177e4SLinus Torvalds {
2021711584eaSDenis Kirjanov 	struct hci_cb *cb;
20221da177e4SLinus Torvalds 
2023fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2024711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20251da177e4SLinus Torvalds 		if (cb->key_change_cfm)
20261da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
20271da177e4SLinus Torvalds 	}
2028fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20291da177e4SLinus Torvalds }
20301da177e4SLinus Torvalds 
20315a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
20325a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
20331da177e4SLinus Torvalds {
2034711584eaSDenis Kirjanov 	struct hci_cb *cb;
20351da177e4SLinus Torvalds 
2036fba7ecf0SJohan Hedberg 	mutex_lock(&hci_cb_list_lock);
2037711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
20381da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
20391da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
20401da177e4SLinus Torvalds 	}
2041fba7ecf0SJohan Hedberg 	mutex_unlock(&hci_cb_list_lock);
20421da177e4SLinus Torvalds }
20431da177e4SLinus Torvalds 
2044301cb2d8SJohan Hedberg static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
2045301cb2d8SJohan Hedberg {
2046dbbfa2abSAndre Guedes 	if (addr_type != ADDR_LE_DEV_RANDOM)
2047301cb2d8SJohan Hedberg 		return false;
2048301cb2d8SJohan Hedberg 
2049301cb2d8SJohan Hedberg 	if ((bdaddr->b[5] & 0xc0) == 0x40)
2050301cb2d8SJohan Hedberg 	       return true;
2051301cb2d8SJohan Hedberg 
2052301cb2d8SJohan Hedberg 	return false;
2053301cb2d8SJohan Hedberg }
2054301cb2d8SJohan Hedberg 
2055c46245b3SJohan Hedberg static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type)
2056c46245b3SJohan Hedberg {
2057c46245b3SJohan Hedberg 	if (addr_type == ADDR_LE_DEV_PUBLIC)
2058c46245b3SJohan Hedberg 		return true;
2059c46245b3SJohan Hedberg 
2060c46245b3SJohan Hedberg 	/* Check for Random Static address type */
2061c46245b3SJohan Hedberg 	if ((addr->b[5] & 0xc0) == 0xc0)
2062c46245b3SJohan Hedberg 		return true;
2063c46245b3SJohan Hedberg 
2064c46245b3SJohan Hedberg 	return false;
2065c46245b3SJohan Hedberg }
2066c46245b3SJohan Hedberg 
20672426f3a5SJohan Hedberg static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
20682426f3a5SJohan Hedberg 					  bdaddr_t *bdaddr, u8 addr_type)
20692426f3a5SJohan Hedberg {
20702426f3a5SJohan Hedberg 	if (!hci_bdaddr_is_rpa(bdaddr, addr_type))
20712426f3a5SJohan Hedberg 		return NULL;
20722426f3a5SJohan Hedberg 
20732426f3a5SJohan Hedberg 	return hci_find_irk_by_rpa(hdev, bdaddr);
20742426f3a5SJohan Hedberg }
20752426f3a5SJohan Hedberg 
2076d4905f24SAndre Guedes static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
2077d4905f24SAndre Guedes 					u16 to_multiplier)
2078d4905f24SAndre Guedes {
2079d4905f24SAndre Guedes 	u16 max_latency;
2080d4905f24SAndre Guedes 
2081d4905f24SAndre Guedes 	if (min > max || min < 6 || max > 3200)
2082d4905f24SAndre Guedes 		return -EINVAL;
2083d4905f24SAndre Guedes 
2084d4905f24SAndre Guedes 	if (to_multiplier < 10 || to_multiplier > 3200)
2085d4905f24SAndre Guedes 		return -EINVAL;
2086d4905f24SAndre Guedes 
2087d4905f24SAndre Guedes 	if (max >= to_multiplier * 8)
2088d4905f24SAndre Guedes 		return -EINVAL;
2089d4905f24SAndre Guedes 
20908757825bSSeungyoun Ju 	max_latency = (to_multiplier * 4 / max) - 1;
2091d4905f24SAndre Guedes 	if (latency > 499 || latency > max_latency)
2092d4905f24SAndre Guedes 		return -EINVAL;
2093d4905f24SAndre Guedes 
2094d4905f24SAndre Guedes 	return 0;
2095d4905f24SAndre Guedes }
2096d4905f24SAndre Guedes 
20971da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
20981da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
20991da177e4SLinus Torvalds 
2100d6ee6ad7SLoic Poulain int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen,
2101d6ee6ad7SLoic Poulain 		   const void *param);
210275e84b7cSJohan Hedberg 
210307dc93ddSJohan Hedberg int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
210407dc93ddSJohan Hedberg 		 const void *param);
210573d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
21060d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
210726afbd82SLuiz Augusto von Dentz void hci_send_iso(struct hci_conn *conn, struct sk_buff *skb);
21081da177e4SLinus Torvalds 
2109a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
2110dfe6d5c3SLuiz Augusto von Dentz void *hci_recv_event_data(struct hci_dev *hdev, __u8 event);
21111da177e4SLinus Torvalds 
2112eab2404bSLuiz Augusto von Dentz u32 hci_conn_get_phy(struct hci_conn *conn);
2113eab2404bSLuiz Augusto von Dentz 
21141da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
2115470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
21167129069eSJohan Hedberg void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
2117c08b1a1dSMarcel Holtmann 			 int flag, struct sock *skip_sk);
2118cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
211938ceaa00SMarcel Holtmann void hci_send_monitor_ctrl_event(struct hci_dev *hdev, u16 event,
212038ceaa00SMarcel Holtmann 				 void *data, u16 data_len, ktime_t tstamp,
212138ceaa00SMarcel Holtmann 				 int flag, struct sock *skip_sk);
21221da177e4SLinus Torvalds 
2123040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event);
2124040030efSMarcel Holtmann 
2125a958452aSMarcel Holtmann #define HCI_MGMT_VAR_LEN	BIT(0)
2126a958452aSMarcel Holtmann #define HCI_MGMT_NO_HDEV	BIT(1)
2127a958452aSMarcel Holtmann #define HCI_MGMT_UNTRUSTED	BIT(2)
2128a958452aSMarcel Holtmann #define HCI_MGMT_UNCONFIGURED	BIT(3)
2129d5cc6626SMarcel Holtmann #define HCI_MGMT_HDEV_OPTIONAL	BIT(4)
2130b9a245fbSJohan Hedberg 
2131801c1e8dSJohan Hedberg struct hci_mgmt_handler {
2132801c1e8dSJohan Hedberg 	int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
2133801c1e8dSJohan Hedberg 		     u16 data_len);
2134801c1e8dSJohan Hedberg 	size_t data_len;
2135b9a245fbSJohan Hedberg 	unsigned long flags;
2136801c1e8dSJohan Hedberg };
2137801c1e8dSJohan Hedberg 
2138801c1e8dSJohan Hedberg struct hci_mgmt_chan {
2139801c1e8dSJohan Hedberg 	struct list_head list;
2140801c1e8dSJohan Hedberg 	unsigned short channel;
2141801c1e8dSJohan Hedberg 	size_t handler_count;
2142801c1e8dSJohan Hedberg 	const struct hci_mgmt_handler *handlers;
214388b94ce9SJohan Hedberg 	void (*hdev_init) (struct sock *sk, struct hci_dev *hdev);
2144801c1e8dSJohan Hedberg };
2145801c1e8dSJohan Hedberg 
2146801c1e8dSJohan Hedberg int hci_mgmt_chan_register(struct hci_mgmt_chan *c);
2147801c1e8dSJohan Hedberg void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c);
2148801c1e8dSJohan Hedberg 
21490381101fSJohan Hedberg /* Management interface */
2150591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR		(BIT(BDADDR_BREDR))
2151591f47f3SAndre Guedes #define DISCOV_TYPE_LE			(BIT(BDADDR_LE_PUBLIC) | \
2152591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2153591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED		(BIT(BDADDR_BREDR) | \
2154591f47f3SAndre Guedes 					 BIT(BDADDR_LE_PUBLIC) | \
2155591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
2156f39799f5SAndre Guedes 
21570d8cc935SAndre Guedes /* These LE scan and inquiry parameters were chosen according to LE General
21580d8cc935SAndre Guedes  * Discovery Procedure specification.
21590d8cc935SAndre Guedes  */
21600d8cc935SAndre Guedes #define DISCOV_LE_SCAN_WIN		0x12
21610d8cc935SAndre Guedes #define DISCOV_LE_SCAN_INT		0x12
21623d5a76f0SLukasz Rymanowski #define DISCOV_LE_TIMEOUT		10240	/* msec */
2163ae55f598SLukasz Rymanowski #define DISCOV_INTERLEAVED_TIMEOUT	5120	/* msec */
21640d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_INQUIRY_LEN	0x04
21650d8cc935SAndre Guedes #define DISCOV_BREDR_INQUIRY_LEN	0x08
21664b0e0cedSJakub Pawlowski #define DISCOV_LE_RESTART_DELAY		msecs_to_jiffies(200)	/* msec */
2167cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MIN	0x00A0	/* 100 msec */
2168cfa15ccaSMarcel Holtmann #define DISCOV_LE_FAST_ADV_INT_MAX	0x00F0	/* 150 msec */
2169eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MIN	0x00A0	/* 200 msec */
2170eca0ae4aSLuiz Augusto von Dentz #define DISCOV_LE_PER_ADV_INT_MAX	0x00A0	/* 200 msec */
2171b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MIN		0x00A0  /* 100 msec */
2172b338d917SBrian Gix #define DISCOV_LE_ADV_MESH_MAX		0x00A0  /* 100 msec */
2173b338d917SBrian Gix #define INTERVAL_TO_MS(x)		(((x) * 10) / 0x10)
21740d8cc935SAndre Guedes 
2175dbf6811aSArchie Pusaka #define NAME_RESOLVE_DURATION		msecs_to_jiffies(10240)	/* 10.24 sec */
2176dbf6811aSArchie Pusaka 
217703c979c4SMarcel Holtmann void mgmt_fill_version_info(void *ver);
217891a668b0SJohan Hedberg int mgmt_new_settings(struct hci_dev *hdev);
2179bf6b56dbSMarcel Holtmann void mgmt_index_added(struct hci_dev *hdev);
2180bf6b56dbSMarcel Holtmann void mgmt_index_removed(struct hci_dev *hdev);
21813eec705eSMarcel Holtmann void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
21822ff13894SJohan Hedberg void mgmt_power_on(struct hci_dev *hdev, int err);
21832ff13894SJohan Hedberg void __mgmt_power_off(struct hci_dev *hdev);
2184dc4a5ee2SMarcel Holtmann void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
2185745c0ce3SVishal Agarwal 		       bool persistent);
218648ec92faSAlfonso Acosta void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn,
21871c6ed31bSYu Liu 			   u8 *name, u8 name_len);
21889b80ec5eSMarcel Holtmann void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
218912d4a3b2SJohan Hedberg 			      u8 link_type, u8 addr_type, u8 reason,
219012d4a3b2SJohan Hedberg 			      bool mgmt_connected);
21917892924cSMarcel Holtmann void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
219288c3df13SJohan Hedberg 			    u8 link_type, u8 addr_type, u8 status);
2193445608d0SMarcel Holtmann void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
219448264f06SJohan Hedberg 			 u8 addr_type, u8 status);
2195ce0e4a0dSMarcel Holtmann void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
2196e669cf80SMarcel Holtmann void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2197c35938b2SSzymon Janc 				  u8 status);
21983eb38528SMarcel Holtmann void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2199744cf19eSJohan Hedberg 				      u8 status);
2200744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
220139adbffeSJohan Hedberg 			      u8 link_type, u8 addr_type, u32 value,
2202272d90dfSJohan Hedberg 			      u8 confirm_hint);
2203744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2204272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2205272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2206272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
2207272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
2208272d90dfSJohan Hedberg 			      u8 link_type, u8 addr_type);
2209604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2210272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
2211272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
2212272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
221392a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
221492a25256SJohan Hedberg 			     u8 link_type, u8 addr_type, u32 passkey,
221592a25256SJohan Hedberg 			     u8 entered);
2216e1e930f5SJohan Hedberg void mgmt_auth_failed(struct hci_conn *conn, u8 status);
2217464996aeSMarcel Holtmann void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
22184e1b0245SMarcel Holtmann void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
22197f9a903cSMarcel Holtmann 				    u8 status);
22207667da34SMarcel Holtmann void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
2221e68f072bSJohan Hedberg void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status);
22222154d3f4SJohan Hedberg void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status);
2223901801b9SMarcel Holtmann void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2224af58925cSMarcel Holtmann 		       u8 addr_type, u8 *dev_class, s8 rssi, u32 flags,
2225b338d917SBrian Gix 		       u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len,
2226b338d917SBrian Gix 		       u64 instant);
22279cf12aeeSMarcel Holtmann void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
2228b644ba33SJohan Hedberg 		      u8 addr_type, s8 rssi, u8 *name, u8 name_len);
22292f1e063bSMarcel Holtmann void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
2230346ce5b7SAbhishek Pandit-Subedi void mgmt_suspending(struct hci_dev *hdev, u8 state);
2231346ce5b7SAbhishek Pandit-Subedi void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr,
2232346ce5b7SAbhishek Pandit-Subedi 		   u8 addr_type);
223384c61d92SJohan Hedberg bool mgmt_powering_down(struct hci_dev *hdev);
223453ac6ab6SMarcel Holtmann void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
2235cad20c27SJohan Hedberg void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent);
223653ac6ab6SMarcel Holtmann void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
223753ac6ab6SMarcel Holtmann 		   bool persistent);
2238ffb5a827SAndre Guedes void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr,
2239f4869e2aSJohan Hedberg 			 u8 bdaddr_type, u8 store_hint, u16 min_interval,
2240f4869e2aSJohan Hedberg 			 u16 max_interval, u16 latency, u16 timeout);
2241f4a407beSJohan Hedberg void mgmt_smp_complete(struct hci_conn *conn, bool complete);
2242f2252570SJohan Hedberg bool mgmt_get_connectable(struct hci_dev *hdev);
2243f2252570SJohan Hedberg u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev);
2244f2252570SJohan Hedberg void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev,
2245f2252570SJohan Hedberg 			    u8 instance);
2246f2252570SJohan Hedberg void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev,
2247f2252570SJohan Hedberg 			      u8 instance);
224866bd095aSArchie Pusaka void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle);
2249b7c23df8SJaganath Kanakkassery int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip);
22508d7f1677SManish Mandlik void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle,
22518d7f1677SManish Mandlik 				  bdaddr_t *bdaddr, u8 addr_type);
2252346af67bSVinicius Costa Gomes 
22531a942de0SBrian Gix int hci_abort_conn(struct hci_conn *conn, u8 reason);
22547d6ca693SJohan Hedberg u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency,
22557d6ca693SJohan Hedberg 		      u16 to_multiplier);
2256fe39c7b2SMarcel Holtmann void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
22578b76ce34SJohan Hedberg 		      __u8 ltk[16], __u8 key_size);
22582519a1fcSAndre Guedes 
2259a1f4c318SJohan Hedberg void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
2260a1f4c318SJohan Hedberg 			       u8 *bdaddr_type);
2261ebd3a747SJohan Hedberg 
22625d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_MASK       0x0003
22635d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_CVSD       0x0000
22645d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_TRANSP     0x0003
22655d4d62f6SFrédéric Dalleau 
22668961987fSKiran K #define LOCAL_CODEC_ACL_MASK	BIT(0)
22678961987fSKiran K #define LOCAL_CODEC_SCO_MASK	BIT(1)
22688961987fSKiran K 
22698961987fSKiran K #define TRANSPORT_TYPE_MAX	0x04
22708961987fSKiran K 
22711da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
2272