xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision 711584ea)
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;
711da177e4SLinus Torvalds };
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds struct hci_conn_hash {
741da177e4SLinus Torvalds 	struct list_head list;
751da177e4SLinus Torvalds 	unsigned int     acl_num;
76bd1eb66bSAndrei Emeltchenko 	unsigned int     amp_num;
771da177e4SLinus Torvalds 	unsigned int     sco_num;
78fcd89c09SVille Tervo 	unsigned int     le_num;
791da177e4SLinus Torvalds };
801da177e4SLinus Torvalds 
81f0358568SJohan Hedberg struct bdaddr_list {
82f0358568SJohan Hedberg 	struct list_head list;
83f0358568SJohan Hedberg 	bdaddr_t bdaddr;
84f0358568SJohan Hedberg };
852aeb9a1aSJohan Hedberg 
862aeb9a1aSJohan Hedberg struct bt_uuid {
872aeb9a1aSJohan Hedberg 	struct list_head list;
882aeb9a1aSJohan Hedberg 	u8 uuid[16];
891aff6f09SJohan Hedberg 	u8 svc_hint;
902aeb9a1aSJohan Hedberg };
912aeb9a1aSJohan Hedberg 
92b899efafSVinicius Costa Gomes struct smp_ltk {
93b899efafSVinicius Costa Gomes 	struct list_head list;
94b899efafSVinicius Costa Gomes 	bdaddr_t bdaddr;
95b899efafSVinicius Costa Gomes 	u8 bdaddr_type;
96b899efafSVinicius Costa Gomes 	u8 authenticated;
97b899efafSVinicius Costa Gomes 	u8 type;
98b899efafSVinicius Costa Gomes 	u8 enc_size;
99b899efafSVinicius Costa Gomes 	__le16 ediv;
100b899efafSVinicius Costa Gomes 	u8 rand[8];
101b899efafSVinicius Costa Gomes 	u8 val[16];
102b899efafSVinicius Costa Gomes } __packed;
103b899efafSVinicius Costa Gomes 
10455ed8ca1SJohan Hedberg struct link_key {
10555ed8ca1SJohan Hedberg 	struct list_head list;
10655ed8ca1SJohan Hedberg 	bdaddr_t bdaddr;
10755ed8ca1SJohan Hedberg 	u8 type;
1089b3b4460SAndrei Emeltchenko 	u8 val[HCI_LINK_KEY_SIZE];
10955ed8ca1SJohan Hedberg 	u8 pin_len;
11055ed8ca1SJohan Hedberg };
11155ed8ca1SJohan Hedberg 
1122763eda6SSzymon Janc struct oob_data {
1132763eda6SSzymon Janc 	struct list_head list;
1142763eda6SSzymon Janc 	bdaddr_t bdaddr;
1152763eda6SSzymon Janc 	u8 hash[16];
1162763eda6SSzymon Janc 	u8 randomizer[16];
1172763eda6SSzymon Janc };
1182763eda6SSzymon Janc 
1197ba8b4beSAndre Guedes struct le_scan_params {
1207ba8b4beSAndre Guedes 	u8 type;
1217ba8b4beSAndre Guedes 	u16 interval;
1227ba8b4beSAndre Guedes 	u16 window;
12328b75a89SAndre Guedes 	int timeout;
1247ba8b4beSAndre Guedes };
1257ba8b4beSAndre Guedes 
126490c5babSJohan Hedberg #define HCI_MAX_SHORT_NAME_LENGTH	10
127490c5babSJohan Hedberg 
128903e4541SAndrei Emeltchenko struct amp_assoc {
129903e4541SAndrei Emeltchenko 	__u16	len;
130903e4541SAndrei Emeltchenko 	__u16	offset;
13193c284eeSAndrei Emeltchenko 	__u16	rem_len;
13293c284eeSAndrei Emeltchenko 	__u16	len_so_far;
133903e4541SAndrei Emeltchenko 	__u8	data[HCI_MAX_AMP_ASSOC_SIZE];
134903e4541SAndrei Emeltchenko };
135903e4541SAndrei Emeltchenko 
136cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4
1371da177e4SLinus Torvalds struct hci_dev {
1381da177e4SLinus Torvalds 	struct list_head list;
13909fd0de5SGustavo F. Padovan 	struct mutex	lock;
1401da177e4SLinus Torvalds 
1411da177e4SLinus Torvalds 	char		name[8];
1421da177e4SLinus Torvalds 	unsigned long	flags;
1431da177e4SLinus Torvalds 	__u16		id;
144c13854ceSMarcel Holtmann 	__u8		bus;
145943da25dSMarcel Holtmann 	__u8		dev_type;
1461da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
1471f6c6378SJohan Hedberg 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
148490c5babSJohan Hedberg 	__u8		short_name[HCI_MAX_SHORT_NAME_LENGTH];
14980a1e1dbSJohan Hedberg 	__u8		eir[HCI_MAX_EIR_LENGTH];
150a9de9248SMarcel Holtmann 	__u8		dev_class[3];
1511aff6f09SJohan Hedberg 	__u8		major_class;
1521aff6f09SJohan Hedberg 	__u8		minor_class;
1531da177e4SLinus Torvalds 	__u8		features[8];
15459e29406SAndre Guedes 	__u8		host_features[8];
155a9de9248SMarcel Holtmann 	__u8		commands[64];
1561143e5a6SMarcel Holtmann 	__u8		hci_ver;
1571143e5a6SMarcel Holtmann 	__u16		hci_rev;
158d5859e22SJohan Hedberg 	__u8		lmp_ver;
1591143e5a6SMarcel Holtmann 	__u16		manufacturer;
1607d69230cSAndrei Emeltchenko 	__u16		lmp_subver;
1611da177e4SLinus Torvalds 	__u16		voice_setting;
16217fa4b9dSJohan Hedberg 	__u8		io_capability;
16391c4e9b1SMarcel Holtmann 	__s8		inq_tx_power;
1642b9be137SMarcel Holtmann 	__u16		devid_source;
1652b9be137SMarcel Holtmann 	__u16		devid_vendor;
1662b9be137SMarcel Holtmann 	__u16		devid_product;
1672b9be137SMarcel Holtmann 	__u16		devid_version;
1681da177e4SLinus Torvalds 
1691da177e4SLinus Torvalds 	__u16		pkt_type;
1705b7f9909SMarcel Holtmann 	__u16		esco_type;
1711da177e4SLinus Torvalds 	__u16		link_policy;
1721da177e4SLinus Torvalds 	__u16		link_mode;
1731da177e4SLinus Torvalds 
17404837f64SMarcel Holtmann 	__u32		idle_timeout;
17504837f64SMarcel Holtmann 	__u16		sniff_min_interval;
17604837f64SMarcel Holtmann 	__u16		sniff_max_interval;
17704837f64SMarcel Holtmann 
178928abaa7SAndrei Emeltchenko 	__u8		amp_status;
179928abaa7SAndrei Emeltchenko 	__u32		amp_total_bw;
180928abaa7SAndrei Emeltchenko 	__u32		amp_max_bw;
181928abaa7SAndrei Emeltchenko 	__u32		amp_min_latency;
182928abaa7SAndrei Emeltchenko 	__u32		amp_max_pdu;
183928abaa7SAndrei Emeltchenko 	__u8		amp_type;
184928abaa7SAndrei Emeltchenko 	__u16		amp_pal_cap;
185928abaa7SAndrei Emeltchenko 	__u16		amp_assoc_size;
186928abaa7SAndrei Emeltchenko 	__u32		amp_max_flush_to;
187928abaa7SAndrei Emeltchenko 	__u32		amp_be_flush_to;
188928abaa7SAndrei Emeltchenko 
189903e4541SAndrei Emeltchenko 	struct amp_assoc	loc_assoc;
190903e4541SAndrei Emeltchenko 
1911e89cffbSAndrei Emeltchenko 	__u8		flow_ctl_mode;
1921e89cffbSAndrei Emeltchenko 
1939f61656aSJohan Hedberg 	unsigned int	auto_accept_delay;
1949f61656aSJohan Hedberg 
1951da177e4SLinus Torvalds 	unsigned long	quirks;
1961da177e4SLinus Torvalds 
1971da177e4SLinus Torvalds 	atomic_t	cmd_cnt;
1981da177e4SLinus Torvalds 	unsigned int	acl_cnt;
1991da177e4SLinus Torvalds 	unsigned int	sco_cnt;
2006ed58ec5SVille Tervo 	unsigned int	le_cnt;
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds 	unsigned int	acl_mtu;
2031da177e4SLinus Torvalds 	unsigned int	sco_mtu;
2046ed58ec5SVille Tervo 	unsigned int	le_mtu;
2051da177e4SLinus Torvalds 	unsigned int	acl_pkts;
2061da177e4SLinus Torvalds 	unsigned int	sco_pkts;
2076ed58ec5SVille Tervo 	unsigned int	le_pkts;
2081da177e4SLinus Torvalds 
209350ee4cfSAndrei Emeltchenko 	__u16		block_len;
210350ee4cfSAndrei Emeltchenko 	__u16		block_mtu;
211350ee4cfSAndrei Emeltchenko 	__u16		num_blocks;
212350ee4cfSAndrei Emeltchenko 	__u16		block_cnt;
213350ee4cfSAndrei Emeltchenko 
2141da177e4SLinus Torvalds 	unsigned long	acl_last_tx;
2151da177e4SLinus Torvalds 	unsigned long	sco_last_tx;
2166ed58ec5SVille Tervo 	unsigned long	le_last_tx;
2171da177e4SLinus Torvalds 
218f48fd9c8SMarcel Holtmann 	struct workqueue_struct	*workqueue;
219f48fd9c8SMarcel Holtmann 
220ab81cbf9SJohan Hedberg 	struct work_struct	power_on;
2213243553fSJohan Hedberg 	struct delayed_work	power_off;
222ab81cbf9SJohan Hedberg 
22316ab91abSJohan Hedberg 	__u16			discov_timeout;
22416ab91abSJohan Hedberg 	struct delayed_work	discov_off;
22516ab91abSJohan Hedberg 
2267d78525dSJohan Hedberg 	struct delayed_work	service_cache;
2277d78525dSJohan Hedberg 
2286bd32326SVille Tervo 	struct timer_list	cmd_timer;
229b78752ccSMarcel Holtmann 
230b78752ccSMarcel Holtmann 	struct work_struct	rx_work;
231c347b765SGustavo F. Padovan 	struct work_struct	cmd_work;
2323eff45eaSGustavo F. Padovan 	struct work_struct	tx_work;
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds 	struct sk_buff_head	rx_q;
2351da177e4SLinus Torvalds 	struct sk_buff_head	raw_q;
2361da177e4SLinus Torvalds 	struct sk_buff_head	cmd_q;
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds 	struct sk_buff		*sent_cmd;
239cd4c5391SSuraj Sumangala 	struct sk_buff		*reassembly[NUM_REASSEMBLY];
2401da177e4SLinus Torvalds 
241a6a67efdSThomas Gleixner 	struct mutex		req_lock;
2421da177e4SLinus Torvalds 	wait_queue_head_t	req_wait_q;
2431da177e4SLinus Torvalds 	__u32			req_status;
2441da177e4SLinus Torvalds 	__u32			req_result;
245a5040efaSJohan Hedberg 
246a5040efaSJohan Hedberg 	__u16			init_last_cmd;
2471da177e4SLinus Torvalds 
2482e58ef3eSJohan Hedberg 	struct list_head	mgmt_pending;
2492e58ef3eSJohan Hedberg 
25030883512SJohan Hedberg 	struct discovery_state	discovery;
2511da177e4SLinus Torvalds 	struct hci_conn_hash	conn_hash;
252ea4bd8baSDavid Miller 	struct list_head	blacklist;
2531da177e4SLinus Torvalds 
2542aeb9a1aSJohan Hedberg 	struct list_head	uuids;
2552aeb9a1aSJohan Hedberg 
25655ed8ca1SJohan Hedberg 	struct list_head	link_keys;
25755ed8ca1SJohan Hedberg 
258b899efafSVinicius Costa Gomes 	struct list_head	long_term_keys;
259b899efafSVinicius Costa Gomes 
2602763eda6SSzymon Janc 	struct list_head	remote_oob_data;
2612763eda6SSzymon Janc 
2621da177e4SLinus Torvalds 	struct hci_dev_stats	stat;
2631da177e4SLinus Torvalds 
2641da177e4SLinus Torvalds 	struct sk_buff_head	driver_init;
2651da177e4SLinus Torvalds 
2661da177e4SLinus Torvalds 	atomic_t		promisc;
2671da177e4SLinus Torvalds 
268ca325f69SMarcel Holtmann 	struct dentry		*debugfs;
269ca325f69SMarcel Holtmann 
270a91f2e39SMarcel Holtmann 	struct device		dev;
2711da177e4SLinus Torvalds 
272611b30f7SMarcel Holtmann 	struct rfkill		*rfkill;
273611b30f7SMarcel Holtmann 
274d23264a8SAndre Guedes 	unsigned long		dev_flags;
275d23264a8SAndre Guedes 
2767ba8b4beSAndre Guedes 	struct delayed_work	le_scan_disable;
2777ba8b4beSAndre Guedes 
27828b75a89SAndre Guedes 	struct work_struct	le_scan;
27928b75a89SAndre Guedes 	struct le_scan_params	le_scan_params;
28028b75a89SAndre Guedes 
2818fa19098SJohan Hedberg 	__s8			adv_tx_power;
2828fa19098SJohan Hedberg 
2831da177e4SLinus Torvalds 	int (*open)(struct hci_dev *hdev);
2841da177e4SLinus Torvalds 	int (*close)(struct hci_dev *hdev);
2851da177e4SLinus Torvalds 	int (*flush)(struct hci_dev *hdev);
2861da177e4SLinus Torvalds 	int (*send)(struct sk_buff *skb);
2871da177e4SLinus Torvalds 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
2881da177e4SLinus Torvalds 	int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
2891da177e4SLinus Torvalds };
2901da177e4SLinus Torvalds 
29153502d69SAndrei Emeltchenko #define HCI_PHY_HANDLE(handle)	(handle & 0xff)
29253502d69SAndrei Emeltchenko 
2931da177e4SLinus Torvalds struct hci_conn {
2941da177e4SLinus Torvalds 	struct list_head list;
2951da177e4SLinus Torvalds 
2961da177e4SLinus Torvalds 	atomic_t	refcnt;
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds 	bdaddr_t	dst;
29929b7988aSAndre Guedes 	__u8		dst_type;
3001da177e4SLinus Torvalds 	__u16		handle;
3011da177e4SLinus Torvalds 	__u16		state;
30204837f64SMarcel Holtmann 	__u8		mode;
3031da177e4SLinus Torvalds 	__u8		type;
304a0c808b3SJohan Hedberg 	bool		out;
3054c67bc74SMarcel Holtmann 	__u8		attempt;
3061da177e4SLinus Torvalds 	__u8		dev_class[3];
30704837f64SMarcel Holtmann 	__u8		features[8];
30804837f64SMarcel Holtmann 	__u16		interval;
309a8746417SMarcel Holtmann 	__u16		pkt_type;
31004837f64SMarcel Holtmann 	__u16		link_policy;
3111da177e4SLinus Torvalds 	__u32		link_mode;
31213d39315SWaldemar Rymarkiewicz 	__u8		key_type;
31340be492fSMarcel Holtmann 	__u8		auth_type;
3148c1b2355SMarcel Holtmann 	__u8		sec_level;
315765c2a96SJohan Hedberg 	__u8		pending_sec_level;
316980e1a53SJohan Hedberg 	__u8		pin_length;
317726b4ffcSVinicius Costa Gomes 	__u8		enc_key_size;
31817fa4b9dSJohan Hedberg 	__u8		io_capability;
31992a25256SJohan Hedberg 	__u32		passkey_notify;
32092a25256SJohan Hedberg 	__u8		passkey_entered;
321052b30b0SMarcel Holtmann 	__u16		disc_timeout;
32251a8efd7SJohan Hedberg 	unsigned long	flags;
3231da177e4SLinus Torvalds 
32403b555e1SJohan Hedberg 	__u8		remote_cap;
32503b555e1SJohan Hedberg 	__u8		remote_auth;
3263161ae1cSAndrei Emeltchenko 	__u8		remote_id;
3276ec5bcadSVishal Agarwal 	bool		flush_key;
32803b555e1SJohan Hedberg 
3291da177e4SLinus Torvalds 	unsigned int	sent;
3301da177e4SLinus Torvalds 
3311da177e4SLinus Torvalds 	struct sk_buff_head data_q;
3322c33c06aSGustavo F. Padovan 	struct list_head chan_list;
3331da177e4SLinus Torvalds 
33419c40e3bSGustavo F. Padovan 	struct delayed_work disc_work;
33504837f64SMarcel Holtmann 	struct timer_list idle_timer;
3369f61656aSJohan Hedberg 	struct timer_list auto_accept_timer;
3371da177e4SLinus Torvalds 
338b219e3acSMarcel Holtmann 	struct device	dev;
3399eba32b8SMarcel Holtmann 	atomic_t	devref;
340b219e3acSMarcel Holtmann 
3411da177e4SLinus Torvalds 	struct hci_dev	*hdev;
3421da177e4SLinus Torvalds 	void		*l2cap_data;
3431da177e4SLinus Torvalds 	void		*sco_data;
3442b64d153SBrian Gix 	void		*smp_conn;
3459740e49dSAndrei Emeltchenko 	struct amp_mgr	*amp_mgr;
3461da177e4SLinus Torvalds 
3471da177e4SLinus Torvalds 	struct hci_conn	*link;
348e9a416b5SJohan Hedberg 
349e9a416b5SJohan Hedberg 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
350e9a416b5SJohan Hedberg 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
351e9a416b5SJohan Hedberg 	void (*disconn_cfm_cb)	(struct hci_conn *conn, u8 reason);
3521da177e4SLinus Torvalds };
3531da177e4SLinus Torvalds 
35473d80debSLuiz Augusto von Dentz struct hci_chan {
35573d80debSLuiz Augusto von Dentz 	struct list_head list;
35642c4e53eSAndrei Emeltchenko 	__u16 handle;
35773d80debSLuiz Augusto von Dentz 	struct hci_conn *conn;
35873d80debSLuiz Augusto von Dentz 	struct sk_buff_head data_q;
35973d80debSLuiz Augusto von Dentz 	unsigned int	sent;
360168df8e5SMat Martineau 	__u8		state;
36173d80debSLuiz Augusto von Dentz };
36273d80debSLuiz Augusto von Dentz 
3631da177e4SLinus Torvalds extern struct list_head hci_dev_list;
3641da177e4SLinus Torvalds extern struct list_head hci_cb_list;
3651da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock;
3661da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock;
3671da177e4SLinus Torvalds 
368686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */
369686ebf28SUlisses Furquim extern int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
3709e664631SAndrei Emeltchenko extern void l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
371686ebf28SUlisses Furquim extern int l2cap_disconn_ind(struct hci_conn *hcon);
3729e664631SAndrei Emeltchenko extern void l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
373686ebf28SUlisses Furquim extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
374c3c7ea65SGustavo Padovan extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb,
375c3c7ea65SGustavo Padovan 			      u16 flags);
376686ebf28SUlisses Furquim 
377686ebf28SUlisses Furquim extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
3789e664631SAndrei Emeltchenko extern void sco_connect_cfm(struct hci_conn *hcon, __u8 status);
3799e664631SAndrei Emeltchenko extern void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
380686ebf28SUlisses Furquim extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
381686ebf28SUlisses Furquim 
3821da177e4SLinus Torvalds /* ----- Inquiry cache ----- */
38370f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX   (HZ*30)   /* 30 seconds */
38470f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   /* 60 seconds */
3851da177e4SLinus Torvalds 
38630883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev)
3871da177e4SLinus Torvalds {
388ff9ef578SJohan Hedberg 	hdev->discovery.state = DISCOVERY_STOPPED;
38930883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.all);
39030883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.unknown);
39130883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.resolve);
3921da177e4SLinus Torvalds }
3931da177e4SLinus Torvalds 
39430dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev);
39530dc78e1SJohan Hedberg 
396ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state);
397ff9ef578SJohan Hedberg 
3981da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev)
3991da177e4SLinus Torvalds {
40030883512SJohan Hedberg 	return list_empty(&hdev->discovery.all);
4011da177e4SLinus Torvalds }
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev)
4041da177e4SLinus Torvalds {
40530883512SJohan Hedberg 	struct discovery_state *c = &hdev->discovery;
4061da177e4SLinus Torvalds 	return jiffies - c->timestamp;
4071da177e4SLinus Torvalds }
4081da177e4SLinus Torvalds 
4091da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e)
4101da177e4SLinus Torvalds {
4111da177e4SLinus Torvalds 	return jiffies - e->timestamp;
4121da177e4SLinus Torvalds }
4131da177e4SLinus Torvalds 
4145a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
4155a9d0a3fSWaldemar Rymarkiewicz 					       bdaddr_t *bdaddr);
416561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
417561aafbcSJohan Hedberg 						       bdaddr_t *bdaddr);
41830dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
41930dc78e1SJohan Hedberg 						       bdaddr_t *bdaddr,
42030dc78e1SJohan Hedberg 						       int state);
421a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
422a3d4e20aSJohan Hedberg 				      struct inquiry_entry *ie);
4233175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
424388fc8faSJohan Hedberg 			      bool name_known, bool *ssp);
4251da177e4SLinus Torvalds 
4261da177e4SLinus Torvalds /* ----- HCI Connections ----- */
4271da177e4SLinus Torvalds enum {
4281da177e4SLinus Torvalds 	HCI_CONN_AUTH_PEND,
42919f8def0SWaldemar Rymarkiewicz 	HCI_CONN_REAUTH_PEND,
4301da177e4SLinus Torvalds 	HCI_CONN_ENCRYPT_PEND,
43104837f64SMarcel Holtmann 	HCI_CONN_RSWITCH_PEND,
43204837f64SMarcel Holtmann 	HCI_CONN_MODE_CHANGE_PEND,
433e73439d8SMarcel Holtmann 	HCI_CONN_SCO_SETUP_PEND,
434d26a2345SVinicius Costa Gomes 	HCI_CONN_LE_SMP_PEND,
435b644ba33SJohan Hedberg 	HCI_CONN_MGMT_CONNECTED,
43658a681efSJohan Hedberg 	HCI_CONN_SSP_ENABLED,
43758a681efSJohan Hedberg 	HCI_CONN_POWER_SAVE,
43858a681efSJohan Hedberg 	HCI_CONN_REMOTE_OOB,
4391da177e4SLinus Torvalds };
4401da177e4SLinus Torvalds 
441aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
442aa64a8b5SJohan Hedberg {
443aa64a8b5SJohan Hedberg 	struct hci_dev *hdev = conn->hdev;
444c3c7ea65SGustavo Padovan 	return test_bit(HCI_SSP_ENABLED, &hdev->dev_flags) &&
445c3c7ea65SGustavo Padovan 	       test_bit(HCI_CONN_SSP_ENABLED, &conn->flags);
446aa64a8b5SJohan Hedberg }
447aa64a8b5SJohan Hedberg 
4481da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
4491da177e4SLinus Torvalds {
4501da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
451bf4c6325SGustavo F. Padovan 	list_add_rcu(&c->list, &h->list);
452fcd89c09SVille Tervo 	switch (c->type) {
453fcd89c09SVille Tervo 	case ACL_LINK:
4541da177e4SLinus Torvalds 		h->acl_num++;
455fcd89c09SVille Tervo 		break;
456bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
457bd1eb66bSAndrei Emeltchenko 		h->amp_num++;
458bd1eb66bSAndrei Emeltchenko 		break;
459fcd89c09SVille Tervo 	case LE_LINK:
460fcd89c09SVille Tervo 		h->le_num++;
461fcd89c09SVille Tervo 		break;
462fcd89c09SVille Tervo 	case SCO_LINK:
463fcd89c09SVille Tervo 	case ESCO_LINK:
4641da177e4SLinus Torvalds 		h->sco_num++;
465fcd89c09SVille Tervo 		break;
466fcd89c09SVille Tervo 	}
4671da177e4SLinus Torvalds }
4681da177e4SLinus Torvalds 
4691da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
4701da177e4SLinus Torvalds {
4711da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
472bf4c6325SGustavo F. Padovan 
473bf4c6325SGustavo F. Padovan 	list_del_rcu(&c->list);
474bf4c6325SGustavo F. Padovan 	synchronize_rcu();
475bf4c6325SGustavo F. Padovan 
476fcd89c09SVille Tervo 	switch (c->type) {
477fcd89c09SVille Tervo 	case ACL_LINK:
4781da177e4SLinus Torvalds 		h->acl_num--;
479fcd89c09SVille Tervo 		break;
480bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
481bd1eb66bSAndrei Emeltchenko 		h->amp_num--;
482bd1eb66bSAndrei Emeltchenko 		break;
483fcd89c09SVille Tervo 	case LE_LINK:
484fcd89c09SVille Tervo 		h->le_num--;
485fcd89c09SVille Tervo 		break;
486fcd89c09SVille Tervo 	case SCO_LINK:
487fcd89c09SVille Tervo 	case ESCO_LINK:
4881da177e4SLinus Torvalds 		h->sco_num--;
489fcd89c09SVille Tervo 		break;
490fcd89c09SVille Tervo 	}
4911da177e4SLinus Torvalds }
4921da177e4SLinus Torvalds 
49352087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
49452087a79SLuiz Augusto von Dentz {
49552087a79SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
49652087a79SLuiz Augusto von Dentz 	switch (type) {
49752087a79SLuiz Augusto von Dentz 	case ACL_LINK:
49852087a79SLuiz Augusto von Dentz 		return h->acl_num;
499bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
500bd1eb66bSAndrei Emeltchenko 		return h->amp_num;
50152087a79SLuiz Augusto von Dentz 	case LE_LINK:
50252087a79SLuiz Augusto von Dentz 		return h->le_num;
50352087a79SLuiz Augusto von Dentz 	case SCO_LINK:
50452087a79SLuiz Augusto von Dentz 	case ESCO_LINK:
50552087a79SLuiz Augusto von Dentz 		return h->sco_num;
50652087a79SLuiz Augusto von Dentz 	default:
50752087a79SLuiz Augusto von Dentz 		return 0;
50852087a79SLuiz Augusto von Dentz 	}
50952087a79SLuiz Augusto von Dentz }
51052087a79SLuiz Augusto von Dentz 
5111da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
5121da177e4SLinus Torvalds 								__u16 handle)
5131da177e4SLinus Torvalds {
5141da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
5151da177e4SLinus Torvalds 	struct hci_conn  *c;
5161da177e4SLinus Torvalds 
517bf4c6325SGustavo F. Padovan 	rcu_read_lock();
518bf4c6325SGustavo F. Padovan 
519bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
520bf4c6325SGustavo F. Padovan 		if (c->handle == handle) {
521bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5221da177e4SLinus Torvalds 			return c;
5231da177e4SLinus Torvalds 		}
524bf4c6325SGustavo F. Padovan 	}
525bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
526bf4c6325SGustavo F. Padovan 
5271da177e4SLinus Torvalds 	return NULL;
5281da177e4SLinus Torvalds }
5291da177e4SLinus Torvalds 
5301da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
5311da177e4SLinus Torvalds 							__u8 type, bdaddr_t *ba)
5321da177e4SLinus Torvalds {
5331da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
5341da177e4SLinus Torvalds 	struct hci_conn  *c;
5351da177e4SLinus Torvalds 
536bf4c6325SGustavo F. Padovan 	rcu_read_lock();
537bf4c6325SGustavo F. Padovan 
538bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
539bf4c6325SGustavo F. Padovan 		if (c->type == type && !bacmp(&c->dst, ba)) {
540bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5411da177e4SLinus Torvalds 			return c;
5421da177e4SLinus Torvalds 		}
543bf4c6325SGustavo F. Padovan 	}
544bf4c6325SGustavo F. Padovan 
545bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
546bf4c6325SGustavo F. Padovan 
5471da177e4SLinus Torvalds 	return NULL;
5481da177e4SLinus Torvalds }
5491da177e4SLinus Torvalds 
5504c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
5514c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
5524c67bc74SMarcel Holtmann {
5534c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
5544c67bc74SMarcel Holtmann 	struct hci_conn  *c;
5554c67bc74SMarcel Holtmann 
556bf4c6325SGustavo F. Padovan 	rcu_read_lock();
557bf4c6325SGustavo F. Padovan 
558bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
559bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
560bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5614c67bc74SMarcel Holtmann 			return c;
5624c67bc74SMarcel Holtmann 		}
563bf4c6325SGustavo F. Padovan 	}
564bf4c6325SGustavo F. Padovan 
565bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
566bf4c6325SGustavo F. Padovan 
5674c67bc74SMarcel Holtmann 	return NULL;
5684c67bc74SMarcel Holtmann }
5694c67bc74SMarcel Holtmann 
5701da177e4SLinus Torvalds void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
571b6a0dc82SMarcel Holtmann void hci_setup_sync(struct hci_conn *conn, __u16 handle);
572e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
5731da177e4SLinus Torvalds 
5741da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
5751da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn);
5761da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
577a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
5781da177e4SLinus Torvalds 
57973d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
5809472007cSAndrei Emeltchenko void hci_chan_del(struct hci_chan *chan);
5812c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
58242c4e53eSAndrei Emeltchenko struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle);
58373d80debSLuiz Augusto von Dentz 
5845a9d0a3fSWaldemar Rymarkiewicz struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
585b12f62cfSAndre Guedes 			     __u8 dst_type, __u8 sec_level, __u8 auth_type);
586e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
587b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
5880684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
5891da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn);
5908c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
5911da177e4SLinus Torvalds 
59214b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
5931da177e4SLinus Torvalds 
5949eba32b8SMarcel Holtmann void hci_conn_hold_device(struct hci_conn *conn);
5959eba32b8SMarcel Holtmann void hci_conn_put_device(struct hci_conn *conn);
5969eba32b8SMarcel Holtmann 
5971da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn)
5981da177e4SLinus Torvalds {
59971becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
60038b3fef1SAndrei Emeltchenko 
6011da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
6022f304d1eSAndre Guedes 	cancel_delayed_work(&conn->disc_work);
6031da177e4SLinus Torvalds }
6041da177e4SLinus Torvalds 
6051da177e4SLinus Torvalds static inline void hci_conn_put(struct hci_conn *conn)
6061da177e4SLinus Torvalds {
60771becf0cSAndrei Emeltchenko 	BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt));
60838b3fef1SAndrei Emeltchenko 
6091da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
61004837f64SMarcel Holtmann 		unsigned long timeo;
611716e4ab5SAndrei Emeltchenko 
612716e4ab5SAndrei Emeltchenko 		switch (conn->type) {
613716e4ab5SAndrei Emeltchenko 		case ACL_LINK:
614716e4ab5SAndrei Emeltchenko 		case LE_LINK:
6156ac59344SMarcel Holtmann 			del_timer(&conn->idle_timer);
6166ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
6175f246e89SAndrei Emeltchenko 				timeo = conn->disc_timeout;
61804837f64SMarcel Holtmann 				if (!conn->out)
619052b30b0SMarcel Holtmann 					timeo *= 2;
6205a9d0a3fSWaldemar Rymarkiewicz 			} else {
6216ac59344SMarcel Holtmann 				timeo = msecs_to_jiffies(10);
6225a9d0a3fSWaldemar Rymarkiewicz 			}
623716e4ab5SAndrei Emeltchenko 			break;
624716e4ab5SAndrei Emeltchenko 
625716e4ab5SAndrei Emeltchenko 		case AMP_LINK:
626716e4ab5SAndrei Emeltchenko 			timeo = conn->disc_timeout;
627716e4ab5SAndrei Emeltchenko 			break;
628716e4ab5SAndrei Emeltchenko 
629716e4ab5SAndrei Emeltchenko 		default:
63004837f64SMarcel Holtmann 			timeo = msecs_to_jiffies(10);
631716e4ab5SAndrei Emeltchenko 			break;
6325a9d0a3fSWaldemar Rymarkiewicz 		}
633716e4ab5SAndrei Emeltchenko 
6342f304d1eSAndre Guedes 		cancel_delayed_work(&conn->disc_work);
63519c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
6361931782bSVinicius Costa Gomes 				   &conn->disc_work, timeo);
6371da177e4SLinus Torvalds 	}
6381da177e4SLinus Torvalds }
6391da177e4SLinus Torvalds 
6401da177e4SLinus Torvalds /* ----- HCI Devices ----- */
641dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
6421da177e4SLinus Torvalds {
643376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
644376261aeSAndrei Emeltchenko 	       atomic_read(&d->dev.kobj.kref.refcount));
645376261aeSAndrei Emeltchenko 
6464c724c71SDavid Herrmann 	put_device(&d->dev);
647010666a1SDavid Herrmann }
6481da177e4SLinus Torvalds 
649dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
6501da177e4SLinus Torvalds {
651376261aeSAndrei Emeltchenko 	BT_DBG("%s orig refcnt %d", d->name,
652376261aeSAndrei Emeltchenko 	       atomic_read(&d->dev.kobj.kref.refcount));
653376261aeSAndrei Emeltchenko 
6544c724c71SDavid Herrmann 	get_device(&d->dev);
6551da177e4SLinus Torvalds 	return d;
6561da177e4SLinus Torvalds }
6571da177e4SLinus Torvalds 
65809fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
65909fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
6601da177e4SLinus Torvalds 
661aa2b86d7SDavid Herrmann #define to_hci_dev(d) container_of(d, struct hci_dev, dev)
6623dc07322SDavid Herrmann #define to_hci_conn(c) container_of(c, struct hci_conn, dev)
663aa2b86d7SDavid Herrmann 
664155961e8SDavid Herrmann static inline void *hci_get_drvdata(struct hci_dev *hdev)
665155961e8SDavid Herrmann {
666155961e8SDavid Herrmann 	return dev_get_drvdata(&hdev->dev);
667155961e8SDavid Herrmann }
668155961e8SDavid Herrmann 
669155961e8SDavid Herrmann static inline void hci_set_drvdata(struct hci_dev *hdev, void *data)
670155961e8SDavid Herrmann {
671155961e8SDavid Herrmann 	dev_set_drvdata(&hdev->dev, data);
672155961e8SDavid Herrmann }
673155961e8SDavid Herrmann 
6748598d064SAndrei Emeltchenko /* hci_dev_list shall be locked */
6758598d064SAndrei Emeltchenko static inline uint8_t __hci_num_ctrl(void)
6768598d064SAndrei Emeltchenko {
6778598d064SAndrei Emeltchenko 	uint8_t count = 0;
6788598d064SAndrei Emeltchenko 	struct list_head *p;
6798598d064SAndrei Emeltchenko 
6808598d064SAndrei Emeltchenko 	list_for_each(p, &hci_dev_list) {
6818598d064SAndrei Emeltchenko 		count++;
6828598d064SAndrei Emeltchenko 	}
6838598d064SAndrei Emeltchenko 
6848598d064SAndrei Emeltchenko 	return count;
6858598d064SAndrei Emeltchenko }
6868598d064SAndrei Emeltchenko 
6871da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
6881da177e4SLinus Torvalds struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
6891da177e4SLinus Torvalds 
6901da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void);
6911da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
6921da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
69359735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
6941da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
6951da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
6961da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
6971da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
6981da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
6991da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
7001da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
7011da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
7021da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
7031da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
7041da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
70540be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
7061da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
7071da177e4SLinus Torvalds 
708c3c7ea65SGustavo Padovan struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev,
709c3c7ea65SGustavo Padovan 					 bdaddr_t *bdaddr);
710f0358568SJohan Hedberg int hci_blacklist_clear(struct hci_dev *hdev);
71188c1fe4bSJohan Hedberg int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
71288c1fe4bSJohan Hedberg int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
713f0358568SJohan Hedberg 
7142aeb9a1aSJohan Hedberg int hci_uuids_clear(struct hci_dev *hdev);
7152aeb9a1aSJohan Hedberg 
71655ed8ca1SJohan Hedberg int hci_link_keys_clear(struct hci_dev *hdev);
71755ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
718d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
719d25e28abSJohan Hedberg 		     bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
720c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
721c9839a11SVinicius Costa Gomes int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
7229a006657SAndrei Emeltchenko 		int new_key, u8 authenticated, u8 tk[16], u8 enc_size,
7239a006657SAndrei Emeltchenko 		__le16 ediv, u8 rand[8]);
724c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
725c9839a11SVinicius Costa Gomes 				     u8 addr_type);
726b899efafSVinicius Costa Gomes int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr);
727b899efafSVinicius Costa Gomes int hci_smp_ltks_clear(struct hci_dev *hdev);
72855ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
72955ed8ca1SJohan Hedberg 
7302763eda6SSzymon Janc int hci_remote_oob_data_clear(struct hci_dev *hdev);
7312763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
7322763eda6SSzymon Janc 							bdaddr_t *bdaddr);
7332763eda6SSzymon Janc int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
7342763eda6SSzymon Janc 								u8 *randomizer);
7352763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
7362763eda6SSzymon Janc 
7371da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
7381da177e4SLinus Torvalds 
73976bca880SMarcel Holtmann int hci_recv_frame(struct sk_buff *skb);
740ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
74199811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
742ef222013SMarcel Holtmann 
7430ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
744ce242970SDavid Herrmann int hci_add_sysfs(struct hci_dev *hdev);
745ce242970SDavid Herrmann void hci_del_sysfs(struct hci_dev *hdev);
746a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
747b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
748b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
7491da177e4SLinus Torvalds 
7506935e0f5SDavid Herrmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
7511da177e4SLinus Torvalds 
7521da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
75304837f64SMarcel Holtmann #define lmp_rswitch_capable(dev)   ((dev)->features[0] & LMP_RSWITCH)
75404837f64SMarcel Holtmann #define lmp_encrypt_capable(dev)   ((dev)->features[0] & LMP_ENCRYPT)
75504837f64SMarcel Holtmann #define lmp_sniff_capable(dev)     ((dev)->features[0] & LMP_SNIFF)
75604837f64SMarcel Holtmann #define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
7575b7f9909SMarcel Holtmann #define lmp_esco_capable(dev)      ((dev)->features[3] & LMP_ESCO)
758769be974SMarcel Holtmann #define lmp_ssp_capable(dev)       ((dev)->features[6] & LMP_SIMPLE_PAIR)
759e702112fSAndrei Emeltchenko #define lmp_no_flush_capable(dev)  ((dev)->features[6] & LMP_NO_FLUSH)
7606ed58ec5SVille Tervo #define lmp_le_capable(dev)        ((dev)->features[4] & LMP_LE)
7615e0452c0SAndre Guedes #define lmp_bredr_capable(dev)     (!((dev)->features[4] & LMP_NO_BREDR))
7621da177e4SLinus Torvalds 
763eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
76459e29406SAndre Guedes #define lmp_host_le_capable(dev)   ((dev)->host_features[0] & LMP_HOST_LE)
765eead27daSAndre Guedes 
7661da177e4SLinus Torvalds /* ----- HCI protocols ----- */
7675a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
7685a9d0a3fSWaldemar Rymarkiewicz 								__u8 type)
7691da177e4SLinus Torvalds {
770686ebf28SUlisses Furquim 	switch (type) {
771686ebf28SUlisses Furquim 	case ACL_LINK:
772686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
7731da177e4SLinus Torvalds 
774686ebf28SUlisses Furquim 	case SCO_LINK:
775686ebf28SUlisses Furquim 	case ESCO_LINK:
776686ebf28SUlisses Furquim 		return sco_connect_ind(hdev, bdaddr);
7771da177e4SLinus Torvalds 
778686ebf28SUlisses Furquim 	default:
779686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
780686ebf28SUlisses Furquim 		return -EINVAL;
781686ebf28SUlisses Furquim 	}
7821da177e4SLinus Torvalds }
7831da177e4SLinus Torvalds 
7841da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
7851da177e4SLinus Torvalds {
786686ebf28SUlisses Furquim 	switch (conn->type) {
787686ebf28SUlisses Furquim 	case ACL_LINK:
788686ebf28SUlisses Furquim 	case LE_LINK:
789686ebf28SUlisses Furquim 		l2cap_connect_cfm(conn, status);
790686ebf28SUlisses Furquim 		break;
7911da177e4SLinus Torvalds 
792686ebf28SUlisses Furquim 	case SCO_LINK:
793686ebf28SUlisses Furquim 	case ESCO_LINK:
794686ebf28SUlisses Furquim 		sco_connect_cfm(conn, status);
795686ebf28SUlisses Furquim 		break;
7961da177e4SLinus Torvalds 
797686ebf28SUlisses Furquim 	default:
798686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
799686ebf28SUlisses Furquim 		break;
800686ebf28SUlisses Furquim 	}
801e9a416b5SJohan Hedberg 
802e9a416b5SJohan Hedberg 	if (conn->connect_cfm_cb)
803e9a416b5SJohan Hedberg 		conn->connect_cfm_cb(conn, status);
8041da177e4SLinus Torvalds }
8051da177e4SLinus Torvalds 
8062950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
8072950f21aSMarcel Holtmann {
808686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
809686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
8102950f21aSMarcel Holtmann 
811686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
8122950f21aSMarcel Holtmann }
8132950f21aSMarcel Holtmann 
8142950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
8151da177e4SLinus Torvalds {
816686ebf28SUlisses Furquim 	switch (conn->type) {
817686ebf28SUlisses Furquim 	case ACL_LINK:
818686ebf28SUlisses Furquim 	case LE_LINK:
819686ebf28SUlisses Furquim 		l2cap_disconn_cfm(conn, reason);
820686ebf28SUlisses Furquim 		break;
8211da177e4SLinus Torvalds 
822686ebf28SUlisses Furquim 	case SCO_LINK:
823686ebf28SUlisses Furquim 	case ESCO_LINK:
824686ebf28SUlisses Furquim 		sco_disconn_cfm(conn, reason);
825686ebf28SUlisses Furquim 		break;
8261da177e4SLinus Torvalds 
827bd1eb66bSAndrei Emeltchenko 	/* L2CAP would be handled for BREDR chan */
828bd1eb66bSAndrei Emeltchenko 	case AMP_LINK:
829bd1eb66bSAndrei Emeltchenko 		break;
830bd1eb66bSAndrei Emeltchenko 
831686ebf28SUlisses Furquim 	default:
832686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
833686ebf28SUlisses Furquim 		break;
834686ebf28SUlisses Furquim 	}
835e9a416b5SJohan Hedberg 
836e9a416b5SJohan Hedberg 	if (conn->disconn_cfm_cb)
837e9a416b5SJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
8381da177e4SLinus Torvalds }
8391da177e4SLinus Torvalds 
8401da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
8411da177e4SLinus Torvalds {
8428c1b2355SMarcel Holtmann 	__u8 encrypt;
8438c1b2355SMarcel Holtmann 
844686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
845686ebf28SUlisses Furquim 		return;
846686ebf28SUlisses Furquim 
84751a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8488c1b2355SMarcel Holtmann 		return;
8498c1b2355SMarcel Holtmann 
8508c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
851686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
852e9a416b5SJohan Hedberg 
853e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
854e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
8551da177e4SLinus Torvalds }
8561da177e4SLinus Torvalds 
8575a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
8585a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
8591da177e4SLinus Torvalds {
860686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
861686ebf28SUlisses Furquim 		return;
8621da177e4SLinus Torvalds 
863686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
864e9a416b5SJohan Hedberg 
865e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
866e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
8671da177e4SLinus Torvalds }
8681da177e4SLinus Torvalds 
8691da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
8701da177e4SLinus Torvalds struct hci_cb {
8711da177e4SLinus Torvalds 	struct list_head list;
8721da177e4SLinus Torvalds 
8731da177e4SLinus Torvalds 	char *name;
8741da177e4SLinus Torvalds 
8755a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
8765a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
8771da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
8781da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
8791da177e4SLinus Torvalds };
8801da177e4SLinus Torvalds 
8811da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
8821da177e4SLinus Torvalds {
883711584eaSDenis Kirjanov 	struct hci_cb *cb;
8848c1b2355SMarcel Holtmann 	__u8 encrypt;
8851da177e4SLinus Torvalds 
8861da177e4SLinus Torvalds 	hci_proto_auth_cfm(conn, status);
8871da177e4SLinus Torvalds 
88851a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8898c1b2355SMarcel Holtmann 		return;
8908c1b2355SMarcel Holtmann 
8918c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
8928c1b2355SMarcel Holtmann 
893f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
894711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
8958c1b2355SMarcel Holtmann 		if (cb->security_cfm)
8968c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
8971da177e4SLinus Torvalds 	}
898f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8991da177e4SLinus Torvalds }
9001da177e4SLinus Torvalds 
9015a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
9025a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
9031da177e4SLinus Torvalds {
904711584eaSDenis Kirjanov 	struct hci_cb *cb;
9051da177e4SLinus Torvalds 
906435fef20SMarcel Holtmann 	if (conn->sec_level == BT_SECURITY_SDP)
907435fef20SMarcel Holtmann 		conn->sec_level = BT_SECURITY_LOW;
908435fef20SMarcel Holtmann 
90988167aedSVinicius Costa Gomes 	if (conn->pending_sec_level > conn->sec_level)
91088167aedSVinicius Costa Gomes 		conn->sec_level = conn->pending_sec_level;
91188167aedSVinicius Costa Gomes 
9129719f8afSMarcel Holtmann 	hci_proto_encrypt_cfm(conn, status, encrypt);
9131da177e4SLinus Torvalds 
914f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
915711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
9168c1b2355SMarcel Holtmann 		if (cb->security_cfm)
9178c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
9181da177e4SLinus Torvalds 	}
919f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
9201da177e4SLinus Torvalds }
9211da177e4SLinus Torvalds 
9221da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
9231da177e4SLinus Torvalds {
924711584eaSDenis Kirjanov 	struct hci_cb *cb;
9251da177e4SLinus Torvalds 
926f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
927711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
9281da177e4SLinus Torvalds 		if (cb->key_change_cfm)
9291da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
9301da177e4SLinus Torvalds 	}
931f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
9321da177e4SLinus Torvalds }
9331da177e4SLinus Torvalds 
9345a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
9355a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
9361da177e4SLinus Torvalds {
937711584eaSDenis Kirjanov 	struct hci_cb *cb;
9381da177e4SLinus Torvalds 
939f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
940711584eaSDenis Kirjanov 	list_for_each_entry(cb, &hci_cb_list, list) {
9411da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
9421da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
9431da177e4SLinus Torvalds 	}
944f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
9451da177e4SLinus Torvalds }
9461da177e4SLinus Torvalds 
9476759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
9486759a675SJohan Hedberg {
94984d9d071SJohan Hedberg 	size_t parsed = 0;
9506759a675SJohan Hedberg 
9516c0c331eSJohan Hedberg 	if (data_len < 2)
9526c0c331eSJohan Hedberg 		return false;
9536c0c331eSJohan Hedberg 
95484d9d071SJohan Hedberg 	while (parsed < data_len - 1) {
95584d9d071SJohan Hedberg 		u8 field_len = data[0];
9566759a675SJohan Hedberg 
9576759a675SJohan Hedberg 		if (field_len == 0)
9586759a675SJohan Hedberg 			break;
9596759a675SJohan Hedberg 
9606759a675SJohan Hedberg 		parsed += field_len + 1;
9616759a675SJohan Hedberg 
9626759a675SJohan Hedberg 		if (parsed > data_len)
9636759a675SJohan Hedberg 			break;
9646759a675SJohan Hedberg 
9656759a675SJohan Hedberg 		if (data[1] == type)
9666759a675SJohan Hedberg 			return true;
9676759a675SJohan Hedberg 
9686759a675SJohan Hedberg 		data += field_len + 1;
9696759a675SJohan Hedberg 	}
9706759a675SJohan Hedberg 
9716759a675SJohan Hedberg 	return false;
9726759a675SJohan Hedberg }
9736759a675SJohan Hedberg 
9749d939d94SVishal Agarwal static inline size_t eir_get_length(u8 *eir, size_t eir_len)
9759d939d94SVishal Agarwal {
9769d939d94SVishal Agarwal 	size_t parsed = 0;
9779d939d94SVishal Agarwal 
9789d939d94SVishal Agarwal 	while (parsed < eir_len) {
9799d939d94SVishal Agarwal 		u8 field_len = eir[0];
9809d939d94SVishal Agarwal 
9819d939d94SVishal Agarwal 		if (field_len == 0)
9829d939d94SVishal Agarwal 			return parsed;
9839d939d94SVishal Agarwal 
9849d939d94SVishal Agarwal 		parsed += field_len + 1;
9859d939d94SVishal Agarwal 		eir += field_len + 1;
9869d939d94SVishal Agarwal 	}
9879d939d94SVishal Agarwal 
9889d939d94SVishal Agarwal 	return eir_len;
9899d939d94SVishal Agarwal }
9909d939d94SVishal Agarwal 
9911dc06093SJohan Hedberg static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
9921dc06093SJohan Hedberg 				  u8 data_len)
9931dc06093SJohan Hedberg {
9941dc06093SJohan Hedberg 	eir[eir_len++] = sizeof(type) + data_len;
9951dc06093SJohan Hedberg 	eir[eir_len++] = type;
9961dc06093SJohan Hedberg 	memcpy(&eir[eir_len], data, data_len);
9971dc06093SJohan Hedberg 	eir_len += data_len;
9981dc06093SJohan Hedberg 
9991dc06093SJohan Hedberg 	return eir_len;
10001dc06093SJohan Hedberg }
10011dc06093SJohan Hedberg 
10021da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
10031da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
10041da177e4SLinus Torvalds 
1005a9de9248SMarcel Holtmann int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
100673d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
10070d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
10081da177e4SLinus Torvalds 
1009a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
10101da177e4SLinus Torvalds 
10111da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
1012470fe1b5SMarcel Holtmann void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
1013470fe1b5SMarcel Holtmann void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk);
1014cd82e61cSMarcel Holtmann void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb);
10151da177e4SLinus Torvalds 
1016040030efSMarcel Holtmann void hci_sock_dev_event(struct hci_dev *hdev, int event);
1017040030efSMarcel Holtmann 
10180381101fSJohan Hedberg /* Management interface */
1019591f47f3SAndre Guedes #define DISCOV_TYPE_BREDR		(BIT(BDADDR_BREDR))
1020591f47f3SAndre Guedes #define DISCOV_TYPE_LE			(BIT(BDADDR_LE_PUBLIC) | \
1021591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
1022591f47f3SAndre Guedes #define DISCOV_TYPE_INTERLEAVED		(BIT(BDADDR_BREDR) | \
1023591f47f3SAndre Guedes 					 BIT(BDADDR_LE_PUBLIC) | \
1024591f47f3SAndre Guedes 					 BIT(BDADDR_LE_RANDOM))
1025f39799f5SAndre Guedes 
10260381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
1027744cf19eSJohan Hedberg int mgmt_index_added(struct hci_dev *hdev);
1028744cf19eSJohan Hedberg int mgmt_index_removed(struct hci_dev *hdev);
1029744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered);
1030744cf19eSJohan Hedberg int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
1031744cf19eSJohan Hedberg int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
1032744cf19eSJohan Hedberg int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
1033744cf19eSJohan Hedberg int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
1034745c0ce3SVishal Agarwal 		      bool persistent);
1035afc747a6SJohan Hedberg int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
103604124681SGustavo F. Padovan 			  u8 addr_type, u32 flags, u8 *name, u8 name_len,
103704124681SGustavo F. Padovan 			  u8 *dev_class);
1038afc747a6SJohan Hedberg int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
1039f0d6a0eaSMikel Astiz 			     u8 link_type, u8 addr_type, u8 reason);
104088c3df13SJohan Hedberg int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr,
104188c3df13SJohan Hedberg 			   u8 link_type, u8 addr_type, u8 status);
104248264f06SJohan Hedberg int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
104348264f06SJohan Hedberg 			u8 addr_type, u8 status);
1044744cf19eSJohan Hedberg int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
1045744cf19eSJohan Hedberg int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1046c35938b2SSzymon Janc 				 u8 status);
1047744cf19eSJohan Hedberg int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1048744cf19eSJohan Hedberg 				     u8 status);
1049744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
1050272d90dfSJohan Hedberg 			      u8 link_type, u8 addr_type, __le32 value,
1051272d90dfSJohan Hedberg 			      u8 confirm_hint);
1052744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1053272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
1054272d90dfSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1055272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
1056272d90dfSJohan Hedberg int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
1057272d90dfSJohan Hedberg 			      u8 link_type, u8 addr_type);
1058604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1059272d90dfSJohan Hedberg 				     u8 link_type, u8 addr_type, u8 status);
1060272d90dfSJohan Hedberg int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
1061272d90dfSJohan Hedberg 					 u8 link_type, u8 addr_type, u8 status);
106292a25256SJohan Hedberg int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr,
106392a25256SJohan Hedberg 			     u8 link_type, u8 addr_type, u32 passkey,
106492a25256SJohan Hedberg 			     u8 entered);
1065bab73cb6SJohan Hedberg int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1066bab73cb6SJohan Hedberg 		     u8 addr_type, u8 status);
106733ef95edSJohan Hedberg int mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status);
1068c0ecddc2SJohan Hedberg int mgmt_ssp_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
10697f9a903cSMarcel Holtmann int mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class,
10707f9a903cSMarcel Holtmann 				   u8 status);
1071744cf19eSJohan Hedberg int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
1072744cf19eSJohan Hedberg int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
1073744cf19eSJohan Hedberg 					    u8 *randomizer, u8 status);
107406199cf8SJohan Hedberg int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
107548264f06SJohan Hedberg int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
107604124681SGustavo F. Padovan 		      u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
107704124681SGustavo F. Padovan 		      u8 ssp, u8 *eir, u16 eir_len);
1078b644ba33SJohan Hedberg int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
1079b644ba33SJohan Hedberg 		     u8 addr_type, s8 rssi, u8 *name, u8 name_len);
10807a135109SAndre Guedes int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
1081e6d465cbSAndre Guedes int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
1082744cf19eSJohan Hedberg int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
10835e0452c0SAndre Guedes int mgmt_interleaved_discovery(struct hci_dev *hdev);
108488c1fe4bSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
108588c1fe4bSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type);
1086bb4b2a9aSAndrei Emeltchenko bool mgmt_valid_hdev(struct hci_dev *hdev);
1087346af67bSVinicius Costa Gomes int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent);
1088346af67bSVinicius Costa Gomes 
10891da177e4SLinus Torvalds /* HCI info for socket */
10901da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk)
10911da177e4SLinus Torvalds 
10921da177e4SLinus Torvalds struct hci_pinfo {
10931da177e4SLinus Torvalds 	struct bt_sock    bt;
10941da177e4SLinus Torvalds 	struct hci_dev    *hdev;
10951da177e4SLinus Torvalds 	struct hci_filter filter;
10961da177e4SLinus Torvalds 	__u32             cmsg_mask;
1097c02178d2SJohan Hedberg 	unsigned short   channel;
10981da177e4SLinus Torvalds };
10991da177e4SLinus Torvalds 
11001da177e4SLinus Torvalds /* HCI security filter */
11011da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF  5
11021da177e4SLinus Torvalds 
11031da177e4SLinus Torvalds struct hci_sec_filter {
11041da177e4SLinus Torvalds 	__u32 type_mask;
11051da177e4SLinus Torvalds 	__u32 event_mask[2];
11061da177e4SLinus Torvalds 	__u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
11071da177e4SLinus Torvalds };
11081da177e4SLinus Torvalds 
11091da177e4SLinus Torvalds /* ----- HCI requests ----- */
11101da177e4SLinus Torvalds #define HCI_REQ_DONE	  0
11111da177e4SLinus Torvalds #define HCI_REQ_PEND	  1
11121da177e4SLinus Torvalds #define HCI_REQ_CANCELED  2
11131da177e4SLinus Torvalds 
1114a6a67efdSThomas Gleixner #define hci_req_lock(d)		mutex_lock(&d->req_lock)
1115a6a67efdSThomas Gleixner #define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
11161da177e4SLinus Torvalds 
111723bb5763SJohan Hedberg void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
11181da177e4SLinus Torvalds 
11192ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
11202ce603ebSClaudio Takahasi 					u16 latency, u16 to_multiplier);
1121a7a595f6SVinicius Costa Gomes void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
1122a7a595f6SVinicius Costa Gomes 							__u8 ltk[16]);
11232519a1fcSAndre Guedes int hci_do_inquiry(struct hci_dev *hdev, u8 length);
1124023d5049SAndre Guedes int hci_cancel_inquiry(struct hci_dev *hdev);
112528b75a89SAndre Guedes int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
112628b75a89SAndre Guedes 		int timeout);
11277dbfac1dSAndre Guedes int hci_cancel_le_scan(struct hci_dev *hdev);
11282519a1fcSAndre Guedes 
112931f7956cSAndre Guedes u8 bdaddr_to_le(u8 bdaddr_type);
113031f7956cSAndre Guedes 
11311da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
1132