xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision 346af67b)
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 
28a6b7a407SAlexey Dobriyan #include <linux/interrupt.h>
291da177e4SLinus Torvalds #include <net/bluetooth/hci.h>
301da177e4SLinus Torvalds 
315e59b791SLuiz Augusto von Dentz /* HCI priority */
325e59b791SLuiz Augusto von Dentz #define HCI_PRIO_MAX	7
335e59b791SLuiz Augusto von Dentz 
341da177e4SLinus Torvalds /* HCI Core structures */
351da177e4SLinus Torvalds struct inquiry_data {
361da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
371da177e4SLinus Torvalds 	__u8		pscan_rep_mode;
381da177e4SLinus Torvalds 	__u8		pscan_period_mode;
391da177e4SLinus Torvalds 	__u8		pscan_mode;
401da177e4SLinus Torvalds 	__u8		dev_class[3];
411ebb9252SMarcel Holtmann 	__le16		clock_offset;
421da177e4SLinus Torvalds 	__s8		rssi;
4341a96212SMarcel Holtmann 	__u8		ssp_mode;
441da177e4SLinus Torvalds };
451da177e4SLinus Torvalds 
461da177e4SLinus Torvalds struct inquiry_entry {
47561aafbcSJohan Hedberg 	struct list_head	all;		/* inq_cache.all */
48561aafbcSJohan Hedberg 	struct list_head	list;		/* unknown or resolve */
49561aafbcSJohan Hedberg 	enum {
50561aafbcSJohan Hedberg 		NAME_NOT_KNOWN,
51561aafbcSJohan Hedberg 		NAME_NEEDED,
52561aafbcSJohan Hedberg 		NAME_PENDING,
53561aafbcSJohan Hedberg 		NAME_KNOWN,
54561aafbcSJohan Hedberg 	} name_state;
551da177e4SLinus Torvalds 	__u32			timestamp;
561da177e4SLinus Torvalds 	struct inquiry_data	data;
571da177e4SLinus Torvalds };
581da177e4SLinus Torvalds 
5930883512SJohan Hedberg struct discovery_state {
60ff9ef578SJohan Hedberg 	enum {
61ff9ef578SJohan Hedberg 		DISCOVERY_STOPPED,
62ff9ef578SJohan Hedberg 		DISCOVERY_STARTING,
6330dc78e1SJohan Hedberg 		DISCOVERY_INQUIRY,
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;
761da177e4SLinus Torvalds 	unsigned int     sco_num;
77fcd89c09SVille Tervo 	unsigned int     le_num;
781da177e4SLinus Torvalds };
791da177e4SLinus Torvalds 
80f0358568SJohan Hedberg struct bdaddr_list {
81f0358568SJohan Hedberg 	struct list_head list;
82f0358568SJohan Hedberg 	bdaddr_t bdaddr;
83f0358568SJohan Hedberg };
842aeb9a1aSJohan Hedberg 
852aeb9a1aSJohan Hedberg struct bt_uuid {
862aeb9a1aSJohan Hedberg 	struct list_head list;
872aeb9a1aSJohan Hedberg 	u8 uuid[16];
881aff6f09SJohan Hedberg 	u8 svc_hint;
892aeb9a1aSJohan Hedberg };
902aeb9a1aSJohan Hedberg 
91b899efafSVinicius Costa Gomes struct smp_ltk {
92b899efafSVinicius Costa Gomes 	struct list_head list;
93b899efafSVinicius Costa Gomes 	bdaddr_t bdaddr;
94b899efafSVinicius Costa Gomes 	u8 bdaddr_type;
95b899efafSVinicius Costa Gomes 	u8 authenticated;
96b899efafSVinicius Costa Gomes 	u8 type;
97b899efafSVinicius Costa Gomes 	u8 enc_size;
98b899efafSVinicius Costa Gomes 	__le16 ediv;
99b899efafSVinicius Costa Gomes 	u8 rand[8];
100b899efafSVinicius Costa Gomes 	u8 val[16];
101b899efafSVinicius Costa Gomes } __packed;
102b899efafSVinicius Costa Gomes 
10334918cd7SVinicius Costa Gomes struct key_master_id {
10434918cd7SVinicius Costa Gomes 	__le16 ediv;
10534918cd7SVinicius Costa Gomes 	u8 rand[8];
10634918cd7SVinicius Costa Gomes } __packed;
10734918cd7SVinicius Costa Gomes 
10834918cd7SVinicius Costa Gomes struct link_key_data {
10934918cd7SVinicius Costa Gomes 	bdaddr_t bdaddr;
11034918cd7SVinicius Costa Gomes 	u8 type;
11134918cd7SVinicius Costa Gomes 	u8 val[16];
11234918cd7SVinicius Costa Gomes 	u8 pin_len;
11334918cd7SVinicius Costa Gomes 	u8 dlen;
11434918cd7SVinicius Costa Gomes 	u8 data[0];
11534918cd7SVinicius Costa Gomes } __packed;
11634918cd7SVinicius Costa Gomes 
11755ed8ca1SJohan Hedberg struct link_key {
11855ed8ca1SJohan Hedberg 	struct list_head list;
11955ed8ca1SJohan Hedberg 	bdaddr_t bdaddr;
12055ed8ca1SJohan Hedberg 	u8 type;
12155ed8ca1SJohan Hedberg 	u8 val[16];
12255ed8ca1SJohan Hedberg 	u8 pin_len;
12334918cd7SVinicius Costa Gomes 	u8 dlen;
12434918cd7SVinicius Costa Gomes 	u8 data[0];
12555ed8ca1SJohan Hedberg };
12655ed8ca1SJohan Hedberg 
1272763eda6SSzymon Janc struct oob_data {
1282763eda6SSzymon Janc 	struct list_head list;
1292763eda6SSzymon Janc 	bdaddr_t bdaddr;
1302763eda6SSzymon Janc 	u8 hash[16];
1312763eda6SSzymon Janc 	u8 randomizer[16];
1322763eda6SSzymon Janc };
1332763eda6SSzymon Janc 
13476c8686fSAndre Guedes struct adv_entry {
13576c8686fSAndre Guedes 	struct list_head list;
13676c8686fSAndre Guedes 	bdaddr_t bdaddr;
13776c8686fSAndre Guedes 	u8 bdaddr_type;
13876c8686fSAndre Guedes };
13976c8686fSAndre Guedes 
140cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4
1411da177e4SLinus Torvalds struct hci_dev {
1421da177e4SLinus Torvalds 	struct list_head list;
14309fd0de5SGustavo F. Padovan 	struct mutex	lock;
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds 	char		name[8];
1461da177e4SLinus Torvalds 	unsigned long	flags;
1471da177e4SLinus Torvalds 	__u16		id;
148c13854ceSMarcel Holtmann 	__u8		bus;
149943da25dSMarcel Holtmann 	__u8		dev_type;
1501da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
1511f6c6378SJohan Hedberg 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
15280a1e1dbSJohan Hedberg 	__u8		eir[HCI_MAX_EIR_LENGTH];
153a9de9248SMarcel Holtmann 	__u8		dev_class[3];
1541aff6f09SJohan Hedberg 	__u8		major_class;
1551aff6f09SJohan Hedberg 	__u8		minor_class;
1561da177e4SLinus Torvalds 	__u8		features[8];
15759e29406SAndre Guedes 	__u8		host_features[8];
158a9de9248SMarcel Holtmann 	__u8		commands[64];
1591143e5a6SMarcel Holtmann 	__u8		hci_ver;
1601143e5a6SMarcel Holtmann 	__u16		hci_rev;
161d5859e22SJohan Hedberg 	__u8		lmp_ver;
1621143e5a6SMarcel Holtmann 	__u16		manufacturer;
163d5859e22SJohan Hedberg 	__le16		lmp_subver;
1641da177e4SLinus Torvalds 	__u16		voice_setting;
16517fa4b9dSJohan Hedberg 	__u8		io_capability;
1661da177e4SLinus Torvalds 
1671da177e4SLinus Torvalds 	__u16		pkt_type;
1685b7f9909SMarcel Holtmann 	__u16		esco_type;
1691da177e4SLinus Torvalds 	__u16		link_policy;
1701da177e4SLinus Torvalds 	__u16		link_mode;
1711da177e4SLinus Torvalds 
17204837f64SMarcel Holtmann 	__u32		idle_timeout;
17304837f64SMarcel Holtmann 	__u16		sniff_min_interval;
17404837f64SMarcel Holtmann 	__u16		sniff_max_interval;
17504837f64SMarcel Holtmann 
176928abaa7SAndrei Emeltchenko 	__u8		amp_status;
177928abaa7SAndrei Emeltchenko 	__u32		amp_total_bw;
178928abaa7SAndrei Emeltchenko 	__u32		amp_max_bw;
179928abaa7SAndrei Emeltchenko 	__u32		amp_min_latency;
180928abaa7SAndrei Emeltchenko 	__u32		amp_max_pdu;
181928abaa7SAndrei Emeltchenko 	__u8		amp_type;
182928abaa7SAndrei Emeltchenko 	__u16		amp_pal_cap;
183928abaa7SAndrei Emeltchenko 	__u16		amp_assoc_size;
184928abaa7SAndrei Emeltchenko 	__u32		amp_max_flush_to;
185928abaa7SAndrei Emeltchenko 	__u32		amp_be_flush_to;
186928abaa7SAndrei Emeltchenko 
1871e89cffbSAndrei Emeltchenko 	__u8		flow_ctl_mode;
1881e89cffbSAndrei Emeltchenko 
1899f61656aSJohan Hedberg 	unsigned int	auto_accept_delay;
1909f61656aSJohan Hedberg 
1911da177e4SLinus Torvalds 	unsigned long	quirks;
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds 	atomic_t	cmd_cnt;
1941da177e4SLinus Torvalds 	unsigned int	acl_cnt;
1951da177e4SLinus Torvalds 	unsigned int	sco_cnt;
1966ed58ec5SVille Tervo 	unsigned int	le_cnt;
1971da177e4SLinus Torvalds 
1981da177e4SLinus Torvalds 	unsigned int	acl_mtu;
1991da177e4SLinus Torvalds 	unsigned int	sco_mtu;
2006ed58ec5SVille Tervo 	unsigned int	le_mtu;
2011da177e4SLinus Torvalds 	unsigned int	acl_pkts;
2021da177e4SLinus Torvalds 	unsigned int	sco_pkts;
2036ed58ec5SVille Tervo 	unsigned int	le_pkts;
2041da177e4SLinus Torvalds 
205350ee4cfSAndrei Emeltchenko 	__u16		block_len;
206350ee4cfSAndrei Emeltchenko 	__u16		block_mtu;
207350ee4cfSAndrei Emeltchenko 	__u16		num_blocks;
208350ee4cfSAndrei Emeltchenko 	__u16		block_cnt;
209350ee4cfSAndrei Emeltchenko 
2101da177e4SLinus Torvalds 	unsigned long	acl_last_tx;
2111da177e4SLinus Torvalds 	unsigned long	sco_last_tx;
2126ed58ec5SVille Tervo 	unsigned long	le_last_tx;
2131da177e4SLinus Torvalds 
214f48fd9c8SMarcel Holtmann 	struct workqueue_struct	*workqueue;
215f48fd9c8SMarcel Holtmann 
216ab81cbf9SJohan Hedberg 	struct work_struct	power_on;
2173243553fSJohan Hedberg 	struct delayed_work	power_off;
218ab81cbf9SJohan Hedberg 
21916ab91abSJohan Hedberg 	__u16			discov_timeout;
22016ab91abSJohan Hedberg 	struct delayed_work	discov_off;
22116ab91abSJohan Hedberg 
2227d78525dSJohan Hedberg 	struct delayed_work	service_cache;
2237d78525dSJohan Hedberg 
2246bd32326SVille Tervo 	struct timer_list	cmd_timer;
225b78752ccSMarcel Holtmann 
226b78752ccSMarcel Holtmann 	struct work_struct	rx_work;
227c347b765SGustavo F. Padovan 	struct work_struct	cmd_work;
2283eff45eaSGustavo F. Padovan 	struct work_struct	tx_work;
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds 	struct sk_buff_head	rx_q;
2311da177e4SLinus Torvalds 	struct sk_buff_head	raw_q;
2321da177e4SLinus Torvalds 	struct sk_buff_head	cmd_q;
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds 	struct sk_buff		*sent_cmd;
235cd4c5391SSuraj Sumangala 	struct sk_buff		*reassembly[NUM_REASSEMBLY];
2361da177e4SLinus Torvalds 
237a6a67efdSThomas Gleixner 	struct mutex		req_lock;
2381da177e4SLinus Torvalds 	wait_queue_head_t	req_wait_q;
2391da177e4SLinus Torvalds 	__u32			req_status;
2401da177e4SLinus Torvalds 	__u32			req_result;
241a5040efaSJohan Hedberg 
242a5040efaSJohan Hedberg 	__u16			init_last_cmd;
2431da177e4SLinus Torvalds 
2442e58ef3eSJohan Hedberg 	struct list_head	mgmt_pending;
2452e58ef3eSJohan Hedberg 
24630883512SJohan Hedberg 	struct discovery_state	discovery;
2471da177e4SLinus Torvalds 	struct hci_conn_hash	conn_hash;
248ea4bd8baSDavid Miller 	struct list_head	blacklist;
2491da177e4SLinus Torvalds 
2502aeb9a1aSJohan Hedberg 	struct list_head	uuids;
2512aeb9a1aSJohan Hedberg 
25255ed8ca1SJohan Hedberg 	struct list_head	link_keys;
25355ed8ca1SJohan Hedberg 
254b899efafSVinicius Costa Gomes 	struct list_head	long_term_keys;
255b899efafSVinicius Costa Gomes 
2562763eda6SSzymon Janc 	struct list_head	remote_oob_data;
2572763eda6SSzymon Janc 
25876c8686fSAndre Guedes 	struct list_head	adv_entries;
259db323f2fSGustavo F. Padovan 	struct delayed_work	adv_work;
26076c8686fSAndre Guedes 
2611da177e4SLinus Torvalds 	struct hci_dev_stats	stat;
2621da177e4SLinus Torvalds 
2631da177e4SLinus Torvalds 	struct sk_buff_head	driver_init;
2641da177e4SLinus Torvalds 
2651da177e4SLinus Torvalds 	void			*driver_data;
2661da177e4SLinus Torvalds 	void			*core_data;
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds 	atomic_t		promisc;
2691da177e4SLinus Torvalds 
270ca325f69SMarcel Holtmann 	struct dentry		*debugfs;
271ca325f69SMarcel Holtmann 
272a91f2e39SMarcel Holtmann 	struct device		*parent;
273a91f2e39SMarcel Holtmann 	struct device		dev;
2741da177e4SLinus Torvalds 
275611b30f7SMarcel Holtmann 	struct rfkill		*rfkill;
276611b30f7SMarcel Holtmann 
277d23264a8SAndre Guedes 	unsigned long		dev_flags;
278d23264a8SAndre Guedes 
2791da177e4SLinus Torvalds 	int (*open)(struct hci_dev *hdev);
2801da177e4SLinus Torvalds 	int (*close)(struct hci_dev *hdev);
2811da177e4SLinus Torvalds 	int (*flush)(struct hci_dev *hdev);
2821da177e4SLinus Torvalds 	int (*send)(struct sk_buff *skb);
2831da177e4SLinus Torvalds 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
2841da177e4SLinus Torvalds 	int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
2851da177e4SLinus Torvalds };
2861da177e4SLinus Torvalds 
2871da177e4SLinus Torvalds struct hci_conn {
2881da177e4SLinus Torvalds 	struct list_head list;
2891da177e4SLinus Torvalds 
2901da177e4SLinus Torvalds 	atomic_t	refcnt;
2911da177e4SLinus Torvalds 
2921da177e4SLinus Torvalds 	bdaddr_t	dst;
29329b7988aSAndre Guedes 	__u8		dst_type;
2941da177e4SLinus Torvalds 	__u16		handle;
2951da177e4SLinus Torvalds 	__u16		state;
29604837f64SMarcel Holtmann 	__u8		mode;
2971da177e4SLinus Torvalds 	__u8		type;
298a0c808b3SJohan Hedberg 	bool		out;
2994c67bc74SMarcel Holtmann 	__u8		attempt;
3001da177e4SLinus Torvalds 	__u8		dev_class[3];
30104837f64SMarcel Holtmann 	__u8		features[8];
30204837f64SMarcel Holtmann 	__u16		interval;
303a8746417SMarcel Holtmann 	__u16		pkt_type;
30404837f64SMarcel Holtmann 	__u16		link_policy;
3051da177e4SLinus Torvalds 	__u32		link_mode;
30613d39315SWaldemar Rymarkiewicz 	__u8		key_type;
30740be492fSMarcel Holtmann 	__u8		auth_type;
3088c1b2355SMarcel Holtmann 	__u8		sec_level;
309765c2a96SJohan Hedberg 	__u8		pending_sec_level;
310980e1a53SJohan Hedberg 	__u8		pin_length;
311726b4ffcSVinicius Costa Gomes 	__u8		enc_key_size;
31217fa4b9dSJohan Hedberg 	__u8		io_capability;
313052b30b0SMarcel Holtmann 	__u16		disc_timeout;
31451a8efd7SJohan Hedberg 	unsigned long	flags;
3151da177e4SLinus Torvalds 
31603b555e1SJohan Hedberg 	__u8		remote_cap;
31703b555e1SJohan Hedberg 	__u8		remote_auth;
31803b555e1SJohan Hedberg 
3191da177e4SLinus Torvalds 	unsigned int	sent;
3201da177e4SLinus Torvalds 
3211da177e4SLinus Torvalds 	struct sk_buff_head data_q;
3222c33c06aSGustavo F. Padovan 	struct list_head chan_list;
3231da177e4SLinus Torvalds 
32419c40e3bSGustavo F. Padovan 	struct delayed_work disc_work;
32504837f64SMarcel Holtmann 	struct timer_list idle_timer;
3269f61656aSJohan Hedberg 	struct timer_list auto_accept_timer;
3271da177e4SLinus Torvalds 
328b219e3acSMarcel Holtmann 	struct device	dev;
3299eba32b8SMarcel Holtmann 	atomic_t	devref;
330b219e3acSMarcel Holtmann 
3311da177e4SLinus Torvalds 	struct hci_dev	*hdev;
3321da177e4SLinus Torvalds 	void		*l2cap_data;
3331da177e4SLinus Torvalds 	void		*sco_data;
3342b64d153SBrian Gix 	void		*smp_conn;
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds 	struct hci_conn	*link;
337e9a416b5SJohan Hedberg 
338e9a416b5SJohan Hedberg 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
339e9a416b5SJohan Hedberg 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
340e9a416b5SJohan Hedberg 	void (*disconn_cfm_cb)	(struct hci_conn *conn, u8 reason);
3411da177e4SLinus Torvalds };
3421da177e4SLinus Torvalds 
34373d80debSLuiz Augusto von Dentz struct hci_chan {
34473d80debSLuiz Augusto von Dentz 	struct list_head list;
34573d80debSLuiz Augusto von Dentz 
34673d80debSLuiz Augusto von Dentz 	struct hci_conn *conn;
34773d80debSLuiz Augusto von Dentz 	struct sk_buff_head data_q;
34873d80debSLuiz Augusto von Dentz 	unsigned int	sent;
34973d80debSLuiz Augusto von Dentz };
35073d80debSLuiz Augusto von Dentz 
3511da177e4SLinus Torvalds extern struct list_head hci_dev_list;
3521da177e4SLinus Torvalds extern struct list_head hci_cb_list;
3531da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock;
3541da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock;
3551da177e4SLinus Torvalds 
356686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */
357686ebf28SUlisses Furquim extern int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
358686ebf28SUlisses Furquim extern int l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
359686ebf28SUlisses Furquim extern int l2cap_disconn_ind(struct hci_conn *hcon);
360686ebf28SUlisses Furquim extern int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
361686ebf28SUlisses Furquim extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
362686ebf28SUlisses Furquim extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
363686ebf28SUlisses Furquim 
364686ebf28SUlisses Furquim extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
365686ebf28SUlisses Furquim extern int sco_connect_cfm(struct hci_conn *hcon, __u8 status);
366686ebf28SUlisses Furquim extern int sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
367686ebf28SUlisses Furquim extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
368686ebf28SUlisses Furquim 
3691da177e4SLinus Torvalds /* ----- Inquiry cache ----- */
37070f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX   (HZ*30)   /* 30 seconds */
37170f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   /* 60 seconds */
3721da177e4SLinus Torvalds 
37330883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev)
3741da177e4SLinus Torvalds {
375ff9ef578SJohan Hedberg 	hdev->discovery.state = DISCOVERY_STOPPED;
37630883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.all);
37730883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.unknown);
37830883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.resolve);
3791da177e4SLinus Torvalds }
3801da177e4SLinus Torvalds 
38130dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev);
38230dc78e1SJohan Hedberg 
383ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state);
384ff9ef578SJohan Hedberg 
3851da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev)
3861da177e4SLinus Torvalds {
38730883512SJohan Hedberg 	return list_empty(&hdev->discovery.all);
3881da177e4SLinus Torvalds }
3891da177e4SLinus Torvalds 
3901da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev)
3911da177e4SLinus Torvalds {
39230883512SJohan Hedberg 	struct discovery_state *c = &hdev->discovery;
3931da177e4SLinus Torvalds 	return jiffies - c->timestamp;
3941da177e4SLinus Torvalds }
3951da177e4SLinus Torvalds 
3961da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e)
3971da177e4SLinus Torvalds {
3981da177e4SLinus Torvalds 	return jiffies - e->timestamp;
3991da177e4SLinus Torvalds }
4001da177e4SLinus Torvalds 
4015a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
4025a9d0a3fSWaldemar Rymarkiewicz 							bdaddr_t *bdaddr);
403561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
404561aafbcSJohan Hedberg 							bdaddr_t *bdaddr);
40530dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
40630dc78e1SJohan Hedberg 							bdaddr_t *bdaddr,
40730dc78e1SJohan Hedberg 							int state);
408a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
409a3d4e20aSJohan Hedberg 						struct inquiry_entry *ie);
4103175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
411561aafbcSJohan Hedberg 							bool name_known);
4121da177e4SLinus Torvalds 
4131da177e4SLinus Torvalds /* ----- HCI Connections ----- */
4141da177e4SLinus Torvalds enum {
4151da177e4SLinus Torvalds 	HCI_CONN_AUTH_PEND,
41619f8def0SWaldemar Rymarkiewicz 	HCI_CONN_REAUTH_PEND,
4171da177e4SLinus Torvalds 	HCI_CONN_ENCRYPT_PEND,
41804837f64SMarcel Holtmann 	HCI_CONN_RSWITCH_PEND,
41904837f64SMarcel Holtmann 	HCI_CONN_MODE_CHANGE_PEND,
420e73439d8SMarcel Holtmann 	HCI_CONN_SCO_SETUP_PEND,
421d26a2345SVinicius Costa Gomes 	HCI_CONN_LE_SMP_PEND,
422b644ba33SJohan Hedberg 	HCI_CONN_MGMT_CONNECTED,
42358a681efSJohan Hedberg 	HCI_CONN_SSP_ENABLED,
42458a681efSJohan Hedberg 	HCI_CONN_POWER_SAVE,
42558a681efSJohan Hedberg 	HCI_CONN_REMOTE_OOB,
4261da177e4SLinus Torvalds };
4271da177e4SLinus Torvalds 
428aa64a8b5SJohan Hedberg static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
429aa64a8b5SJohan Hedberg {
430aa64a8b5SJohan Hedberg 	struct hci_dev *hdev = conn->hdev;
431aa64a8b5SJohan Hedberg 	return (test_bit(HCI_SSP_ENABLED, &hdev->flags) &&
432aa64a8b5SJohan Hedberg 				test_bit(HCI_CONN_SSP_ENABLED, &conn->flags));
433aa64a8b5SJohan Hedberg }
434aa64a8b5SJohan Hedberg 
4351da177e4SLinus Torvalds static inline void hci_conn_hash_init(struct hci_dev *hdev)
4361da177e4SLinus Torvalds {
4371da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
4381da177e4SLinus Torvalds 	INIT_LIST_HEAD(&h->list);
4391da177e4SLinus Torvalds 	h->acl_num = 0;
4401da177e4SLinus Torvalds 	h->sco_num = 0;
441dc8ed672SGustavo F. Padovan 	h->le_num = 0;
4421da177e4SLinus Torvalds }
4431da177e4SLinus Torvalds 
4441da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
4451da177e4SLinus Torvalds {
4461da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
447bf4c6325SGustavo F. Padovan 	list_add_rcu(&c->list, &h->list);
448fcd89c09SVille Tervo 	switch (c->type) {
449fcd89c09SVille Tervo 	case ACL_LINK:
4501da177e4SLinus Torvalds 		h->acl_num++;
451fcd89c09SVille Tervo 		break;
452fcd89c09SVille Tervo 	case LE_LINK:
453fcd89c09SVille Tervo 		h->le_num++;
454fcd89c09SVille Tervo 		break;
455fcd89c09SVille Tervo 	case SCO_LINK:
456fcd89c09SVille Tervo 	case ESCO_LINK:
4571da177e4SLinus Torvalds 		h->sco_num++;
458fcd89c09SVille Tervo 		break;
459fcd89c09SVille Tervo 	}
4601da177e4SLinus Torvalds }
4611da177e4SLinus Torvalds 
4621da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
4631da177e4SLinus Torvalds {
4641da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
465bf4c6325SGustavo F. Padovan 
466bf4c6325SGustavo F. Padovan 	list_del_rcu(&c->list);
467bf4c6325SGustavo F. Padovan 	synchronize_rcu();
468bf4c6325SGustavo F. Padovan 
469fcd89c09SVille Tervo 	switch (c->type) {
470fcd89c09SVille Tervo 	case ACL_LINK:
4711da177e4SLinus Torvalds 		h->acl_num--;
472fcd89c09SVille Tervo 		break;
473fcd89c09SVille Tervo 	case LE_LINK:
474fcd89c09SVille Tervo 		h->le_num--;
475fcd89c09SVille Tervo 		break;
476fcd89c09SVille Tervo 	case SCO_LINK:
477fcd89c09SVille Tervo 	case ESCO_LINK:
4781da177e4SLinus Torvalds 		h->sco_num--;
479fcd89c09SVille Tervo 		break;
480fcd89c09SVille Tervo 	}
4811da177e4SLinus Torvalds }
4821da177e4SLinus Torvalds 
48352087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
48452087a79SLuiz Augusto von Dentz {
48552087a79SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
48652087a79SLuiz Augusto von Dentz 	switch (type) {
48752087a79SLuiz Augusto von Dentz 	case ACL_LINK:
48852087a79SLuiz Augusto von Dentz 		return h->acl_num;
48952087a79SLuiz Augusto von Dentz 	case LE_LINK:
49052087a79SLuiz Augusto von Dentz 		return h->le_num;
49152087a79SLuiz Augusto von Dentz 	case SCO_LINK:
49252087a79SLuiz Augusto von Dentz 	case ESCO_LINK:
49352087a79SLuiz Augusto von Dentz 		return h->sco_num;
49452087a79SLuiz Augusto von Dentz 	default:
49552087a79SLuiz Augusto von Dentz 		return 0;
49652087a79SLuiz Augusto von Dentz 	}
49752087a79SLuiz Augusto von Dentz }
49852087a79SLuiz Augusto von Dentz 
4991da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
5001da177e4SLinus Torvalds 								__u16 handle)
5011da177e4SLinus Torvalds {
5021da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
5031da177e4SLinus Torvalds 	struct hci_conn  *c;
5041da177e4SLinus Torvalds 
505bf4c6325SGustavo F. Padovan 	rcu_read_lock();
506bf4c6325SGustavo F. Padovan 
507bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
508bf4c6325SGustavo F. Padovan 		if (c->handle == handle) {
509bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5101da177e4SLinus Torvalds 			return c;
5111da177e4SLinus Torvalds 		}
512bf4c6325SGustavo F. Padovan 	}
513bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
514bf4c6325SGustavo F. Padovan 
5151da177e4SLinus Torvalds 	return NULL;
5161da177e4SLinus Torvalds }
5171da177e4SLinus Torvalds 
5181da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
5191da177e4SLinus Torvalds 							__u8 type, bdaddr_t *ba)
5201da177e4SLinus Torvalds {
5211da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
5221da177e4SLinus Torvalds 	struct hci_conn  *c;
5231da177e4SLinus Torvalds 
524bf4c6325SGustavo F. Padovan 	rcu_read_lock();
525bf4c6325SGustavo F. Padovan 
526bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
527bf4c6325SGustavo F. Padovan 		if (c->type == type && !bacmp(&c->dst, ba)) {
528bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5291da177e4SLinus Torvalds 			return c;
5301da177e4SLinus Torvalds 		}
531bf4c6325SGustavo F. Padovan 	}
532bf4c6325SGustavo F. Padovan 
533bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
534bf4c6325SGustavo F. Padovan 
5351da177e4SLinus Torvalds 	return NULL;
5361da177e4SLinus Torvalds }
5371da177e4SLinus Torvalds 
5384c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
5394c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
5404c67bc74SMarcel Holtmann {
5414c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
5424c67bc74SMarcel Holtmann 	struct hci_conn  *c;
5434c67bc74SMarcel Holtmann 
544bf4c6325SGustavo F. Padovan 	rcu_read_lock();
545bf4c6325SGustavo F. Padovan 
546bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
547bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
548bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5494c67bc74SMarcel Holtmann 			return c;
5504c67bc74SMarcel Holtmann 		}
551bf4c6325SGustavo F. Padovan 	}
552bf4c6325SGustavo F. Padovan 
553bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
554bf4c6325SGustavo F. Padovan 
5554c67bc74SMarcel Holtmann 	return NULL;
5564c67bc74SMarcel Holtmann }
5574c67bc74SMarcel Holtmann 
5584c67bc74SMarcel Holtmann void hci_acl_connect(struct hci_conn *conn);
5591da177e4SLinus Torvalds void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
5601da177e4SLinus Torvalds void hci_add_sco(struct hci_conn *conn, __u16 handle);
561b6a0dc82SMarcel Holtmann void hci_setup_sync(struct hci_conn *conn, __u16 handle);
562e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
5631da177e4SLinus Torvalds 
5641da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
5651da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn);
5661da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
567a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
5681da177e4SLinus Torvalds 
56973d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
57073d80debSLuiz Augusto von Dentz int hci_chan_del(struct hci_chan *chan);
5712c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
57273d80debSLuiz Augusto von Dentz 
5735a9d0a3fSWaldemar Rymarkiewicz struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
5745a9d0a3fSWaldemar Rymarkiewicz 						__u8 sec_level, __u8 auth_type);
575e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
576b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
5770684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
5781da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn);
5798c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
5801da177e4SLinus Torvalds 
58114b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
5821da177e4SLinus Torvalds 
5839eba32b8SMarcel Holtmann void hci_conn_hold_device(struct hci_conn *conn);
5849eba32b8SMarcel Holtmann void hci_conn_put_device(struct hci_conn *conn);
5859eba32b8SMarcel Holtmann 
5861da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn)
5871da177e4SLinus Torvalds {
5881da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
5892f304d1eSAndre Guedes 	cancel_delayed_work(&conn->disc_work);
5901da177e4SLinus Torvalds }
5911da177e4SLinus Torvalds 
5921da177e4SLinus Torvalds static inline void hci_conn_put(struct hci_conn *conn)
5931da177e4SLinus Torvalds {
5941da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
59504837f64SMarcel Holtmann 		unsigned long timeo;
596454d48ffSVinicius Costa Gomes 		if (conn->type == ACL_LINK || conn->type == LE_LINK) {
5976ac59344SMarcel Holtmann 			del_timer(&conn->idle_timer);
5986ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
599052b30b0SMarcel Holtmann 				timeo = msecs_to_jiffies(conn->disc_timeout);
60004837f64SMarcel Holtmann 				if (!conn->out)
601052b30b0SMarcel Holtmann 					timeo *= 2;
6025a9d0a3fSWaldemar Rymarkiewicz 			} else {
6036ac59344SMarcel Holtmann 				timeo = msecs_to_jiffies(10);
6045a9d0a3fSWaldemar Rymarkiewicz 			}
6055a9d0a3fSWaldemar Rymarkiewicz 		} else {
60604837f64SMarcel Holtmann 			timeo = msecs_to_jiffies(10);
6075a9d0a3fSWaldemar Rymarkiewicz 		}
6082f304d1eSAndre Guedes 		cancel_delayed_work(&conn->disc_work);
60919c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
6101931782bSVinicius Costa Gomes 					&conn->disc_work, timeo);
6111da177e4SLinus Torvalds 	}
6121da177e4SLinus Torvalds }
6131da177e4SLinus Torvalds 
6141da177e4SLinus Torvalds /* ----- HCI Devices ----- */
615dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
6161da177e4SLinus Torvalds {
6174c724c71SDavid Herrmann 	put_device(&d->dev);
618010666a1SDavid Herrmann }
6191da177e4SLinus Torvalds 
620dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
6211da177e4SLinus Torvalds {
6224c724c71SDavid Herrmann 	get_device(&d->dev);
6231da177e4SLinus Torvalds 	return d;
6241da177e4SLinus Torvalds }
6251da177e4SLinus Torvalds 
62609fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
62709fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
6281da177e4SLinus Torvalds 
6291da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
6301da177e4SLinus Torvalds struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
6311da177e4SLinus Torvalds 
6321da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void);
6331da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
6341da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
63559735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
6361da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
6371da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
6381da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
6391da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
6401da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
6411da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
6421da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
6431da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
6441da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
6451da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
6461da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
64740be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
6481da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
6491da177e4SLinus Torvalds 
650f0358568SJohan Hedberg struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
651f0358568SJohan Hedberg int hci_blacklist_clear(struct hci_dev *hdev);
652b2a66aadSAntti Julku int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr);
653b2a66aadSAntti Julku int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr);
654f0358568SJohan Hedberg 
6552aeb9a1aSJohan Hedberg int hci_uuids_clear(struct hci_dev *hdev);
6562aeb9a1aSJohan Hedberg 
65755ed8ca1SJohan Hedberg int hci_link_keys_clear(struct hci_dev *hdev);
65855ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
659d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
660d25e28abSJohan Hedberg 			bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
661c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
662c9839a11SVinicius Costa Gomes int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type,
663c9839a11SVinicius Costa Gomes 				int new_key, u8 authenticated, u8 tk[16],
664c9839a11SVinicius Costa Gomes 				u8 enc_size, u16 ediv, u8 rand[8]);
665c9839a11SVinicius Costa Gomes struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
666c9839a11SVinicius Costa Gomes 								u8 addr_type);
667b899efafSVinicius Costa Gomes int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr);
668b899efafSVinicius Costa Gomes int hci_smp_ltks_clear(struct hci_dev *hdev);
66955ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
67055ed8ca1SJohan Hedberg 
6712763eda6SSzymon Janc int hci_remote_oob_data_clear(struct hci_dev *hdev);
6722763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
6732763eda6SSzymon Janc 							bdaddr_t *bdaddr);
6742763eda6SSzymon Janc int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
6752763eda6SSzymon Janc 								u8 *randomizer);
6762763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
6772763eda6SSzymon Janc 
67835815085SAndre Guedes #define ADV_CLEAR_TIMEOUT (3*60*HZ) /* Three minutes */
67976c8686fSAndre Guedes int hci_adv_entries_clear(struct hci_dev *hdev);
68076c8686fSAndre Guedes struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr);
68176c8686fSAndre Guedes int hci_add_adv_entry(struct hci_dev *hdev,
68276c8686fSAndre Guedes 					struct hci_ev_le_advertising_info *ev);
68376c8686fSAndre Guedes 
684ab81cbf9SJohan Hedberg void hci_del_off_timer(struct hci_dev *hdev);
685ab81cbf9SJohan Hedberg 
6861da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
6871da177e4SLinus Torvalds 
68876bca880SMarcel Holtmann int hci_recv_frame(struct sk_buff *skb);
689ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
69099811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
691ef222013SMarcel Holtmann 
6920ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
693ce242970SDavid Herrmann int hci_add_sysfs(struct hci_dev *hdev);
694ce242970SDavid Herrmann void hci_del_sysfs(struct hci_dev *hdev);
695a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
696b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
697b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
6981da177e4SLinus Torvalds 
699a91f2e39SMarcel Holtmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->parent = (pdev))
7001da177e4SLinus Torvalds 
7011da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
70204837f64SMarcel Holtmann #define lmp_rswitch_capable(dev)   ((dev)->features[0] & LMP_RSWITCH)
70304837f64SMarcel Holtmann #define lmp_encrypt_capable(dev)   ((dev)->features[0] & LMP_ENCRYPT)
70404837f64SMarcel Holtmann #define lmp_sniff_capable(dev)     ((dev)->features[0] & LMP_SNIFF)
70504837f64SMarcel Holtmann #define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
7065b7f9909SMarcel Holtmann #define lmp_esco_capable(dev)      ((dev)->features[3] & LMP_ESCO)
707769be974SMarcel Holtmann #define lmp_ssp_capable(dev)       ((dev)->features[6] & LMP_SIMPLE_PAIR)
708e702112fSAndrei Emeltchenko #define lmp_no_flush_capable(dev)  ((dev)->features[6] & LMP_NO_FLUSH)
7096ed58ec5SVille Tervo #define lmp_le_capable(dev)        ((dev)->features[4] & LMP_LE)
7101da177e4SLinus Torvalds 
711eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
71259e29406SAndre Guedes #define lmp_host_le_capable(dev)   ((dev)->host_features[0] & LMP_HOST_LE)
713eead27daSAndre Guedes 
7141da177e4SLinus Torvalds /* ----- HCI protocols ----- */
7155a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
7165a9d0a3fSWaldemar Rymarkiewicz 								__u8 type)
7171da177e4SLinus Torvalds {
718686ebf28SUlisses Furquim 	switch (type) {
719686ebf28SUlisses Furquim 	case ACL_LINK:
720686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
7211da177e4SLinus Torvalds 
722686ebf28SUlisses Furquim 	case SCO_LINK:
723686ebf28SUlisses Furquim 	case ESCO_LINK:
724686ebf28SUlisses Furquim 		return sco_connect_ind(hdev, bdaddr);
7251da177e4SLinus Torvalds 
726686ebf28SUlisses Furquim 	default:
727686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
728686ebf28SUlisses Furquim 		return -EINVAL;
729686ebf28SUlisses Furquim 	}
7301da177e4SLinus Torvalds }
7311da177e4SLinus Torvalds 
7321da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
7331da177e4SLinus Torvalds {
734686ebf28SUlisses Furquim 	switch (conn->type) {
735686ebf28SUlisses Furquim 	case ACL_LINK:
736686ebf28SUlisses Furquim 	case LE_LINK:
737686ebf28SUlisses Furquim 		l2cap_connect_cfm(conn, status);
738686ebf28SUlisses Furquim 		break;
7391da177e4SLinus Torvalds 
740686ebf28SUlisses Furquim 	case SCO_LINK:
741686ebf28SUlisses Furquim 	case ESCO_LINK:
742686ebf28SUlisses Furquim 		sco_connect_cfm(conn, status);
743686ebf28SUlisses Furquim 		break;
7441da177e4SLinus Torvalds 
745686ebf28SUlisses Furquim 	default:
746686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
747686ebf28SUlisses Furquim 		break;
748686ebf28SUlisses Furquim 	}
749e9a416b5SJohan Hedberg 
750e9a416b5SJohan Hedberg 	if (conn->connect_cfm_cb)
751e9a416b5SJohan Hedberg 		conn->connect_cfm_cb(conn, status);
7521da177e4SLinus Torvalds }
7531da177e4SLinus Torvalds 
7542950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
7552950f21aSMarcel Holtmann {
756686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
757686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
7582950f21aSMarcel Holtmann 
759686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
7602950f21aSMarcel Holtmann }
7612950f21aSMarcel Holtmann 
7622950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
7631da177e4SLinus Torvalds {
764686ebf28SUlisses Furquim 	switch (conn->type) {
765686ebf28SUlisses Furquim 	case ACL_LINK:
766686ebf28SUlisses Furquim 	case LE_LINK:
767686ebf28SUlisses Furquim 		l2cap_disconn_cfm(conn, reason);
768686ebf28SUlisses Furquim 		break;
7691da177e4SLinus Torvalds 
770686ebf28SUlisses Furquim 	case SCO_LINK:
771686ebf28SUlisses Furquim 	case ESCO_LINK:
772686ebf28SUlisses Furquim 		sco_disconn_cfm(conn, reason);
773686ebf28SUlisses Furquim 		break;
7741da177e4SLinus Torvalds 
775686ebf28SUlisses Furquim 	default:
776686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
777686ebf28SUlisses Furquim 		break;
778686ebf28SUlisses Furquim 	}
779e9a416b5SJohan Hedberg 
780e9a416b5SJohan Hedberg 	if (conn->disconn_cfm_cb)
781e9a416b5SJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
7821da177e4SLinus Torvalds }
7831da177e4SLinus Torvalds 
7841da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
7851da177e4SLinus Torvalds {
7868c1b2355SMarcel Holtmann 	__u8 encrypt;
7878c1b2355SMarcel Holtmann 
788686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
789686ebf28SUlisses Furquim 		return;
790686ebf28SUlisses Furquim 
79151a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
7928c1b2355SMarcel Holtmann 		return;
7938c1b2355SMarcel Holtmann 
7948c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
795686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
796e9a416b5SJohan Hedberg 
797e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
798e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
7991da177e4SLinus Torvalds }
8001da177e4SLinus Torvalds 
8015a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
8025a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
8031da177e4SLinus Torvalds {
804686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
805686ebf28SUlisses Furquim 		return;
8061da177e4SLinus Torvalds 
807686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
808e9a416b5SJohan Hedberg 
809e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
810e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
8111da177e4SLinus Torvalds }
8121da177e4SLinus Torvalds 
8131da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
8141da177e4SLinus Torvalds struct hci_cb {
8151da177e4SLinus Torvalds 	struct list_head list;
8161da177e4SLinus Torvalds 
8171da177e4SLinus Torvalds 	char *name;
8181da177e4SLinus Torvalds 
8195a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
8205a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
8211da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
8221da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
8231da177e4SLinus Torvalds };
8241da177e4SLinus Torvalds 
8251da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
8261da177e4SLinus Torvalds {
8271da177e4SLinus Torvalds 	struct list_head *p;
8288c1b2355SMarcel Holtmann 	__u8 encrypt;
8291da177e4SLinus Torvalds 
8301da177e4SLinus Torvalds 	hci_proto_auth_cfm(conn, status);
8311da177e4SLinus Torvalds 
83251a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8338c1b2355SMarcel Holtmann 		return;
8348c1b2355SMarcel Holtmann 
8358c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
8368c1b2355SMarcel Holtmann 
837f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8381da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8391da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8408c1b2355SMarcel Holtmann 		if (cb->security_cfm)
8418c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
8421da177e4SLinus Torvalds 	}
843f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8441da177e4SLinus Torvalds }
8451da177e4SLinus Torvalds 
8465a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
8475a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
8481da177e4SLinus Torvalds {
8491da177e4SLinus Torvalds 	struct list_head *p;
8501da177e4SLinus Torvalds 
851435fef20SMarcel Holtmann 	if (conn->sec_level == BT_SECURITY_SDP)
852435fef20SMarcel Holtmann 		conn->sec_level = BT_SECURITY_LOW;
853435fef20SMarcel Holtmann 
85488167aedSVinicius Costa Gomes 	if (conn->pending_sec_level > conn->sec_level)
85588167aedSVinicius Costa Gomes 		conn->sec_level = conn->pending_sec_level;
85688167aedSVinicius Costa Gomes 
8579719f8afSMarcel Holtmann 	hci_proto_encrypt_cfm(conn, status, encrypt);
8581da177e4SLinus Torvalds 
859f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8601da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8611da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8628c1b2355SMarcel Holtmann 		if (cb->security_cfm)
8638c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
8641da177e4SLinus Torvalds 	}
865f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8661da177e4SLinus Torvalds }
8671da177e4SLinus Torvalds 
8681da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
8691da177e4SLinus Torvalds {
8701da177e4SLinus Torvalds 	struct list_head *p;
8711da177e4SLinus Torvalds 
872f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8731da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8741da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8751da177e4SLinus Torvalds 		if (cb->key_change_cfm)
8761da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
8771da177e4SLinus Torvalds 	}
878f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8791da177e4SLinus Torvalds }
8801da177e4SLinus Torvalds 
8815a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
8825a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
8831da177e4SLinus Torvalds {
8841da177e4SLinus Torvalds 	struct list_head *p;
8851da177e4SLinus Torvalds 
886f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8871da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8881da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8891da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
8901da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
8911da177e4SLinus Torvalds 	}
892f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8931da177e4SLinus Torvalds }
8941da177e4SLinus Torvalds 
8956759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
8966759a675SJohan Hedberg {
8976759a675SJohan Hedberg 	u8 field_len;
8986759a675SJohan Hedberg 	size_t parsed;
8996759a675SJohan Hedberg 
9006759a675SJohan Hedberg 	for (parsed = 0; parsed < data_len - 1; parsed += field_len) {
9016759a675SJohan Hedberg 		field_len = data[0];
9026759a675SJohan Hedberg 
9036759a675SJohan Hedberg 		if (field_len == 0)
9046759a675SJohan Hedberg 			break;
9056759a675SJohan Hedberg 
9066759a675SJohan Hedberg 		parsed += field_len + 1;
9076759a675SJohan Hedberg 
9086759a675SJohan Hedberg 		if (parsed > data_len)
9096759a675SJohan Hedberg 			break;
9106759a675SJohan Hedberg 
9116759a675SJohan Hedberg 		if (data[1] == type)
9126759a675SJohan Hedberg 			return true;
9136759a675SJohan Hedberg 
9146759a675SJohan Hedberg 		data += field_len + 1;
9156759a675SJohan Hedberg 	}
9166759a675SJohan Hedberg 
9176759a675SJohan Hedberg 	return false;
9186759a675SJohan Hedberg }
9196759a675SJohan Hedberg 
9201dc06093SJohan Hedberg static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
9211dc06093SJohan Hedberg 								u8 data_len)
9221dc06093SJohan Hedberg {
9231dc06093SJohan Hedberg 	eir[eir_len++] = sizeof(type) + data_len;
9241dc06093SJohan Hedberg 	eir[eir_len++] = type;
9251dc06093SJohan Hedberg 	memcpy(&eir[eir_len], data, data_len);
9261dc06093SJohan Hedberg 	eir_len += data_len;
9271dc06093SJohan Hedberg 
9281dc06093SJohan Hedberg 	return eir_len;
9291dc06093SJohan Hedberg }
9301dc06093SJohan Hedberg 
9311da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
9321da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
9331da177e4SLinus Torvalds 
9341da177e4SLinus Torvalds int hci_register_notifier(struct notifier_block *nb);
9351da177e4SLinus Torvalds int hci_unregister_notifier(struct notifier_block *nb);
9361da177e4SLinus Torvalds 
937a9de9248SMarcel Holtmann int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
93873d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
9390d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
9401da177e4SLinus Torvalds 
941a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
9421da177e4SLinus Torvalds 
9431da177e4SLinus Torvalds void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
9441da177e4SLinus Torvalds 
9451da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
946eec8d2bcSJohan Hedberg void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb,
947eec8d2bcSJohan Hedberg 							struct sock *skip_sk);
9481da177e4SLinus Torvalds 
9490381101fSJohan Hedberg /* Management interface */
9500381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
951744cf19eSJohan Hedberg int mgmt_index_added(struct hci_dev *hdev);
952744cf19eSJohan Hedberg int mgmt_index_removed(struct hci_dev *hdev);
953744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered);
954744cf19eSJohan Hedberg int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
955744cf19eSJohan Hedberg int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
956744cf19eSJohan Hedberg int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
957744cf19eSJohan Hedberg int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
958744cf19eSJohan Hedberg 								u8 persistent);
959afc747a6SJohan Hedberg int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
960b644ba33SJohan Hedberg 					u8 addr_type, u8 *name, u8 name_len,
961b644ba33SJohan Hedberg 					u8 *dev_class);
962afc747a6SJohan Hedberg int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
963afc747a6SJohan Hedberg 						u8 link_type, u8 addr_type);
96437d9ef76SJohan Hedberg int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
96548264f06SJohan Hedberg int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
96648264f06SJohan Hedberg 						u8 addr_type, u8 status);
967744cf19eSJohan Hedberg int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
968744cf19eSJohan Hedberg int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
969c35938b2SSzymon Janc 								u8 status);
970744cf19eSJohan Hedberg int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
971744cf19eSJohan Hedberg 								u8 status);
972744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
973744cf19eSJohan Hedberg 						__le32 value, u8 confirm_hint);
974744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
975744cf19eSJohan Hedberg 								u8 status);
976744cf19eSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev,
977744cf19eSJohan Hedberg 						bdaddr_t *bdaddr, u8 status);
978604086b7SBrian Gix int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr);
979604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
980604086b7SBrian Gix 								u8 status);
981604086b7SBrian Gix int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev,
982604086b7SBrian Gix 						bdaddr_t *bdaddr, u8 status);
983744cf19eSJohan Hedberg int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
984744cf19eSJohan Hedberg int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
985744cf19eSJohan Hedberg int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
986744cf19eSJohan Hedberg 						u8 *randomizer, u8 status);
98748264f06SJohan Hedberg int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
988561aafbcSJohan Hedberg 					u8 addr_type, u8 *dev_class, s8 rssi,
989e319d2e7SJohan Hedberg 					u8 cfm_name, u8 *eir, u16 eir_len);
990b644ba33SJohan Hedberg int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
991b644ba33SJohan Hedberg 			u8 addr_type, s8 rssi, u8 *name, u8 name_len);
9927a135109SAndre Guedes int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
993e6d465cbSAndre Guedes int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
994744cf19eSJohan Hedberg int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
995744cf19eSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr);
996744cf19eSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr);
9970381101fSJohan Hedberg 
998346af67bSVinicius Costa Gomes int mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, u8 persistent);
999346af67bSVinicius Costa Gomes 
10001da177e4SLinus Torvalds /* HCI info for socket */
10011da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk)
10021da177e4SLinus Torvalds 
100314c0b608SJohan Hedberg /* HCI socket flags */
100414c0b608SJohan Hedberg #define HCI_PI_MGMT_INIT	0
100514c0b608SJohan Hedberg 
10061da177e4SLinus Torvalds struct hci_pinfo {
10071da177e4SLinus Torvalds 	struct bt_sock    bt;
10081da177e4SLinus Torvalds 	struct hci_dev    *hdev;
10091da177e4SLinus Torvalds 	struct hci_filter filter;
10101da177e4SLinus Torvalds 	__u32             cmsg_mask;
1011c02178d2SJohan Hedberg 	unsigned short   channel;
101214c0b608SJohan Hedberg 	unsigned long     flags;
10131da177e4SLinus Torvalds };
10141da177e4SLinus Torvalds 
10151da177e4SLinus Torvalds /* HCI security filter */
10161da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF  5
10171da177e4SLinus Torvalds 
10181da177e4SLinus Torvalds struct hci_sec_filter {
10191da177e4SLinus Torvalds 	__u32 type_mask;
10201da177e4SLinus Torvalds 	__u32 event_mask[2];
10211da177e4SLinus Torvalds 	__u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
10221da177e4SLinus Torvalds };
10231da177e4SLinus Torvalds 
10241da177e4SLinus Torvalds /* ----- HCI requests ----- */
10251da177e4SLinus Torvalds #define HCI_REQ_DONE	  0
10261da177e4SLinus Torvalds #define HCI_REQ_PEND	  1
10271da177e4SLinus Torvalds #define HCI_REQ_CANCELED  2
10281da177e4SLinus Torvalds 
1029a6a67efdSThomas Gleixner #define hci_req_lock(d)		mutex_lock(&d->req_lock)
1030a6a67efdSThomas Gleixner #define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
10311da177e4SLinus Torvalds 
103223bb5763SJohan Hedberg void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
10331da177e4SLinus Torvalds 
10342ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
10352ce603ebSClaudio Takahasi 					u16 latency, u16 to_multiplier);
1036a7a595f6SVinicius Costa Gomes void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
1037a7a595f6SVinicius Costa Gomes 							__u8 ltk[16]);
1038a7a595f6SVinicius Costa Gomes void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16]);
1039a7a595f6SVinicius Costa Gomes void hci_le_ltk_neg_reply(struct hci_conn *conn);
1040a7a595f6SVinicius Costa Gomes 
10412519a1fcSAndre Guedes int hci_do_inquiry(struct hci_dev *hdev, u8 length);
1042023d5049SAndre Guedes int hci_cancel_inquiry(struct hci_dev *hdev);
10432519a1fcSAndre Guedes 
10441da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
1045