xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision ae55f598)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds    BlueZ - Bluetooth protocol stack for Linux
32d0a0346SRon Shaffer    Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
41da177e4SLinus Torvalds 
51da177e4SLinus Torvalds    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
61da177e4SLinus Torvalds 
71da177e4SLinus Torvalds    This program is free software; you can redistribute it and/or modify
81da177e4SLinus Torvalds    it under the terms of the GNU General Public License version 2 as
91da177e4SLinus Torvalds    published by the Free Software Foundation;
101da177e4SLinus Torvalds 
111da177e4SLinus Torvalds    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
121da177e4SLinus Torvalds    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
131da177e4SLinus Torvalds    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
141da177e4SLinus Torvalds    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
151da177e4SLinus Torvalds    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
161da177e4SLinus Torvalds    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
171da177e4SLinus Torvalds    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
181da177e4SLinus Torvalds    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
211da177e4SLinus Torvalds    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
221da177e4SLinus Torvalds    SOFTWARE IS DISCLAIMED.
231da177e4SLinus Torvalds */
241da177e4SLinus Torvalds 
251da177e4SLinus Torvalds #ifndef __HCI_CORE_H
261da177e4SLinus Torvalds #define __HCI_CORE_H
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #include <net/bluetooth/hci.h>
291da177e4SLinus Torvalds 
305e59b791SLuiz Augusto von Dentz /* HCI priority */
315e59b791SLuiz Augusto von Dentz #define HCI_PRIO_MAX	7
325e59b791SLuiz Augusto von Dentz 
331da177e4SLinus Torvalds /* HCI Core structures */
341da177e4SLinus Torvalds struct inquiry_data {
351da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
361da177e4SLinus Torvalds 	__u8		pscan_rep_mode;
371da177e4SLinus Torvalds 	__u8		pscan_period_mode;
381da177e4SLinus Torvalds 	__u8		pscan_mode;
391da177e4SLinus Torvalds 	__u8		dev_class[3];
401ebb9252SMarcel Holtmann 	__le16		clock_offset;
411da177e4SLinus Torvalds 	__s8		rssi;
4241a96212SMarcel Holtmann 	__u8		ssp_mode;
431da177e4SLinus Torvalds };
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds struct inquiry_entry {
46561aafbcSJohan Hedberg 	struct list_head	all;		/* inq_cache.all */
47561aafbcSJohan Hedberg 	struct list_head	list;		/* unknown or resolve */
48561aafbcSJohan Hedberg 	enum {
49561aafbcSJohan Hedberg 		NAME_NOT_KNOWN,
50561aafbcSJohan Hedberg 		NAME_NEEDED,
51561aafbcSJohan Hedberg 		NAME_PENDING,
52561aafbcSJohan Hedberg 		NAME_KNOWN,
53561aafbcSJohan Hedberg 	} name_state;
541da177e4SLinus Torvalds 	__u32			timestamp;
551da177e4SLinus Torvalds 	struct inquiry_data	data;
561da177e4SLinus Torvalds };
571da177e4SLinus Torvalds 
5830883512SJohan Hedberg struct discovery_state {
594aab14e5SAndre Guedes 	int			type;
60ff9ef578SJohan Hedberg 	enum {
61ff9ef578SJohan Hedberg 		DISCOVERY_STOPPED,
62ff9ef578SJohan Hedberg 		DISCOVERY_STARTING,
63343f935bSAndre Guedes 		DISCOVERY_FINDING,
6430dc78e1SJohan Hedberg 		DISCOVERY_RESOLVING,
65ff9ef578SJohan Hedberg 		DISCOVERY_STOPPING,
66ff9ef578SJohan Hedberg 	} state;
67561aafbcSJohan Hedberg 	struct list_head	all;	/* All devices found during inquiry */
68561aafbcSJohan Hedberg 	struct list_head	unknown;	/* Name state not known */
69561aafbcSJohan Hedberg 	struct list_head	resolve;	/* Name needs to be resolved */
701da177e4SLinus Torvalds 	__u32			timestamp;
71b9a6328fSJohan Hedberg 	bdaddr_t		last_adv_addr;
72b9a6328fSJohan Hedberg 	u8			last_adv_addr_type;
73ff5cd29fSJohan Hedberg 	s8			last_adv_rssi;
74b9a6328fSJohan Hedberg 	u8			last_adv_data[HCI_MAX_AD_LENGTH];
75b9a6328fSJohan Hedberg 	u8			last_adv_data_len;
761da177e4SLinus Torvalds };
771da177e4SLinus Torvalds 
781da177e4SLinus Torvalds struct hci_conn_hash {
791da177e4SLinus Torvalds 	struct list_head list;
801da177e4SLinus Torvalds 	unsigned int     acl_num;
81bd1eb66bSAndrei Emeltchenko 	unsigned int     amp_num;
821da177e4SLinus Torvalds 	unsigned int     sco_num;
83fcd89c09SVille Tervo 	unsigned int     le_num;
841da177e4SLinus Torvalds };
851da177e4SLinus Torvalds 
86f0358568SJohan Hedberg struct bdaddr_list {
87f0358568SJohan Hedberg 	struct list_head list;
88f0358568SJohan Hedberg 	bdaddr_t bdaddr;
89b9ee0a78SMarcel Holtmann 	u8 bdaddr_type;
90f0358568SJohan Hedberg };
912aeb9a1aSJohan Hedberg 
922aeb9a1aSJohan Hedberg struct bt_uuid {
932aeb9a1aSJohan Hedberg 	struct list_head list;
942aeb9a1aSJohan Hedberg 	u8 uuid[16];
9583be8ecaSJohan Hedberg 	u8 size;
961aff6f09SJohan Hedberg 	u8 svc_hint;
972aeb9a1aSJohan Hedberg };
982aeb9a1aSJohan Hedberg 
997ee4ea36SMarcel Holtmann struct smp_csrk {
1007ee4ea36SMarcel Holtmann 	bdaddr_t bdaddr;
1017ee4ea36SMarcel Holtmann 	u8 bdaddr_type;
1027ee4ea36SMarcel Holtmann 	u8 master;
1037ee4ea36SMarcel Holtmann 	u8 val[16];
1047ee4ea36SMarcel Holtmann };
1057ee4ea36SMarcel Holtmann 
106b899efafSVinicius Costa Gomes struct smp_ltk {
107b899efafSVinicius Costa Gomes 	struct list_head list;
108b899efafSVinicius Costa Gomes 	bdaddr_t bdaddr;
109b899efafSVinicius Costa Gomes 	u8 bdaddr_type;
110b899efafSVinicius Costa Gomes 	u8 authenticated;
111b899efafSVinicius Costa Gomes 	u8 type;
112b899efafSVinicius Costa Gomes 	u8 enc_size;
113b899efafSVinicius Costa Gomes 	__le16 ediv;
114fe39c7b2SMarcel Holtmann 	__le64 rand;
115b899efafSVinicius Costa Gomes 	u8 val[16];
11603c515d7SMarcel Holtmann };
117b899efafSVinicius Costa Gomes 
118970c4e46SJohan Hedberg struct smp_irk {
119970c4e46SJohan Hedberg 	struct list_head list;
120970c4e46SJohan Hedberg 	bdaddr_t rpa;
121970c4e46SJohan Hedberg 	bdaddr_t bdaddr;
122970c4e46SJohan Hedberg 	u8 addr_type;
123970c4e46SJohan Hedberg 	u8 val[16];
124970c4e46SJohan Hedberg };
125970c4e46SJohan Hedberg 
12655ed8ca1SJohan Hedberg struct link_key {
12755ed8ca1SJohan Hedberg 	struct list_head list;
12855ed8ca1SJohan Hedberg 	bdaddr_t bdaddr;
12955ed8ca1SJohan Hedberg 	u8 type;
1309b3b4460SAndrei Emeltchenko 	u8 val[HCI_LINK_KEY_SIZE];
13155ed8ca1SJohan Hedberg 	u8 pin_len;
13255ed8ca1SJohan Hedberg };
13355ed8ca1SJohan Hedberg 
1342763eda6SSzymon Janc struct oob_data {
1352763eda6SSzymon Janc 	struct list_head list;
1362763eda6SSzymon Janc 	bdaddr_t bdaddr;
137519ca9d0SMarcel Holtmann 	u8 hash192[16];
138519ca9d0SMarcel Holtmann 	u8 randomizer192[16];
139519ca9d0SMarcel Holtmann 	u8 hash256[16];
140519ca9d0SMarcel Holtmann 	u8 randomizer256[16];
1412763eda6SSzymon Janc };
1422763eda6SSzymon Janc 
143490c5babSJohan Hedberg #define HCI_MAX_SHORT_NAME_LENGTH	10
144490c5babSJohan Hedberg 
145d6bfd59cSJohan Hedberg /* Default LE RPA expiry time, 15 minutes */
146d6bfd59cSJohan Hedberg #define HCI_DEFAULT_RPA_TIMEOUT		(15 * 60)
147d6bfd59cSJohan Hedberg 
148903e4541SAndrei Emeltchenko struct amp_assoc {
149903e4541SAndrei Emeltchenko 	__u16	len;
150903e4541SAndrei Emeltchenko 	__u16	offset;
15193c284eeSAndrei Emeltchenko 	__u16	rem_len;
15293c284eeSAndrei Emeltchenko 	__u16	len_so_far;
153903e4541SAndrei Emeltchenko 	__u8	data[HCI_MAX_AMP_ASSOC_SIZE];
154903e4541SAndrei Emeltchenko };
155903e4541SAndrei Emeltchenko 
156d2c5d77fSJohan Hedberg #define HCI_MAX_PAGES	3
157cad718edSJohan Hedberg 
158cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4
1591da177e4SLinus Torvalds struct hci_dev {
1601da177e4SLinus Torvalds 	struct list_head list;
16109fd0de5SGustavo F. Padovan 	struct mutex	lock;
1621da177e4SLinus Torvalds 
1631da177e4SLinus Torvalds 	char		name[8];
1641da177e4SLinus Torvalds 	unsigned long	flags;
1651da177e4SLinus Torvalds 	__u16		id;
166c13854ceSMarcel Holtmann 	__u8		bus;
167943da25dSMarcel Holtmann 	__u8		dev_type;
1681da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
1697a4cd51dSMarcel Holtmann 	bdaddr_t	random_addr;
170d13eafceSMarcel Holtmann 	bdaddr_t	static_addr;
17156ed2cb8SJohan Hedberg 	__u8		adv_addr_type;
1721f6c6378SJohan Hedberg 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
173490c5babSJohan Hedberg 	__u8		short_name[HCI_MAX_SHORT_NAME_LENGTH];
17480a1e1dbSJohan Hedberg 	__u8		eir[HCI_MAX_EIR_LENGTH];
175a9de9248SMarcel Holtmann 	__u8		dev_class[3];
1761aff6f09SJohan Hedberg 	__u8		major_class;
1771aff6f09SJohan Hedberg 	__u8		minor_class;
178d2c5d77fSJohan Hedberg 	__u8		max_page;
179cad718edSJohan Hedberg 	__u8		features[HCI_MAX_PAGES][8];
18060e77321SJohan Hedberg 	__u8		le_features[8];
181cf1d081fSJohan Hedberg 	__u8		le_white_list_size;
1829b008c04SJohan Hedberg 	__u8		le_states[8];
183a9de9248SMarcel Holtmann 	__u8		commands[64];
1841143e5a6SMarcel Holtmann 	__u8		hci_ver;
1851143e5a6SMarcel Holtmann 	__u16		hci_rev;
186d5859e22SJohan Hedberg 	__u8		lmp_ver;
1871143e5a6SMarcel Holtmann 	__u16		manufacturer;
1887d69230cSAndrei Emeltchenko 	__u16		lmp_subver;
1891da177e4SLinus Torvalds 	__u16		voice_setting;
190b4cb9fb2SMarcel Holtmann 	__u8		num_iac;
19117fa4b9dSJohan Hedberg 	__u8		io_capability;
19291c4e9b1SMarcel Holtmann 	__s8		inq_tx_power;
193f332ec66SJohan Hedberg 	__u16		page_scan_interval;
194f332ec66SJohan Hedberg 	__u16		page_scan_window;
195f332ec66SJohan Hedberg 	__u8		page_scan_type;
1963f959d46SMarcel Holtmann 	__u8		le_adv_channel_map;
197533553f8SMarcel Holtmann 	__u8		le_scan_type;
198bef64738SMarcel Holtmann 	__u16		le_scan_interval;
199bef64738SMarcel Holtmann 	__u16		le_scan_window;
2004e70c7e7SMarcel Holtmann 	__u16		le_conn_min_interval;
2014e70c7e7SMarcel Holtmann 	__u16		le_conn_max_interval;
20206f5b778SMarcel Holtmann 	__u8		ssp_debug_mode;
203f332ec66SJohan Hedberg 
2042b9be137SMarcel Holtmann 	__u16		devid_source;
2052b9be137SMarcel Holtmann 	__u16		devid_vendor;
2062b9be137SMarcel Holtmann 	__u16		devid_product;
2072b9be137SMarcel Holtmann 	__u16		devid_version;
2081da177e4SLinus Torvalds 
2091da177e4SLinus Torvalds 	__u16		pkt_type;
2105b7f9909SMarcel Holtmann 	__u16		esco_type;
2111da177e4SLinus Torvalds 	__u16		link_policy;
2121da177e4SLinus Torvalds 	__u16		link_mode;
2131da177e4SLinus Torvalds 
21404837f64SMarcel Holtmann 	__u32		idle_timeout;
21504837f64SMarcel Holtmann 	__u16		sniff_min_interval;
21604837f64SMarcel Holtmann 	__u16		sniff_max_interval;
21704837f64SMarcel Holtmann 
218928abaa7SAndrei Emeltchenko 	__u8		amp_status;
219928abaa7SAndrei Emeltchenko 	__u32		amp_total_bw;
220928abaa7SAndrei Emeltchenko 	__u32		amp_max_bw;
221928abaa7SAndrei Emeltchenko 	__u32		amp_min_latency;
222928abaa7SAndrei Emeltchenko 	__u32		amp_max_pdu;
223928abaa7SAndrei Emeltchenko 	__u8		amp_type;
224928abaa7SAndrei Emeltchenko 	__u16		amp_pal_cap;
225928abaa7SAndrei Emeltchenko 	__u16		amp_assoc_size;
226928abaa7SAndrei Emeltchenko 	__u32		amp_max_flush_to;
227928abaa7SAndrei Emeltchenko 	__u32		amp_be_flush_to;
228928abaa7SAndrei Emeltchenko 
229903e4541SAndrei Emeltchenko 	struct amp_assoc	loc_assoc;
230903e4541SAndrei Emeltchenko 
2311e89cffbSAndrei Emeltchenko 	__u8		flow_ctl_mode;
2321e89cffbSAndrei Emeltchenko 
2339f61656aSJohan Hedberg 	unsigned int	auto_accept_delay;
2349f61656aSJohan Hedberg 
2351da177e4SLinus Torvalds 	unsigned long	quirks;
2361da177e4SLinus Torvalds 
2371da177e4SLinus Torvalds 	atomic_t	cmd_cnt;
2381da177e4SLinus Torvalds 	unsigned int	acl_cnt;
2391da177e4SLinus Torvalds 	unsigned int	sco_cnt;
2406ed58ec5SVille Tervo 	unsigned int	le_cnt;
2411da177e4SLinus Torvalds 
2421da177e4SLinus Torvalds 	unsigned int	acl_mtu;
2431da177e4SLinus Torvalds 	unsigned int	sco_mtu;
2446ed58ec5SVille Tervo 	unsigned int	le_mtu;
2451da177e4SLinus Torvalds 	unsigned int	acl_pkts;
2461da177e4SLinus Torvalds 	unsigned int	sco_pkts;
2476ed58ec5SVille Tervo 	unsigned int	le_pkts;
2481da177e4SLinus Torvalds 
249350ee4cfSAndrei Emeltchenko 	__u16		block_len;
250350ee4cfSAndrei Emeltchenko 	__u16		block_mtu;
251350ee4cfSAndrei Emeltchenko 	__u16		num_blocks;
252350ee4cfSAndrei Emeltchenko 	__u16		block_cnt;
253350ee4cfSAndrei Emeltchenko 
2541da177e4SLinus Torvalds 	unsigned long	acl_last_tx;
2551da177e4SLinus Torvalds 	unsigned long	sco_last_tx;
2566ed58ec5SVille Tervo 	unsigned long	le_last_tx;
2571da177e4SLinus Torvalds 
258f48fd9c8SMarcel Holtmann 	struct workqueue_struct	*workqueue;
2596ead1bbcSJohan Hedberg 	struct workqueue_struct	*req_workqueue;
260f48fd9c8SMarcel Holtmann 
261ab81cbf9SJohan Hedberg 	struct work_struct	power_on;
2623243553fSJohan Hedberg 	struct delayed_work	power_off;
263ab81cbf9SJohan Hedberg 
26416ab91abSJohan Hedberg 	__u16			discov_timeout;
26516ab91abSJohan Hedberg 	struct delayed_work	discov_off;
26616ab91abSJohan Hedberg 
2677d78525dSJohan Hedberg 	struct delayed_work	service_cache;
2687d78525dSJohan Hedberg 
2696bd32326SVille Tervo 	struct timer_list	cmd_timer;
270b78752ccSMarcel Holtmann 
271b78752ccSMarcel Holtmann 	struct work_struct	rx_work;
272c347b765SGustavo F. Padovan 	struct work_struct	cmd_work;
2733eff45eaSGustavo F. Padovan 	struct work_struct	tx_work;
2741da177e4SLinus Torvalds 
2751da177e4SLinus Torvalds 	struct sk_buff_head	rx_q;
2761da177e4SLinus Torvalds 	struct sk_buff_head	raw_q;
2771da177e4SLinus Torvalds 	struct sk_buff_head	cmd_q;
2781da177e4SLinus Torvalds 
279b6ddb638SJohan Hedberg 	struct sk_buff		*recv_evt;
2801da177e4SLinus Torvalds 	struct sk_buff		*sent_cmd;
281cd4c5391SSuraj Sumangala 	struct sk_buff		*reassembly[NUM_REASSEMBLY];
2821da177e4SLinus Torvalds 
283a6a67efdSThomas Gleixner 	struct mutex		req_lock;
2841da177e4SLinus Torvalds 	wait_queue_head_t	req_wait_q;
2851da177e4SLinus Torvalds 	__u32			req_status;
2861da177e4SLinus Torvalds 	__u32			req_result;
287a5040efaSJohan Hedberg 
28899780a7bSJohan Hedberg 	struct crypto_blkcipher	*tfm_aes;
2892e58ef3eSJohan Hedberg 
29030883512SJohan Hedberg 	struct discovery_state	discovery;
2911da177e4SLinus Torvalds 	struct hci_conn_hash	conn_hash;
2925c136e90SAndre Guedes 
2935c136e90SAndre Guedes 	struct list_head	mgmt_pending;
294ea4bd8baSDavid Miller 	struct list_head	blacklist;
2952aeb9a1aSJohan Hedberg 	struct list_head	uuids;
29655ed8ca1SJohan Hedberg 	struct list_head	link_keys;
297b899efafSVinicius Costa Gomes 	struct list_head	long_term_keys;
298970c4e46SJohan Hedberg 	struct list_head	identity_resolving_keys;
2992763eda6SSzymon Janc 	struct list_head	remote_oob_data;
300d2ab0ac1SMarcel Holtmann 	struct list_head	le_white_list;
30115819a70SAndre Guedes 	struct list_head	le_conn_params;
30277a77a30SAndre Guedes 	struct list_head	pend_le_conns;
3032763eda6SSzymon Janc 
3041da177e4SLinus Torvalds 	struct hci_dev_stats	stat;
3051da177e4SLinus Torvalds 
3061da177e4SLinus Torvalds 	atomic_t		promisc;
3071da177e4SLinus Torvalds 
308ca325f69SMarcel Holtmann 	struct dentry		*debugfs;
309ca325f69SMarcel Holtmann 
310a91f2e39SMarcel Holtmann 	struct device		dev;
3111da177e4SLinus Torvalds 
312611b30f7SMarcel Holtmann 	struct rfkill		*rfkill;
313611b30f7SMarcel Holtmann 
314d23264a8SAndre Guedes 	unsigned long		dev_flags;
315d23264a8SAndre Guedes 
3167ba8b4beSAndre Guedes 	struct delayed_work	le_scan_disable;
3177ba8b4beSAndre Guedes 
3188fa19098SJohan Hedberg 	__s8			adv_tx_power;
3193f0f524bSJohan Hedberg 	__u8			adv_data[HCI_MAX_AD_LENGTH];
3203f0f524bSJohan Hedberg 	__u8			adv_data_len;
321f8e808bdSMarcel Holtmann 	__u8			scan_rsp_data[HCI_MAX_AD_LENGTH];
322f8e808bdSMarcel Holtmann 	__u8			scan_rsp_data_len;
3238fa19098SJohan Hedberg 
324863efaf2SJohan Hedberg 	__u8			irk[16];
325d6bfd59cSJohan Hedberg 	__u32			rpa_timeout;
326d6bfd59cSJohan Hedberg 	struct delayed_work	rpa_expired;
3272b5224dcSMarcel Holtmann 	bdaddr_t		rpa;
328863efaf2SJohan Hedberg 
3291da177e4SLinus Torvalds 	int (*open)(struct hci_dev *hdev);
3301da177e4SLinus Torvalds 	int (*close)(struct hci_dev *hdev);
3311da177e4SLinus Torvalds 	int (*flush)(struct hci_dev *hdev);
332f41c70c4SMarcel Holtmann 	int (*setup)(struct hci_dev *hdev);
3337bd8f09fSMarcel Holtmann 	int (*send)(struct hci_dev *hdev, struct sk_buff *skb);
3341da177e4SLinus Torvalds 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
3351da177e4SLinus Torvalds };
3361da177e4SLinus Torvalds 
33753502d69SAndrei Emeltchenko #define HCI_PHY_HANDLE(handle)	(handle & 0xff)
33853502d69SAndrei Emeltchenko 
3391da177e4SLinus Torvalds struct hci_conn {
3401da177e4SLinus Torvalds 	struct list_head list;
3411da177e4SLinus Torvalds 
3421da177e4SLinus Torvalds 	atomic_t	refcnt;
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds 	bdaddr_t	dst;
34529b7988aSAndre Guedes 	__u8		dst_type;
346662e8820SMarcel Holtmann 	bdaddr_t	src;
347e7c4096eSMarcel Holtmann 	__u8		src_type;
348cb1d68f7SJohan Hedberg 	bdaddr_t	init_addr;
349cb1d68f7SJohan Hedberg 	__u8		init_addr_type;
350cb1d68f7SJohan Hedberg 	bdaddr_t	resp_addr;
351cb1d68f7SJohan Hedberg 	__u8		resp_addr_type;
3521da177e4SLinus Torvalds 	__u16		handle;
3531da177e4SLinus Torvalds 	__u16		state;
35404837f64SMarcel Holtmann 	__u8		mode;
3551da177e4SLinus Torvalds 	__u8		type;
356a0c808b3SJohan Hedberg 	bool		out;
3574c67bc74SMarcel Holtmann 	__u8		attempt;
3581da177e4SLinus Torvalds 	__u8		dev_class[3];
359cad718edSJohan Hedberg 	__u8		features[HCI_MAX_PAGES][8];
360a8746417SMarcel Holtmann 	__u16		pkt_type;
36104837f64SMarcel Holtmann 	__u16		link_policy;
3621da177e4SLinus Torvalds 	__u32		link_mode;
36313d39315SWaldemar Rymarkiewicz 	__u8		key_type;
36440be492fSMarcel Holtmann 	__u8		auth_type;
3658c1b2355SMarcel Holtmann 	__u8		sec_level;
366765c2a96SJohan Hedberg 	__u8		pending_sec_level;
367980e1a53SJohan Hedberg 	__u8		pin_length;
368726b4ffcSVinicius Costa Gomes 	__u8		enc_key_size;
36917fa4b9dSJohan Hedberg 	__u8		io_capability;
37092a25256SJohan Hedberg 	__u32		passkey_notify;
37192a25256SJohan Hedberg 	__u8		passkey_entered;
372052b30b0SMarcel Holtmann 	__u16		disc_timeout;
37310c62ddcSFrédéric Dalleau 	__u16		setting;
3741e406eefSAndre Guedes 	__u16		le_conn_min_interval;
3751e406eefSAndre Guedes 	__u16		le_conn_max_interval;
37651a8efd7SJohan Hedberg 	unsigned long	flags;
3771da177e4SLinus Torvalds 
37803b555e1SJohan Hedberg 	__u8		remote_cap;
37903b555e1SJohan Hedberg 	__u8		remote_auth;
3803161ae1cSAndrei Emeltchenko 	__u8		remote_id;
3816ec5bcadSVishal Agarwal 	bool		flush_key;
38203b555e1SJohan Hedberg 
3831da177e4SLinus Torvalds 	unsigned int	sent;
3841da177e4SLinus Torvalds 
3851da177e4SLinus Torvalds 	struct sk_buff_head data_q;
3862c33c06aSGustavo F. Padovan 	struct list_head chan_list;
3871da177e4SLinus Torvalds 
38819c40e3bSGustavo F. Padovan 	struct delayed_work disc_work;
3897bc18d9dSJohan Hedberg 	struct delayed_work auto_accept_work;
390a74a84f6SJohan Hedberg 	struct delayed_work idle_work;
3919489eca4SJohan Hedberg 	struct delayed_work le_conn_timeout;
3921da177e4SLinus Torvalds 
393b219e3acSMarcel Holtmann 	struct device	dev;
394b219e3acSMarcel Holtmann 
3951da177e4SLinus Torvalds 	struct hci_dev	*hdev;
3961da177e4SLinus Torvalds 	void		*l2cap_data;
3971da177e4SLinus Torvalds 	void		*sco_data;
3982b64d153SBrian Gix 	void		*smp_conn;
3999740e49dSAndrei Emeltchenko 	struct amp_mgr	*amp_mgr;
4001da177e4SLinus Torvalds 
4011da177e4SLinus Torvalds 	struct hci_conn	*link;
402e9a416b5SJohan Hedberg 
403e9a416b5SJohan Hedberg 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
404e9a416b5SJohan Hedberg 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
405e9a416b5SJohan Hedberg 	void (*disconn_cfm_cb)	(struct hci_conn *conn, u8 reason);
4061da177e4SLinus Torvalds };
4071da177e4SLinus Torvalds 
40873d80debSLuiz Augusto von Dentz struct hci_chan {
40973d80debSLuiz Augusto von Dentz 	struct list_head list;
41042c4e53eSAndrei Emeltchenko 	__u16 handle;
41173d80debSLuiz Augusto von Dentz 	struct hci_conn *conn;
41273d80debSLuiz Augusto von Dentz 	struct sk_buff_head data_q;
41373d80debSLuiz Augusto von Dentz 	unsigned int	sent;
414168df8e5SMat Martineau 	__u8		state;
41573d80debSLuiz Augusto von Dentz };
41673d80debSLuiz Augusto von Dentz 
41715819a70SAndre Guedes struct hci_conn_params {
41815819a70SAndre Guedes 	struct list_head list;
41915819a70SAndre Guedes 
42015819a70SAndre Guedes 	bdaddr_t addr;
42115819a70SAndre Guedes 	u8 addr_type;
42215819a70SAndre Guedes 
42315819a70SAndre Guedes 	u16 conn_min_interval;
42415819a70SAndre Guedes 	u16 conn_max_interval;
4259fcb18efSAndre Guedes 
4269fcb18efSAndre Guedes 	enum {
4279fcb18efSAndre Guedes 		HCI_AUTO_CONN_DISABLED,
4289fcb18efSAndre Guedes 		HCI_AUTO_CONN_ALWAYS,
4299fcb18efSAndre Guedes 		HCI_AUTO_CONN_LINK_LOSS,
4309fcb18efSAndre Guedes 	} auto_connect;
43115819a70SAndre Guedes };
43215819a70SAndre Guedes 
4331da177e4SLinus Torvalds extern struct list_head hci_dev_list;
4341da177e4SLinus Torvalds extern struct list_head hci_cb_list;
4351da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock;
4361da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock;
4371da177e4SLinus Torvalds 
438686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */
439e74e58f8SJoe Perches int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
440e74e58f8SJoe Perches void l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
441e74e58f8SJoe Perches int l2cap_disconn_ind(struct hci_conn *hcon);
442e74e58f8SJoe Perches void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
443e74e58f8SJoe Perches int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
444e74e58f8SJoe Perches int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
445686ebf28SUlisses Furquim 
446e74e58f8SJoe Perches int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags);
447e74e58f8SJoe Perches void sco_connect_cfm(struct hci_conn *hcon, __u8 status);
448e74e58f8SJoe Perches void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
449e74e58f8SJoe Perches int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
450686ebf28SUlisses Furquim 
4511da177e4SLinus Torvalds /* ----- Inquiry cache ----- */
45270f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX   (HZ*30)   /* 30 seconds */
45370f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   /* 60 seconds */
4541da177e4SLinus Torvalds 
45530883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev)
4561da177e4SLinus Torvalds {
457ff9ef578SJohan Hedberg 	hdev->discovery.state = DISCOVERY_STOPPED;
45830883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.all);
45930883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.unknown);
46030883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.resolve);
4611da177e4SLinus Torvalds }
4621da177e4SLinus Torvalds 
46330dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev);
46430dc78e1SJohan Hedberg 
465ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state);
466ff9ef578SJohan Hedberg 
4671da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev)
4681da177e4SLinus Torvalds {
46930883512SJohan Hedberg 	return list_empty(&hdev->discovery.all);
4701da177e4SLinus Torvalds }
4711da177e4SLinus Torvalds 
4721da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev)
4731da177e4SLinus Torvalds {
47430883512SJohan Hedberg 	struct discovery_state *c = &hdev->discovery;
4751da177e4SLinus Torvalds 	return jiffies - c->timestamp;
4761da177e4SLinus Torvalds }
4771da177e4SLinus Torvalds 
4781da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e)
4791da177e4SLinus Torvalds {
4801da177e4SLinus Torvalds 	return jiffies - e->timestamp;
4811da177e4SLinus Torvalds }
4821da177e4SLinus Torvalds 
4835a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
4845a9d0a3fSWaldemar Rymarkiewicz 					       bdaddr_t *bdaddr);
485561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
486561aafbcSJohan Hedberg 						       bdaddr_t *bdaddr);
48730dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
48830dc78e1SJohan Hedberg 						       bdaddr_t *bdaddr,
48930dc78e1SJohan Hedberg 						       int state);
490a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
491a3d4e20aSJohan Hedberg 				      struct inquiry_entry *ie);
4923175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
493388fc8faSJohan Hedberg 			      bool name_known, bool *ssp);
4941f9b9a5dSAndre Guedes void hci_inquiry_cache_flush(struct hci_dev *hdev);
4951da177e4SLinus Torvalds 
4961da177e4SLinus Torvalds /* ----- HCI Connections ----- */
4971da177e4SLinus Torvalds enum {
4981da177e4SLinus Torvalds 	HCI_CONN_AUTH_PEND,
49919f8def0SWaldemar Rymarkiewicz 	HCI_CONN_REAUTH_PEND,
5001da177e4SLinus Torvalds 	HCI_CONN_ENCRYPT_PEND,
50104837f64SMarcel Holtmann 	HCI_CONN_RSWITCH_PEND,
50204837f64SMarcel Holtmann 	HCI_CONN_MODE_CHANGE_PEND,
503e73439d8SMarcel Holtmann 	HCI_CONN_SCO_SETUP_PEND,
504d26a2345SVinicius Costa Gomes 	HCI_CONN_LE_SMP_PEND,
505b644ba33SJohan Hedberg 	HCI_CONN_MGMT_CONNECTED,
50658a681efSJohan Hedberg 	HCI_CONN_SSP_ENABLED,
507eb9a8f3fSMarcel Holtmann 	HCI_CONN_SC_ENABLED,
508abf76badSMarcel Holtmann 	HCI_CONN_AES_CCM,
50958a681efSJohan Hedberg 	HCI_CONN_POWER_SAVE,
51058a681efSJohan Hedberg 	HCI_CONN_REMOTE_OOB,
51118722c24SJukka Rissanen 	HCI_CONN_6LOWPAN,
5121da177e4SLinus Torvalds };
5131da177e4SLinus Torvalds 
514aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
515aa64a8b5SJohan Hedberg {
516aa64a8b5SJohan Hedberg 	struct hci_dev *hdev = conn->hdev;
517c3c7ea65SGustavo Padovan 	return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
518c3c7ea65SGustavo Padovan 	       test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
519aa64a8b5SJohan Hedberg }
520aa64a8b5SJohan Hedberg 
521eb9a8f3fSMarcel Holtmann static inline bool hci_conn_sc_enabled(struct hci_conn *conn)
522eb9a8f3fSMarcel Holtmann {
523eb9a8f3fSMarcel Holtmann 	struct hci_dev *hdev = conn->hdev;
524eb9a8f3fSMarcel Holtmann 	return test_bit(HCI_SC_ENABLED, &hdev->dev_flags) &&
525eb9a8f3fSMarcel Holtmann 	       test_bit(HCI_CONN_SC_ENABLED, &conn->flags);
526eb9a8f3fSMarcel Holtmann }
527eb9a8f3fSMarcel Holtmann 
5281da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
5291da177e4SLinus Torvalds {
5301da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
531bf4c6325SGustavo F. Padovan 	list_add_rcu(&c->list, &h->list);
532fcd89c09SVille Tervo 	switch (c->type) {
533fcd89c09SVille Tervo 	case ACL_LINK:
5341da177e4SLinus Torvalds 		h->acl_num++;
535fcd89c09SVille Tervo 		break;
536bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
537bd1eb66bSAndrei Emeltchenko 		h->amp_num++;
538bd1eb66bSAndrei Emeltchenko 		break;
539fcd89c09SVille Tervo 	case LE_LINK:
540fcd89c09SVille Tervo 		h->le_num++;
541fcd89c09SVille Tervo 		break;
542fcd89c09SVille Tervo 	case SCO_LINK:
543fcd89c09SVille Tervo 	case ESCO_LINK:
5441da177e4SLinus Torvalds 		h->sco_num++;
545fcd89c09SVille Tervo 		break;
546fcd89c09SVille Tervo 	}
5471da177e4SLinus Torvalds }
5481da177e4SLinus Torvalds 
5491da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
5501da177e4SLinus Torvalds {
5511da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
552bf4c6325SGustavo F. Padovan 
553bf4c6325SGustavo F. Padovan 	list_del_rcu(&c->list);
554bf4c6325SGustavo F. Padovan 	synchronize_rcu();
555bf4c6325SGustavo F. Padovan 
556fcd89c09SVille Tervo 	switch (c->type) {
557fcd89c09SVille Tervo 	case ACL_LINK:
5581da177e4SLinus Torvalds 		h->acl_num--;
559fcd89c09SVille Tervo 		break;
560bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
561bd1eb66bSAndrei Emeltchenko 		h->amp_num--;
562bd1eb66bSAndrei Emeltchenko 		break;
563fcd89c09SVille Tervo 	case LE_LINK:
564fcd89c09SVille Tervo 		h->le_num--;
565fcd89c09SVille Tervo 		break;
566fcd89c09SVille Tervo 	case SCO_LINK:
567fcd89c09SVille Tervo 	case ESCO_LINK:
5681da177e4SLinus Torvalds 		h->sco_num--;
569fcd89c09SVille Tervo 		break;
570fcd89c09SVille Tervo 	}
5711da177e4SLinus Torvalds }
5721da177e4SLinus Torvalds 
57352087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
57452087a79SLuiz Augusto von Dentz {
57552087a79SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
57652087a79SLuiz Augusto von Dentz 	switch (type) {
57752087a79SLuiz Augusto von Dentz 	case ACL_LINK:
57852087a79SLuiz Augusto von Dentz 		return h->acl_num;
579bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
580bd1eb66bSAndrei Emeltchenko 		return h->amp_num;
58152087a79SLuiz Augusto von Dentz 	case LE_LINK:
58252087a79SLuiz Augusto von Dentz 		return h->le_num;
58352087a79SLuiz Augusto von Dentz 	case SCO_LINK:
58452087a79SLuiz Augusto von Dentz 	case ESCO_LINK:
58552087a79SLuiz Augusto von Dentz 		return h->sco_num;
58652087a79SLuiz Augusto von Dentz 	default:
58752087a79SLuiz Augusto von Dentz 		return 0;
58852087a79SLuiz Augusto von Dentz 	}
58952087a79SLuiz Augusto von Dentz }
59052087a79SLuiz Augusto von Dentz 
591f4f07505SJohan Hedberg static inline unsigned int hci_conn_count(struct hci_dev *hdev)
592f4f07505SJohan Hedberg {
593f4f07505SJohan Hedberg 	struct hci_conn_hash *c = &hdev->conn_hash;
594f4f07505SJohan Hedberg 
595f4f07505SJohan Hedberg 	return c->acl_num + c->amp_num + c->sco_num + c->le_num;
596f4f07505SJohan Hedberg }
597f4f07505SJohan Hedberg 
5981da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
5991da177e4SLinus Torvalds 								__u16 handle)
6001da177e4SLinus Torvalds {
6011da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
6021da177e4SLinus Torvalds 	struct hci_conn  *c;
6031da177e4SLinus Torvalds 
604bf4c6325SGustavo F. Padovan 	rcu_read_lock();
605bf4c6325SGustavo F. Padovan 
606bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
607bf4c6325SGustavo F. Padovan 		if (c->handle == handle) {
608bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
6091da177e4SLinus Torvalds 			return c;
6101da177e4SLinus Torvalds 		}
611bf4c6325SGustavo F. Padovan 	}
612bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
613bf4c6325SGustavo F. Padovan 
6141da177e4SLinus Torvalds 	return NULL;
6151da177e4SLinus Torvalds }
6161da177e4SLinus Torvalds 
6171da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
6181da177e4SLinus Torvalds 							__u8 type, bdaddr_t *ba)
6191da177e4SLinus Torvalds {
6201da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
6211da177e4SLinus Torvalds 	struct hci_conn  *c;
6221da177e4SLinus Torvalds 
623bf4c6325SGustavo F. Padovan 	rcu_read_lock();
624bf4c6325SGustavo F. Padovan 
625bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
626bf4c6325SGustavo F. Padovan 		if (c->type == type && !bacmp(&c->dst, ba)) {
627bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
6281da177e4SLinus Torvalds 			return c;
6291da177e4SLinus Torvalds 		}
630bf4c6325SGustavo F. Padovan 	}
631bf4c6325SGustavo F. Padovan 
632bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
633bf4c6325SGustavo F. Padovan 
6341da177e4SLinus Torvalds 	return NULL;
6351da177e4SLinus Torvalds }
6361da177e4SLinus Torvalds 
6374c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
6384c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
6394c67bc74SMarcel Holtmann {
6404c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
6414c67bc74SMarcel Holtmann 	struct hci_conn  *c;
6424c67bc74SMarcel Holtmann 
643bf4c6325SGustavo F. Padovan 	rcu_read_lock();
644bf4c6325SGustavo F. Padovan 
645bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
646bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
647bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
6484c67bc74SMarcel Holtmann 			return c;
6494c67bc74SMarcel Holtmann 		}
650bf4c6325SGustavo F. Padovan 	}
651bf4c6325SGustavo F. Padovan 
652bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
653bf4c6325SGustavo F. Padovan 
6544c67bc74SMarcel Holtmann 	return NULL;
6554c67bc74SMarcel Holtmann }
6564c67bc74SMarcel Holtmann 
657bed71748SAndre Guedes void hci_disconnect(struct hci_conn *conn, __u8 reason);
6582dea632fSFrédéric Dalleau bool hci_setup_sync(struct hci_conn *conn, __u16 handle);
659e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
6601da177e4SLinus Torvalds 
6611da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
6621da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn);
6631da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
664a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
6651da177e4SLinus Torvalds 
66673d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
6679472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan);
6682c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
66942c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
67073d80debSLuiz Augusto von Dentz 
67104a6c589SAndre Guedes struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
67204a6c589SAndre Guedes 				u8 dst_type, u8 sec_level, u8 auth_type);
67304a6c589SAndre Guedes struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
67404a6c589SAndre Guedes 				 u8 sec_level, u8 auth_type);
67510c62ddcSFrédéric Dalleau struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
67610c62ddcSFrédéric Dalleau 				 __u16 setting);
677e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
678b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
6790684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
6801da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn);
6818c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
6821da177e4SLinus Torvalds 
68314b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
6841da177e4SLinus Torvalds 
68506c053fbSAndre Guedes void hci_le_conn_failed(struct hci_conn *conn, u8 status);
68606c053fbSAndre Guedes 
6878d12356fSDavid Herrmann /*
6888d12356fSDavid Herrmann  * hci_conn_get() and hci_conn_put() are used to control the life-time of an
6898d12356fSDavid Herrmann  * "hci_conn" object. They do not guarantee that the hci_conn object is running,
6908d12356fSDavid Herrmann  * working or anything else. They just guarantee that the object is available
6918d12356fSDavid Herrmann  * and can be dereferenced. So you can use its locks, local variables and any
6928d12356fSDavid Herrmann  * other constant data.
6938d12356fSDavid Herrmann  * Before accessing runtime data, you _must_ lock the object and then check that
6948d12356fSDavid Herrmann  * it is still running. As soon as you release the locks, the connection might
6958d12356fSDavid Herrmann  * get dropped, though.
6968d12356fSDavid Herrmann  *
6978d12356fSDavid Herrmann  * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control
6988d12356fSDavid Herrmann  * how long the underlying connection is held. So every channel that runs on the
6998d12356fSDavid Herrmann  * hci_conn object calls this to prevent the connection from disappearing. As
7008d12356fSDavid Herrmann  * long as you hold a device, you must also guarantee that you have a valid
7018d12356fSDavid Herrmann  * reference to the device via hci_conn_get() (or the initial reference from
7028d12356fSDavid Herrmann  * hci_conn_add()).
7038d12356fSDavid Herrmann  * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't
7048d12356fSDavid Herrmann  * break because nobody cares for that. But this means, we cannot use
7058d12356fSDavid Herrmann  * _get()/_drop() in it, but require the caller to have a valid ref (FIXME).
7068d12356fSDavid Herrmann  */
7078d12356fSDavid Herrmann 
7088d12356fSDavid Herrmann static inline void hci_conn_get(struct hci_conn *conn)
7098d12356fSDavid Herrmann {
7108d12356fSDavid Herrmann 	get_device(&conn->dev);
7118d12356fSDavid Herrmann }
7128d12356fSDavid Herrmann 
7138d12356fSDavid Herrmann static inline void hci_conn_put(struct hci_conn *conn)
7148d12356fSDavid Herrmann {
7158d12356fSDavid Herrmann 	put_device(&conn->dev);
7168d12356fSDavid Herrmann }
7178d12356fSDavid Herrmann 
7181da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn)
7191da177e4SLinus Torvalds {
72071becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
72138b3fef1SAndrei Emeltchenko 
7221da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
7232f304d1eSAndre Guedes 	cancel_delayed_work(&conn->disc_work);
7241da177e4SLinus Torvalds }
7251da177e4SLinus Torvalds 
72676a68ba0SDavid Herrmann static inline void hci_conn_drop(struct hci_conn *conn)
7271da177e4SLinus Torvalds {
72871becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
72938b3fef1SAndrei Emeltchenko 
7301da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
73104837f64SMarcel Holtmann 		unsigned long timeo;
732716e4ab5SAndrei Emeltchenko 
733716e4ab5SAndrei Emeltchenko 		switch (conn->type) {
734716e4ab5SAndrei Emeltchenko 		case ACL_LINK:
735716e4ab5SAndrei Emeltchenko 		case LE_LINK:
736a74a84f6SJohan Hedberg 			cancel_delayed_work(&conn->idle_work);
7376ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
7385f246e89SAndrei Emeltchenko 				timeo = conn->disc_timeout;
73904837f64SMarcel Holtmann 				if (!conn->out)
740052b30b0SMarcel Holtmann 					timeo *= 2;
7415a9d0a3fSWaldemar Rymarkiewicz 			} else {
7426ac59344SMarcel Holtmann 				timeo = msecs_to_jiffies(10);
7435a9d0a3fSWaldemar Rymarkiewicz 			}
744716e4ab5SAndrei Emeltchenko 			break;
745716e4ab5SAndrei Emeltchenko 
746716e4ab5SAndrei Emeltchenko 		case AMP_LINK:
747716e4ab5SAndrei Emeltchenko 			timeo = conn->disc_timeout;
748716e4ab5SAndrei Emeltchenko 			break;
749716e4ab5SAndrei Emeltchenko 
750716e4ab5SAndrei Emeltchenko 		default:
75104837f64SMarcel Holtmann 			timeo = msecs_to_jiffies(10);
752716e4ab5SAndrei Emeltchenko 			break;
7535a9d0a3fSWaldemar Rymarkiewicz 		}
754716e4ab5SAndrei Emeltchenko 
7552f304d1eSAndre Guedes 		cancel_delayed_work(&conn->disc_work);
75619c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
7571931782bSVinicius Costa Gomes 				   &conn->disc_work, timeo);
7581da177e4SLinus Torvalds 	}
7591da177e4SLinus Torvalds }
7601da177e4SLinus Torvalds 
7611da177e4SLinus Torvalds /* ----- HCI Devices ----- */
762dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
7631da177e4SLinus Torvalds {
764376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
765376261aeSAndrei Emeltchenko 	       atomic_read(&d->dev.kobj.kref.refcount));
766376261aeSAndrei Emeltchenko 
7674c724c71SDavid Herrmann 	put_device(&d->dev);
768010666a1SDavid Herrmann }
7691da177e4SLinus Torvalds 
770dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
7711da177e4SLinus Torvalds {
772376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
773376261aeSAndrei Emeltchenko 	       atomic_read(&d->dev.kobj.kref.refcount));
774376261aeSAndrei Emeltchenko 
7754c724c71SDavid Herrmann 	get_device(&d->dev);
7761da177e4SLinus Torvalds 	return d;
7771da177e4SLinus Torvalds }
7781da177e4SLinus Torvalds 
77909fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
78009fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
7811da177e4SLinus Torvalds 
782aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev)
7833dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev)
784aa2b86d7SDavid Herrmann 
785155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev)
786155961e8SDavid Herrmann {
787155961e8SDavid Herrmann 	return dev_get_drvdata(&hdev->dev);
788155961e8SDavid Herrmann }
789155961e8SDavid Herrmann 
790155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
791155961e8SDavid Herrmann {
792155961e8SDavid Herrmann 	dev_set_drvdata(&hdev->dev, data);
793155961e8SDavid Herrmann }
794155961e8SDavid Herrmann 
7951da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
7960c0afedfSJohan Hedberg struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src);
7971da177e4SLinus Torvalds 
7981da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void);
7991da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
8001da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
80159735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
8021da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
8031da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
8041da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
8051da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
8061da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
8071da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
8081da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
8091da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
8101da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
8111da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
8121da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
81340be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
8141da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
8151da177e4SLinus Torvalds 
816c3c7ea65SGustavo Padovan struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
817b9ee0a78SMarcel Holtmann 					 bdaddr_t *bdaddr, u8 type);
81888c1fe4bSJohan Hedberg int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
81988c1fe4bSJohan Hedberg int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
820f0358568SJohan Hedberg 
821d2ab0ac1SMarcel Holtmann struct bdaddr_list *hci_white_list_lookup(struct hci_dev *hdev,
822d2ab0ac1SMarcel Holtmann 					  bdaddr_t *bdaddr, u8 type);
823d2ab0ac1SMarcel Holtmann void hci_white_list_clear(struct hci_dev *hdev);
824d2ab0ac1SMarcel Holtmann int hci_white_list_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
825d2ab0ac1SMarcel Holtmann int hci_white_list_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
826d2ab0ac1SMarcel Holtmann 
82715819a70SAndre Guedes struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
82815819a70SAndre Guedes 					       bdaddr_t *addr, u8 addr_type);
829a9b0a04cSAndre Guedes int hci_conn_params_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type,
8309fcb18efSAndre Guedes 			u8 auto_connect, u16 conn_min_interval,
8319fcb18efSAndre Guedes 			u16 conn_max_interval);
83215819a70SAndre Guedes void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
83315819a70SAndre Guedes void hci_conn_params_clear(struct hci_dev *hdev);
83415819a70SAndre Guedes 
83577a77a30SAndre Guedes struct bdaddr_list *hci_pend_le_conn_lookup(struct hci_dev *hdev,
83677a77a30SAndre Guedes 					    bdaddr_t *addr, u8 addr_type);
83777a77a30SAndre Guedes void hci_pend_le_conn_add(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
83877a77a30SAndre Guedes void hci_pend_le_conn_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type);
83977a77a30SAndre Guedes void hci_pend_le_conns_clear(struct hci_dev *hdev);
84077a77a30SAndre Guedes 
841a4790dbdSAndre Guedes void hci_update_background_scan(struct hci_dev *hdev);
842a4790dbdSAndre Guedes 
84335f7498aSJohan Hedberg void hci_uuids_clear(struct hci_dev *hdev);
8442aeb9a1aSJohan Hedberg 
84535f7498aSJohan Hedberg void hci_link_keys_clear(struct hci_dev *hdev);
84655ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
847d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
848d25e28abSJohan Hedberg 		     bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
849fe39c7b2SMarcel Holtmann struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, __le64 rand,
85098a0b845SJohan Hedberg 			     bool master);
851ca9142b8SJohan Hedberg struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
85235d70271SJohan Hedberg 			    u8 addr_type, u8 type, u8 authenticated,
853fe39c7b2SMarcel Holtmann 			    u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand);
854c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
85598a0b845SJohan Hedberg 				     u8 addr_type, bool master);
856e0b2b27eSJohan Hedberg int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type);
85735f7498aSJohan Hedberg void hci_smp_ltks_clear(struct hci_dev *hdev);
85855ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
85955ed8ca1SJohan Hedberg 
860970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa);
861970c4e46SJohan Hedberg struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
862970c4e46SJohan Hedberg 				     u8 addr_type);
863ca9142b8SJohan Hedberg struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
864ca9142b8SJohan Hedberg 			    u8 addr_type, u8 val[16], bdaddr_t *rpa);
865a7ec7338SJohan Hedberg void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type);
866970c4e46SJohan Hedberg void hci_smp_irks_clear(struct hci_dev *hdev);
867970c4e46SJohan Hedberg 
86835f7498aSJohan Hedberg void hci_remote_oob_data_clear(struct hci_dev *hdev);
8692763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
8702763eda6SSzymon Janc 					  bdaddr_t *bdaddr);
8710798872eSMarcel Holtmann int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
8720798872eSMarcel Holtmann 			    u8 *hash, u8 *randomizer);
8730798872eSMarcel Holtmann int hci_add_remote_oob_ext_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
8740798872eSMarcel Holtmann 				u8 *hash192, u8 *randomizer192,
8750798872eSMarcel Holtmann 				u8 *hash256, u8 *randomizer256);
8762763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
8772763eda6SSzymon Janc 
8781da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
8791da177e4SLinus Torvalds 
880e1a26170SMarcel Holtmann int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb);
881ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
88299811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
883ef222013SMarcel Holtmann 
8840ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
885a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
886b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
887b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
8881da177e4SLinus Torvalds 
8896935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
8901da177e4SLinus Torvalds 
8911da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
892cad718edSJohan Hedberg #define lmp_encrypt_capable(dev)   ((dev)->features[0][0] & LMP_ENCRYPT)
893cad718edSJohan Hedberg #define lmp_rswitch_capable(dev)   ((dev)->features[0][0] & LMP_RSWITCH)
894cad718edSJohan Hedberg #define lmp_hold_capable(dev)      ((dev)->features[0][0] & LMP_HOLD)
895cad718edSJohan Hedberg #define lmp_sniff_capable(dev)     ((dev)->features[0][0] & LMP_SNIFF)
896cad718edSJohan Hedberg #define lmp_park_capable(dev)      ((dev)->features[0][1] & LMP_PARK)
897cad718edSJohan Hedberg #define lmp_inq_rssi_capable(dev)  ((dev)->features[0][3] & LMP_RSSI_INQ)
898cad718edSJohan Hedberg #define lmp_esco_capable(dev)      ((dev)->features[0][3] & LMP_ESCO)
899cad718edSJohan Hedberg #define lmp_bredr_capable(dev)     (!((dev)->features[0][4] & LMP_NO_BREDR))
900cad718edSJohan Hedberg #define lmp_le_capable(dev)        ((dev)->features[0][4] & LMP_LE)
901cad718edSJohan Hedberg #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR)
902cad718edSJohan Hedberg #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC)
903cad718edSJohan Hedberg #define lmp_ext_inq_capable(dev)   ((dev)->features[0][6] & LMP_EXT_INQ)
904cad718edSJohan Hedberg #define lmp_le_br_capable(dev)     (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR))
905cad718edSJohan Hedberg #define lmp_ssp_capable(dev)       ((dev)->features[0][6] & LMP_SIMPLE_PAIR)
906cad718edSJohan Hedberg #define lmp_no_flush_capable(dev)  ((dev)->features[0][6] & LMP_NO_FLUSH)
907cad718edSJohan Hedberg #define lmp_lsto_capable(dev)      ((dev)->features[0][7] & LMP_LSTO)
908cad718edSJohan Hedberg #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR)
909cad718edSJohan Hedberg #define lmp_ext_feat_capable(dev)  ((dev)->features[0][7] & LMP_EXTFEATURES)
91007a5c61eSFrédéric Dalleau #define lmp_transp_capable(dev)    ((dev)->features[0][2] & LMP_TRANSPARENT)
9111da177e4SLinus Torvalds 
912eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
91353b834d2SMarcel Holtmann #define lmp_csb_master_capable(dev) ((dev)->features[2][0] & LMP_CSB_MASTER)
91453b834d2SMarcel Holtmann #define lmp_csb_slave_capable(dev)  ((dev)->features[2][0] & LMP_CSB_SLAVE)
91553b834d2SMarcel Holtmann #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN)
91653b834d2SMarcel Holtmann #define lmp_sync_scan_capable(dev)  ((dev)->features[2][0] & LMP_SYNC_SCAN)
917d5991585SMarcel Holtmann #define lmp_sc_capable(dev)         ((dev)->features[2][1] & LMP_SC)
918d5991585SMarcel Holtmann #define lmp_ping_capable(dev)       ((dev)->features[2][1] & LMP_PING)
91953b834d2SMarcel Holtmann 
92053b834d2SMarcel Holtmann /* ----- Host capabilities ----- */
921cad718edSJohan Hedberg #define lmp_host_ssp_capable(dev)  ((dev)->features[1][0] & LMP_HOST_SSP)
922d5991585SMarcel Holtmann #define lmp_host_sc_capable(dev)   ((dev)->features[1][0] & LMP_HOST_SC)
923cad718edSJohan Hedberg #define lmp_host_le_capable(dev)   (!!((dev)->features[1][0] & LMP_HOST_LE))
924cad718edSJohan Hedberg #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR))
925eead27daSAndre Guedes 
9261da177e4SLinus Torvalds /* ----- HCI protocols ----- */
92720714bfeSFrédéric Dalleau #define HCI_PROTO_DEFER             0x01
92820714bfeSFrédéric Dalleau 
9295a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
93020714bfeSFrédéric Dalleau 					__u8 type, __u8 *flags)
9311da177e4SLinus Torvalds {
932686ebf28SUlisses Furquim 	switch (type) {
933686ebf28SUlisses Furquim 	case ACL_LINK:
934686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
9351da177e4SLinus Torvalds 
936686ebf28SUlisses Furquim 	case SCO_LINK:
937686ebf28SUlisses Furquim 	case ESCO_LINK:
93820714bfeSFrédéric Dalleau 		return sco_connect_ind(hdev, bdaddr, flags);
9391da177e4SLinus Torvalds 
940686ebf28SUlisses Furquim 	default:
941686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
942686ebf28SUlisses Furquim 		return -EINVAL;
943686ebf28SUlisses Furquim 	}
9441da177e4SLinus Torvalds }
9451da177e4SLinus Torvalds 
9461da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
9471da177e4SLinus Torvalds {
948686ebf28SUlisses Furquim 	switch (conn->type) {
949686ebf28SUlisses Furquim 	case ACL_LINK:
950686ebf28SUlisses Furquim 	case LE_LINK:
951686ebf28SUlisses Furquim 		l2cap_connect_cfm(conn, status);
952686ebf28SUlisses Furquim 		break;
9531da177e4SLinus Torvalds 
954686ebf28SUlisses Furquim 	case SCO_LINK:
955686ebf28SUlisses Furquim 	case ESCO_LINK:
956686ebf28SUlisses Furquim 		sco_connect_cfm(conn, status);
957686ebf28SUlisses Furquim 		break;
9581da177e4SLinus Torvalds 
959686ebf28SUlisses Furquim 	default:
960686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
961686ebf28SUlisses Furquim 		break;
962686ebf28SUlisses Furquim 	}
963e9a416b5SJohan Hedberg 
964e9a416b5SJohan Hedberg 	if (conn->connect_cfm_cb)
965e9a416b5SJohan Hedberg 		conn->connect_cfm_cb(conn, status);
9661da177e4SLinus Torvalds }
9671da177e4SLinus Torvalds 
9682950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
9692950f21aSMarcel Holtmann {
970686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
971686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
9722950f21aSMarcel Holtmann 
973686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
9742950f21aSMarcel Holtmann }
9752950f21aSMarcel Holtmann 
9762950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
9771da177e4SLinus Torvalds {
978686ebf28SUlisses Furquim 	switch (conn->type) {
979686ebf28SUlisses Furquim 	case ACL_LINK:
980686ebf28SUlisses Furquim 	case LE_LINK:
981686ebf28SUlisses Furquim 		l2cap_disconn_cfm(conn, reason);
982686ebf28SUlisses Furquim 		break;
9831da177e4SLinus Torvalds 
984686ebf28SUlisses Furquim 	case SCO_LINK:
985686ebf28SUlisses Furquim 	case ESCO_LINK:
986686ebf28SUlisses Furquim 		sco_disconn_cfm(conn, reason);
987686ebf28SUlisses Furquim 		break;
9881da177e4SLinus Torvalds 
989bd1eb66bSAndrei Emeltchenko 	/* L2CAP would be handled for BREDR chan */
990bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
991bd1eb66bSAndrei Emeltchenko 		break;
992bd1eb66bSAndrei Emeltchenko 
993686ebf28SUlisses Furquim 	default:
994686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
995686ebf28SUlisses Furquim 		break;
996686ebf28SUlisses Furquim 	}
997e9a416b5SJohan Hedberg 
998e9a416b5SJohan Hedberg 	if (conn->disconn_cfm_cb)
999e9a416b5SJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
10001da177e4SLinus Torvalds }
10011da177e4SLinus Torvalds 
10021da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
10031da177e4SLinus Torvalds {
10048c1b2355SMarcel Holtmann 	__u8 encrypt;
10058c1b2355SMarcel Holtmann 
1006686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
1007686ebf28SUlisses Furquim 		return;
1008686ebf28SUlisses Furquim 
100951a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
10108c1b2355SMarcel Holtmann 		return;
10118c1b2355SMarcel Holtmann 
10128c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
1013686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
1014e9a416b5SJohan Hedberg 
1015e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
1016e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
10171da177e4SLinus Torvalds }
10181da177e4SLinus Torvalds 
10195a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
10205a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
10211da177e4SLinus Torvalds {
1022686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
1023686ebf28SUlisses Furquim 		return;
10241da177e4SLinus Torvalds 
1025686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
1026e9a416b5SJohan Hedberg 
1027e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
1028e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
10291da177e4SLinus Torvalds }
10301da177e4SLinus Torvalds 
10311da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
10321da177e4SLinus Torvalds struct hci_cb {
10331da177e4SLinus Torvalds 	struct list_head list;
10341da177e4SLinus Torvalds 
10351da177e4SLinus Torvalds 	char *name;
10361da177e4SLinus Torvalds 
10375a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
10385a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
10391da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
10401da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
10411da177e4SLinus Torvalds };
10421da177e4SLinus Torvalds 
10431da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
10441da177e4SLinus Torvalds {
1045711584eaSDenis Kirjanov 	struct hci_cb *cb;
10468c1b2355SMarcel Holtmann 	__u8 encrypt;
10471da177e4SLinus Torvalds 
10481da177e4SLinus Torvalds 	hci_proto_auth_cfm(conn, status);
10491da177e4SLinus Torvalds 
105051a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
10518c1b2355SMarcel Holtmann 		return;
10528c1b2355SMarcel Holtmann 
10538c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
10548c1b2355SMarcel Holtmann 
1055f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
1056711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
10578c1b2355SMarcel Holtmann 		if (cb->security_cfm)
10588c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
10591da177e4SLinus Torvalds 	}
1060f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
10611da177e4SLinus Torvalds }
10621da177e4SLinus Torvalds 
10635a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
10645a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
10651da177e4SLinus Torvalds {
1066711584eaSDenis Kirjanov 	struct hci_cb *cb;
10671da177e4SLinus Torvalds 
1068435fef20SMarcel Holtmann 	if (conn->sec_level == BT_SECURITY_SDP)
1069435fef20SMarcel Holtmann 		conn->sec_level = BT_SECURITY_LOW;
1070435fef20SMarcel Holtmann 
107188167aedSVinicius Costa Gomes 	if (conn->pending_sec_level > conn->sec_level)
107288167aedSVinicius Costa Gomes 		conn->sec_level = conn->pending_sec_level;
107388167aedSVinicius Costa Gomes 
10749719f8afSMarcel Holtmann 	hci_proto_encrypt_cfm(conn, status, encrypt);
10751da177e4SLinus Torvalds 
1076f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
1077711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
10788c1b2355SMarcel Holtmann 		if (cb->security_cfm)
10798c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
10801da177e4SLinus Torvalds 	}
1081f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
10821da177e4SLinus Torvalds }
10831da177e4SLinus Torvalds 
10841da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
10851da177e4SLinus Torvalds {
1086711584eaSDenis Kirjanov 	struct hci_cb *cb;
10871da177e4SLinus Torvalds 
1088f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
1089711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
10901da177e4SLinus Torvalds 		if (cb->key_change_cfm)
10911da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
10921da177e4SLinus Torvalds 	}
1093f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
10941da177e4SLinus Torvalds }
10951da177e4SLinus Torvalds 
10965a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
10975a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
10981da177e4SLinus Torvalds {
1099711584eaSDenis Kirjanov 	struct hci_cb *cb;
11001da177e4SLinus Torvalds 
1101f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
1102711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
11031da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
11041da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
11051da177e4SLinus Torvalds 	}
1106f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
11071da177e4SLinus Torvalds }
11081da177e4SLinus Torvalds 
11096759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
11106759a675SJohan Hedberg {
111184d9d071SJohan Hedberg 	size_t parsed = 0;
11126759a675SJohan Hedberg 
11136c0c331eSJohan Hedberg 	if (data_len < 2)
11146c0c331eSJohan Hedberg 		return false;
11156c0c331eSJohan Hedberg 
111684d9d071SJohan Hedberg 	while (parsed < data_len - 1) {
111784d9d071SJohan Hedberg 		u8 field_len = data[0];
11186759a675SJohan Hedberg 
11196759a675SJohan Hedberg 		if (field_len == 0)
11206759a675SJohan Hedberg 			break;
11216759a675SJohan Hedberg 
11226759a675SJohan Hedberg 		parsed += field_len + 1;
11236759a675SJohan Hedberg 
11246759a675SJohan Hedberg 		if (parsed > data_len)
11256759a675SJohan Hedberg 			break;
11266759a675SJohan Hedberg 
11276759a675SJohan Hedberg 		if (data[1] == type)
11286759a675SJohan Hedberg 			return true;
11296759a675SJohan Hedberg 
11306759a675SJohan Hedberg 		data += field_len + 1;
11316759a675SJohan Hedberg 	}
11326759a675SJohan Hedberg 
11336759a675SJohan Hedberg 	return false;
11346759a675SJohan Hedberg }
11356759a675SJohan Hedberg 
1136301cb2d8SJohan Hedberg static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type)
1137301cb2d8SJohan Hedberg {
1138301cb2d8SJohan Hedberg 	if (addr_type != 0x01)
1139301cb2d8SJohan Hedberg 		return false;
1140301cb2d8SJohan Hedberg 
1141301cb2d8SJohan Hedberg 	if ((bdaddr->b[5] & 0xc0) == 0x40)
1142301cb2d8SJohan Hedberg 	       return true;
1143301cb2d8SJohan Hedberg 
1144301cb2d8SJohan Hedberg 	return false;
1145301cb2d8SJohan Hedberg }
1146301cb2d8SJohan Hedberg 
11472426f3a5SJohan Hedberg static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev,
11482426f3a5SJohan Hedberg 					  bdaddr_t *bdaddr, u8 addr_type)
11492426f3a5SJohan Hedberg {
11502426f3a5SJohan Hedberg 	if (!hci_bdaddr_is_rpa(bdaddr, addr_type))
11512426f3a5SJohan Hedberg 		return NULL;
11522426f3a5SJohan Hedberg 
11532426f3a5SJohan Hedberg 	return hci_find_irk_by_rpa(hdev, bdaddr);
11542426f3a5SJohan Hedberg }
11552426f3a5SJohan Hedberg 
11561da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
11571da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
11581da177e4SLinus Torvalds 
11593119ae95SJohan Hedberg struct hci_request {
11603119ae95SJohan Hedberg 	struct hci_dev		*hdev;
11613119ae95SJohan Hedberg 	struct sk_buff_head	cmd_q;
11625d73e034SAndre Guedes 
11635d73e034SAndre Guedes 	/* If something goes wrong when building the HCI request, the error
11645d73e034SAndre Guedes 	 * value is stored in this field.
11655d73e034SAndre Guedes 	 */
11665d73e034SAndre Guedes 	int			err;
11673119ae95SJohan Hedberg };
11683119ae95SJohan Hedberg 
11693119ae95SJohan Hedberg void hci_req_init(struct hci_request *req, struct hci_dev *hdev);
11703119ae95SJohan Hedberg int hci_req_run(struct hci_request *req, hci_req_complete_t complete);
117107dc93ddSJohan Hedberg void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
117207dc93ddSJohan Hedberg 		 const void *param);
117307dc93ddSJohan Hedberg void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
117407dc93ddSJohan Hedberg 		    const void *param, u8 event);
11759238f36aSJohan Hedberg void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status);
11763119ae95SJohan Hedberg 
1177b1efcc28SAndre Guedes void hci_req_add_le_scan_disable(struct hci_request *req);
11788ef30fd3SAndre Guedes void hci_req_add_le_passive_scan(struct hci_request *req);
1179b1efcc28SAndre Guedes 
118075e84b7cSJohan Hedberg struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
118107dc93ddSJohan Hedberg 			       const void *param, u32 timeout);
11827b1abbbeSJohan Hedberg struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
118307dc93ddSJohan Hedberg 				  const void *param, u8 event, u32 timeout);
118475e84b7cSJohan Hedberg 
118507dc93ddSJohan Hedberg int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
118607dc93ddSJohan Hedberg 		 const void *param);
118773d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
11880d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
11891da177e4SLinus Torvalds 
1190a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
11911da177e4SLinus Torvalds 
11921da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
1193470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
1194470fe1b5SMarcel Holtmann void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk);
1195cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
11961da177e4SLinus Torvalds 
1197040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event);
1198040030efSMarcel Holtmann 
11990381101fSJohan Hedberg /* Management interface */
1200591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR		(BIT(BDADDR_BREDR))
1201591f47f3SAndre Guedes #define DISCOV_TYPE_LE			(BIT(BDADDR_LE_PUBLIC) | \
1202591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
1203591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED		(BIT(BDADDR_BREDR) | \
1204591f47f3SAndre Guedes 					 BIT(BDADDR_LE_PUBLIC) | \
1205591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
1206f39799f5SAndre Guedes 
12070d8cc935SAndre Guedes /* These LE scan and inquiry parameters were chosen according to LE General
12080d8cc935SAndre Guedes  * Discovery Procedure specification.
12090d8cc935SAndre Guedes  */
12100d8cc935SAndre Guedes #define DISCOV_LE_SCAN_WIN		0x12
12110d8cc935SAndre Guedes #define DISCOV_LE_SCAN_INT		0x12
12120d8cc935SAndre Guedes #define DISCOV_LE_TIMEOUT		msecs_to_jiffies(10240)
1213ae55f598SLukasz Rymanowski #define DISCOV_INTERLEAVED_TIMEOUT	5120	/* msec */
12140d8cc935SAndre Guedes #define DISCOV_INTERLEAVED_INQUIRY_LEN	0x04
12150d8cc935SAndre Guedes #define DISCOV_BREDR_INQUIRY_LEN	0x08
12160d8cc935SAndre Guedes 
12170381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
1218bf6b56dbSMarcel Holtmann void mgmt_index_added(struct hci_dev *hdev);
1219bf6b56dbSMarcel Holtmann void mgmt_index_removed(struct hci_dev *hdev);
12203eec705eSMarcel Holtmann void mgmt_set_powered_failed(struct hci_dev *hdev, int err);
1221744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered);
1222d1967ff8SMarcel Holtmann void mgmt_discoverable_timeout(struct hci_dev *hdev);
122386a75645SMarcel Holtmann void mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
1224a330916cSMarcel Holtmann void mgmt_connectable(struct hci_dev *hdev, u8 connectable);
1225778b235aSJohan Hedberg void mgmt_advertising(struct hci_dev *hdev, u8 advertising);
12264796e8afSMarcel Holtmann void mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
1227dc4a5ee2SMarcel Holtmann void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
1228745c0ce3SVishal Agarwal 		       bool persistent);
1229ecd90ae7SMarcel Holtmann void mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
123004124681SGustavo F. Padovan 			   u8 addr_type, u32 flags, u8 *name, u8 name_len,
123104124681SGustavo F. Padovan 			   u8 *dev_class);
12329b80ec5eSMarcel Holtmann void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
123312d4a3b2SJohan Hedberg 			      u8 link_type, u8 addr_type, u8 reason,
123412d4a3b2SJohan Hedberg 			      bool mgmt_connected);
12357892924cSMarcel Holtmann void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
123688c3df13SJohan Hedberg 			    u8 link_type, u8 addr_type, u8 status);
1237445608d0SMarcel Holtmann void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
123848264f06SJohan Hedberg 			 u8 addr_type, u8 status);
1239ce0e4a0dSMarcel Holtmann void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
1240e669cf80SMarcel Holtmann void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1241c35938b2SSzymon Janc 				  u8 status);
12423eb38528SMarcel Holtmann void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1243744cf19eSJohan Hedberg 				      u8 status);
1244744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
124539adbffeSJohan Hedberg 			      u8 link_type, u8 addr_type, u32 value,
1246272d90dfSJohan Hedberg 			      u8 confirm_hint);
1247744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1248272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
1249272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1250272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
1251272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
1252272d90dfSJohan Hedberg 			      u8 link_type, u8 addr_type);
1253604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1254272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
1255272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1256272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
125792a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
125892a25256SJohan Hedberg 			     u8 link_type, u8 addr_type, u32 passkey,
125992a25256SJohan Hedberg 			     u8 entered);
1260e546099cSMarcel Holtmann void mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1261bab73cb6SJohan Hedberg 		      u8 addr_type, u8 status);
1262464996aeSMarcel Holtmann void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
12633e248560SMarcel Holtmann void mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
1264eac83dc6SMarcel Holtmann void mgmt_sc_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
12654e1b0245SMarcel Holtmann void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
12667f9a903cSMarcel Holtmann 				    u8 status);
12677667da34SMarcel Holtmann void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
12684d2d2796SMarcel Holtmann void mgmt_read_local_oob_data_complete(struct hci_dev *hdev, u8 *hash192,
12694d2d2796SMarcel Holtmann 				       u8 *randomizer192, u8 *hash256,
12704d2d2796SMarcel Holtmann 				       u8 *randomizer256, u8 status);
1271901801b9SMarcel Holtmann void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
127273cf71d9SJohan Hedberg 		       u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
127373cf71d9SJohan Hedberg 		       u8 ssp, u8 *eir, u16 eir_len, u8 *scan_rsp,
12745d2e9fadSJohan Hedberg 		       u8 scan_rsp_len);
12759cf12aeeSMarcel Holtmann void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1276b644ba33SJohan Hedberg 		      u8 addr_type, s8 rssi, u8 *name, u8 name_len);
12772f1e063bSMarcel Holtmann void mgmt_discovering(struct hci_dev *hdev, u8 discovering);
127888c1fe4bSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
127988c1fe4bSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
128053ac6ab6SMarcel Holtmann void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent);
128195fbac8aSJohan Hedberg void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk);
128253ac6ab6SMarcel Holtmann void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk,
128353ac6ab6SMarcel Holtmann 		   bool persistent);
12845976e608SMarcel Holtmann void mgmt_reenable_advertising(struct hci_dev *hdev);
1285f4a407beSJohan Hedberg void mgmt_smp_complete(struct hci_conn *conn, bool complete);
1286346af67bSVinicius Costa Gomes 
12871da177e4SLinus Torvalds /* HCI info for socket */
12881da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk)
12891da177e4SLinus Torvalds 
12901da177e4SLinus Torvalds struct hci_pinfo {
12911da177e4SLinus Torvalds 	struct bt_sock    bt;
12921da177e4SLinus Torvalds 	struct hci_dev    *hdev;
12931da177e4SLinus Torvalds 	struct hci_filter filter;
12941da177e4SLinus Torvalds 	__u32             cmsg_mask;
1295c02178d2SJohan Hedberg 	unsigned short   channel;
12961da177e4SLinus Torvalds };
12971da177e4SLinus Torvalds 
12981da177e4SLinus Torvalds /* HCI security filter */
12991da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF  5
13001da177e4SLinus Torvalds 
13011da177e4SLinus Torvalds struct hci_sec_filter {
13021da177e4SLinus Torvalds 	__u32 type_mask;
13031da177e4SLinus Torvalds 	__u32 event_mask[2];
13041da177e4SLinus Torvalds 	__u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
13051da177e4SLinus Torvalds };
13061da177e4SLinus Torvalds 
13071da177e4SLinus Torvalds /* ----- HCI requests ----- */
13081da177e4SLinus Torvalds #define HCI_REQ_DONE	  0
13091da177e4SLinus Torvalds #define HCI_REQ_PEND	  1
13101da177e4SLinus Torvalds #define HCI_REQ_CANCELED  2
13111da177e4SLinus Torvalds 
1312a6a67efdSThomas Gleixner #define hci_req_lock(d)		mutex_lock(&d->req_lock)
1313a6a67efdSThomas Gleixner #define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
13141da177e4SLinus Torvalds 
13152ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
13162ce603ebSClaudio Takahasi 					u16 latency, u16 to_multiplier);
1317fe39c7b2SMarcel Holtmann void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand,
1318a7a595f6SVinicius Costa Gomes 							__u8 ltk[16]);
13192519a1fcSAndre Guedes 
132094b1fc92SMarcel Holtmann int hci_update_random_address(struct hci_request *req, bool require_privacy,
132194b1fc92SMarcel Holtmann 			      u8 *own_addr_type);
1322a1f4c318SJohan Hedberg void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
1323a1f4c318SJohan Hedberg 			       u8 *bdaddr_type);
1324ebd3a747SJohan Hedberg 
13255d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_MASK       0x0003
13265d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_CVSD       0x0000
13275d4d62f6SFrédéric Dalleau #define SCO_AIRMODE_TRANSP     0x0003
13285d4d62f6SFrédéric Dalleau 
13291da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
1330