xref: /openbmc/linux/include/net/bluetooth/hci_core.h (revision 51a8efd7)
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 
9134918cd7SVinicius Costa Gomes struct key_master_id {
9234918cd7SVinicius Costa Gomes 	__le16 ediv;
9334918cd7SVinicius Costa Gomes 	u8 rand[8];
9434918cd7SVinicius Costa Gomes } __packed;
9534918cd7SVinicius Costa Gomes 
9634918cd7SVinicius Costa Gomes struct link_key_data {
9734918cd7SVinicius Costa Gomes 	bdaddr_t bdaddr;
9834918cd7SVinicius Costa Gomes 	u8 type;
9934918cd7SVinicius Costa Gomes 	u8 val[16];
10034918cd7SVinicius Costa Gomes 	u8 pin_len;
10134918cd7SVinicius Costa Gomes 	u8 dlen;
10234918cd7SVinicius Costa Gomes 	u8 data[0];
10334918cd7SVinicius Costa Gomes } __packed;
10434918cd7SVinicius Costa Gomes 
10555ed8ca1SJohan Hedberg struct link_key {
10655ed8ca1SJohan Hedberg 	struct list_head list;
10755ed8ca1SJohan Hedberg 	bdaddr_t bdaddr;
10855ed8ca1SJohan Hedberg 	u8 type;
10955ed8ca1SJohan Hedberg 	u8 val[16];
11055ed8ca1SJohan Hedberg 	u8 pin_len;
11134918cd7SVinicius Costa Gomes 	u8 dlen;
11234918cd7SVinicius Costa Gomes 	u8 data[0];
11355ed8ca1SJohan Hedberg };
11455ed8ca1SJohan Hedberg 
1152763eda6SSzymon Janc struct oob_data {
1162763eda6SSzymon Janc 	struct list_head list;
1172763eda6SSzymon Janc 	bdaddr_t bdaddr;
1182763eda6SSzymon Janc 	u8 hash[16];
1192763eda6SSzymon Janc 	u8 randomizer[16];
1202763eda6SSzymon Janc };
1212763eda6SSzymon Janc 
12276c8686fSAndre Guedes struct adv_entry {
12376c8686fSAndre Guedes 	struct list_head list;
12476c8686fSAndre Guedes 	bdaddr_t bdaddr;
12576c8686fSAndre Guedes 	u8 bdaddr_type;
12676c8686fSAndre Guedes };
12776c8686fSAndre Guedes 
128cd4c5391SSuraj Sumangala #define NUM_REASSEMBLY 4
1291da177e4SLinus Torvalds struct hci_dev {
1301da177e4SLinus Torvalds 	struct list_head list;
13109fd0de5SGustavo F. Padovan 	struct mutex	lock;
1321da177e4SLinus Torvalds 
1331da177e4SLinus Torvalds 	char		name[8];
1341da177e4SLinus Torvalds 	unsigned long	flags;
1351da177e4SLinus Torvalds 	__u16		id;
136c13854ceSMarcel Holtmann 	__u8		bus;
137943da25dSMarcel Holtmann 	__u8		dev_type;
1381da177e4SLinus Torvalds 	bdaddr_t	bdaddr;
1391f6c6378SJohan Hedberg 	__u8		dev_name[HCI_MAX_NAME_LENGTH];
14080a1e1dbSJohan Hedberg 	__u8		eir[HCI_MAX_EIR_LENGTH];
141a9de9248SMarcel Holtmann 	__u8		dev_class[3];
1421aff6f09SJohan Hedberg 	__u8		major_class;
1431aff6f09SJohan Hedberg 	__u8		minor_class;
1441da177e4SLinus Torvalds 	__u8		features[8];
14559e29406SAndre Guedes 	__u8		host_features[8];
146a9de9248SMarcel Holtmann 	__u8		commands[64];
147333140b5SMarcel Holtmann 	__u8		ssp_mode;
1481143e5a6SMarcel Holtmann 	__u8		hci_ver;
1491143e5a6SMarcel Holtmann 	__u16		hci_rev;
150d5859e22SJohan Hedberg 	__u8		lmp_ver;
1511143e5a6SMarcel Holtmann 	__u16		manufacturer;
152d5859e22SJohan Hedberg 	__le16		lmp_subver;
1531da177e4SLinus Torvalds 	__u16		voice_setting;
15417fa4b9dSJohan Hedberg 	__u8		io_capability;
1551da177e4SLinus Torvalds 
1561da177e4SLinus Torvalds 	__u16		pkt_type;
1575b7f9909SMarcel Holtmann 	__u16		esco_type;
1581da177e4SLinus Torvalds 	__u16		link_policy;
1591da177e4SLinus Torvalds 	__u16		link_mode;
1601da177e4SLinus Torvalds 
16104837f64SMarcel Holtmann 	__u32		idle_timeout;
16204837f64SMarcel Holtmann 	__u16		sniff_min_interval;
16304837f64SMarcel Holtmann 	__u16		sniff_max_interval;
16404837f64SMarcel Holtmann 
165928abaa7SAndrei Emeltchenko 	__u8		amp_status;
166928abaa7SAndrei Emeltchenko 	__u32		amp_total_bw;
167928abaa7SAndrei Emeltchenko 	__u32		amp_max_bw;
168928abaa7SAndrei Emeltchenko 	__u32		amp_min_latency;
169928abaa7SAndrei Emeltchenko 	__u32		amp_max_pdu;
170928abaa7SAndrei Emeltchenko 	__u8		amp_type;
171928abaa7SAndrei Emeltchenko 	__u16		amp_pal_cap;
172928abaa7SAndrei Emeltchenko 	__u16		amp_assoc_size;
173928abaa7SAndrei Emeltchenko 	__u32		amp_max_flush_to;
174928abaa7SAndrei Emeltchenko 	__u32		amp_be_flush_to;
175928abaa7SAndrei Emeltchenko 
1761e89cffbSAndrei Emeltchenko 	__u8		flow_ctl_mode;
1771e89cffbSAndrei Emeltchenko 
1789f61656aSJohan Hedberg 	unsigned int	auto_accept_delay;
1799f61656aSJohan Hedberg 
1801da177e4SLinus Torvalds 	unsigned long	quirks;
1811da177e4SLinus Torvalds 
1821da177e4SLinus Torvalds 	atomic_t	cmd_cnt;
1831da177e4SLinus Torvalds 	unsigned int	acl_cnt;
1841da177e4SLinus Torvalds 	unsigned int	sco_cnt;
1856ed58ec5SVille Tervo 	unsigned int	le_cnt;
1861da177e4SLinus Torvalds 
1871da177e4SLinus Torvalds 	unsigned int	acl_mtu;
1881da177e4SLinus Torvalds 	unsigned int	sco_mtu;
1896ed58ec5SVille Tervo 	unsigned int	le_mtu;
1901da177e4SLinus Torvalds 	unsigned int	acl_pkts;
1911da177e4SLinus Torvalds 	unsigned int	sco_pkts;
1926ed58ec5SVille Tervo 	unsigned int	le_pkts;
1931da177e4SLinus Torvalds 
194350ee4cfSAndrei Emeltchenko 	__u16		block_len;
195350ee4cfSAndrei Emeltchenko 	__u16		block_mtu;
196350ee4cfSAndrei Emeltchenko 	__u16		num_blocks;
197350ee4cfSAndrei Emeltchenko 	__u16		block_cnt;
198350ee4cfSAndrei Emeltchenko 
1991da177e4SLinus Torvalds 	unsigned long	acl_last_tx;
2001da177e4SLinus Torvalds 	unsigned long	sco_last_tx;
2016ed58ec5SVille Tervo 	unsigned long	le_last_tx;
2021da177e4SLinus Torvalds 
203f48fd9c8SMarcel Holtmann 	struct workqueue_struct	*workqueue;
204f48fd9c8SMarcel Holtmann 
205ab81cbf9SJohan Hedberg 	struct work_struct	power_on;
2063243553fSJohan Hedberg 	struct delayed_work	power_off;
207ab81cbf9SJohan Hedberg 
20816ab91abSJohan Hedberg 	__u16			discov_timeout;
20916ab91abSJohan Hedberg 	struct delayed_work	discov_off;
21016ab91abSJohan Hedberg 
2117d78525dSJohan Hedberg 	struct delayed_work	service_cache;
2127d78525dSJohan Hedberg 
2136bd32326SVille Tervo 	struct timer_list	cmd_timer;
214b78752ccSMarcel Holtmann 
215b78752ccSMarcel Holtmann 	struct work_struct	rx_work;
216c347b765SGustavo F. Padovan 	struct work_struct	cmd_work;
2173eff45eaSGustavo F. Padovan 	struct work_struct	tx_work;
2181da177e4SLinus Torvalds 
2191da177e4SLinus Torvalds 	struct sk_buff_head	rx_q;
2201da177e4SLinus Torvalds 	struct sk_buff_head	raw_q;
2211da177e4SLinus Torvalds 	struct sk_buff_head	cmd_q;
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds 	struct sk_buff		*sent_cmd;
224cd4c5391SSuraj Sumangala 	struct sk_buff		*reassembly[NUM_REASSEMBLY];
2251da177e4SLinus Torvalds 
226a6a67efdSThomas Gleixner 	struct mutex		req_lock;
2271da177e4SLinus Torvalds 	wait_queue_head_t	req_wait_q;
2281da177e4SLinus Torvalds 	__u32			req_status;
2291da177e4SLinus Torvalds 	__u32			req_result;
230a5040efaSJohan Hedberg 
231a5040efaSJohan Hedberg 	__u16			init_last_cmd;
2321da177e4SLinus Torvalds 
2332e58ef3eSJohan Hedberg 	struct list_head	mgmt_pending;
2342e58ef3eSJohan Hedberg 
23530883512SJohan Hedberg 	struct discovery_state	discovery;
2361da177e4SLinus Torvalds 	struct hci_conn_hash	conn_hash;
237ea4bd8baSDavid Miller 	struct list_head	blacklist;
2381da177e4SLinus Torvalds 
2392aeb9a1aSJohan Hedberg 	struct list_head	uuids;
2402aeb9a1aSJohan Hedberg 
24155ed8ca1SJohan Hedberg 	struct list_head	link_keys;
24255ed8ca1SJohan Hedberg 
2432763eda6SSzymon Janc 	struct list_head	remote_oob_data;
2442763eda6SSzymon Janc 
24576c8686fSAndre Guedes 	struct list_head	adv_entries;
246db323f2fSGustavo F. Padovan 	struct delayed_work	adv_work;
24776c8686fSAndre Guedes 
2481da177e4SLinus Torvalds 	struct hci_dev_stats	stat;
2491da177e4SLinus Torvalds 
2501da177e4SLinus Torvalds 	struct sk_buff_head	driver_init;
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds 	void			*driver_data;
2531da177e4SLinus Torvalds 	void			*core_data;
2541da177e4SLinus Torvalds 
2551da177e4SLinus Torvalds 	atomic_t		promisc;
2561da177e4SLinus Torvalds 
257ca325f69SMarcel Holtmann 	struct dentry		*debugfs;
258ca325f69SMarcel Holtmann 
259a91f2e39SMarcel Holtmann 	struct device		*parent;
260a91f2e39SMarcel Holtmann 	struct device		dev;
2611da177e4SLinus Torvalds 
262611b30f7SMarcel Holtmann 	struct rfkill		*rfkill;
263611b30f7SMarcel Holtmann 
264d23264a8SAndre Guedes 	unsigned long		dev_flags;
265d23264a8SAndre Guedes 
2661da177e4SLinus Torvalds 	int (*open)(struct hci_dev *hdev);
2671da177e4SLinus Torvalds 	int (*close)(struct hci_dev *hdev);
2681da177e4SLinus Torvalds 	int (*flush)(struct hci_dev *hdev);
2691da177e4SLinus Torvalds 	int (*send)(struct sk_buff *skb);
2701da177e4SLinus Torvalds 	void (*notify)(struct hci_dev *hdev, unsigned int evt);
2711da177e4SLinus Torvalds 	int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
2721da177e4SLinus Torvalds };
2731da177e4SLinus Torvalds 
2741da177e4SLinus Torvalds struct hci_conn {
2751da177e4SLinus Torvalds 	struct list_head list;
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds 	atomic_t	refcnt;
2781da177e4SLinus Torvalds 
2791da177e4SLinus Torvalds 	bdaddr_t	dst;
28029b7988aSAndre Guedes 	__u8		dst_type;
2811da177e4SLinus Torvalds 	__u16		handle;
2821da177e4SLinus Torvalds 	__u16		state;
28304837f64SMarcel Holtmann 	__u8		mode;
2841da177e4SLinus Torvalds 	__u8		type;
2851da177e4SLinus Torvalds 	__u8		out;
2864c67bc74SMarcel Holtmann 	__u8		attempt;
2871da177e4SLinus Torvalds 	__u8		dev_class[3];
28804837f64SMarcel Holtmann 	__u8		features[8];
28941a96212SMarcel Holtmann 	__u8		ssp_mode;
29004837f64SMarcel Holtmann 	__u16		interval;
291a8746417SMarcel Holtmann 	__u16		pkt_type;
29204837f64SMarcel Holtmann 	__u16		link_policy;
2931da177e4SLinus Torvalds 	__u32		link_mode;
29413d39315SWaldemar Rymarkiewicz 	__u8		key_type;
29540be492fSMarcel Holtmann 	__u8		auth_type;
2968c1b2355SMarcel Holtmann 	__u8		sec_level;
297765c2a96SJohan Hedberg 	__u8		pending_sec_level;
298980e1a53SJohan Hedberg 	__u8		pin_length;
299726b4ffcSVinicius Costa Gomes 	__u8		enc_key_size;
30017fa4b9dSJohan Hedberg 	__u8		io_capability;
30104837f64SMarcel Holtmann 	__u8		power_save;
302052b30b0SMarcel Holtmann 	__u16		disc_timeout;
30351a8efd7SJohan Hedberg 	unsigned long	flags;
3041da177e4SLinus Torvalds 
30503b555e1SJohan Hedberg 	__u8		remote_cap;
30603b555e1SJohan Hedberg 	__u8		remote_oob;
30703b555e1SJohan Hedberg 	__u8		remote_auth;
30803b555e1SJohan Hedberg 
3091da177e4SLinus Torvalds 	unsigned int	sent;
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds 	struct sk_buff_head data_q;
3122c33c06aSGustavo F. Padovan 	struct list_head chan_list;
3131da177e4SLinus Torvalds 
31419c40e3bSGustavo F. Padovan 	struct delayed_work disc_work;
31504837f64SMarcel Holtmann 	struct timer_list idle_timer;
3169f61656aSJohan Hedberg 	struct timer_list auto_accept_timer;
3171da177e4SLinus Torvalds 
318b219e3acSMarcel Holtmann 	struct device	dev;
3199eba32b8SMarcel Holtmann 	atomic_t	devref;
320b219e3acSMarcel Holtmann 
3211da177e4SLinus Torvalds 	struct hci_dev	*hdev;
3221da177e4SLinus Torvalds 	void		*l2cap_data;
3231da177e4SLinus Torvalds 	void		*sco_data;
3242b64d153SBrian Gix 	void		*smp_conn;
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 	struct hci_conn	*link;
327e9a416b5SJohan Hedberg 
328e9a416b5SJohan Hedberg 	void (*connect_cfm_cb)	(struct hci_conn *conn, u8 status);
329e9a416b5SJohan Hedberg 	void (*security_cfm_cb)	(struct hci_conn *conn, u8 status);
330e9a416b5SJohan Hedberg 	void (*disconn_cfm_cb)	(struct hci_conn *conn, u8 reason);
3311da177e4SLinus Torvalds };
3321da177e4SLinus Torvalds 
33373d80debSLuiz Augusto von Dentz struct hci_chan {
33473d80debSLuiz Augusto von Dentz 	struct list_head list;
33573d80debSLuiz Augusto von Dentz 
33673d80debSLuiz Augusto von Dentz 	struct hci_conn *conn;
33773d80debSLuiz Augusto von Dentz 	struct sk_buff_head data_q;
33873d80debSLuiz Augusto von Dentz 	unsigned int	sent;
33973d80debSLuiz Augusto von Dentz };
34073d80debSLuiz Augusto von Dentz 
3411da177e4SLinus Torvalds extern struct list_head hci_dev_list;
3421da177e4SLinus Torvalds extern struct list_head hci_cb_list;
3431da177e4SLinus Torvalds extern rwlock_t hci_dev_list_lock;
3441da177e4SLinus Torvalds extern rwlock_t hci_cb_list_lock;
3451da177e4SLinus Torvalds 
346686ebf28SUlisses Furquim /* ----- HCI interface to upper protocols ----- */
347686ebf28SUlisses Furquim extern int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
348686ebf28SUlisses Furquim extern int l2cap_connect_cfm(struct hci_conn *hcon, u8 status);
349686ebf28SUlisses Furquim extern int l2cap_disconn_ind(struct hci_conn *hcon);
350686ebf28SUlisses Furquim extern int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason);
351686ebf28SUlisses Furquim extern int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt);
352686ebf28SUlisses Furquim extern int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags);
353686ebf28SUlisses Furquim 
354686ebf28SUlisses Furquim extern int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr);
355686ebf28SUlisses Furquim extern int sco_connect_cfm(struct hci_conn *hcon, __u8 status);
356686ebf28SUlisses Furquim extern int sco_disconn_cfm(struct hci_conn *hcon, __u8 reason);
357686ebf28SUlisses Furquim extern int sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb);
358686ebf28SUlisses Furquim 
3591da177e4SLinus Torvalds /* ----- Inquiry cache ----- */
36070f23020SAndrei Emeltchenko #define INQUIRY_CACHE_AGE_MAX   (HZ*30)   /* 30 seconds */
36170f23020SAndrei Emeltchenko #define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   /* 60 seconds */
3621da177e4SLinus Torvalds 
36330883512SJohan Hedberg static inline void discovery_init(struct hci_dev *hdev)
3641da177e4SLinus Torvalds {
365ff9ef578SJohan Hedberg 	hdev->discovery.state = DISCOVERY_STOPPED;
36630883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.all);
36730883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.unknown);
36830883512SJohan Hedberg 	INIT_LIST_HEAD(&hdev->discovery.resolve);
3691da177e4SLinus Torvalds }
3701da177e4SLinus Torvalds 
37130dc78e1SJohan Hedberg bool hci_discovery_active(struct hci_dev *hdev);
37230dc78e1SJohan Hedberg 
373ff9ef578SJohan Hedberg void hci_discovery_set_state(struct hci_dev *hdev, int state);
374ff9ef578SJohan Hedberg 
3751da177e4SLinus Torvalds static inline int inquiry_cache_empty(struct hci_dev *hdev)
3761da177e4SLinus Torvalds {
37730883512SJohan Hedberg 	return list_empty(&hdev->discovery.all);
3781da177e4SLinus Torvalds }
3791da177e4SLinus Torvalds 
3801da177e4SLinus Torvalds static inline long inquiry_cache_age(struct hci_dev *hdev)
3811da177e4SLinus Torvalds {
38230883512SJohan Hedberg 	struct discovery_state *c = &hdev->discovery;
3831da177e4SLinus Torvalds 	return jiffies - c->timestamp;
3841da177e4SLinus Torvalds }
3851da177e4SLinus Torvalds 
3861da177e4SLinus Torvalds static inline long inquiry_entry_age(struct inquiry_entry *e)
3871da177e4SLinus Torvalds {
3881da177e4SLinus Torvalds 	return jiffies - e->timestamp;
3891da177e4SLinus Torvalds }
3901da177e4SLinus Torvalds 
3915a9d0a3fSWaldemar Rymarkiewicz struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
3925a9d0a3fSWaldemar Rymarkiewicz 							bdaddr_t *bdaddr);
393561aafbcSJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
394561aafbcSJohan Hedberg 							bdaddr_t *bdaddr);
39530dc78e1SJohan Hedberg struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
39630dc78e1SJohan Hedberg 							bdaddr_t *bdaddr,
39730dc78e1SJohan Hedberg 							int state);
398a3d4e20aSJohan Hedberg void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
399a3d4e20aSJohan Hedberg 						struct inquiry_entry *ie);
4003175405bSJohan Hedberg bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
401561aafbcSJohan Hedberg 							bool name_known);
4021da177e4SLinus Torvalds 
4031da177e4SLinus Torvalds /* ----- HCI Connections ----- */
4041da177e4SLinus Torvalds enum {
4051da177e4SLinus Torvalds 	HCI_CONN_AUTH_PEND,
40619f8def0SWaldemar Rymarkiewicz 	HCI_CONN_REAUTH_PEND,
4071da177e4SLinus Torvalds 	HCI_CONN_ENCRYPT_PEND,
40804837f64SMarcel Holtmann 	HCI_CONN_RSWITCH_PEND,
40904837f64SMarcel Holtmann 	HCI_CONN_MODE_CHANGE_PEND,
410e73439d8SMarcel Holtmann 	HCI_CONN_SCO_SETUP_PEND,
411d26a2345SVinicius Costa Gomes 	HCI_CONN_LE_SMP_PEND,
4121da177e4SLinus Torvalds };
4131da177e4SLinus Torvalds 
4141da177e4SLinus Torvalds static inline void hci_conn_hash_init(struct hci_dev *hdev)
4151da177e4SLinus Torvalds {
4161da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
4171da177e4SLinus Torvalds 	INIT_LIST_HEAD(&h->list);
4181da177e4SLinus Torvalds 	h->acl_num = 0;
4191da177e4SLinus Torvalds 	h->sco_num = 0;
420dc8ed672SGustavo F. Padovan 	h->le_num = 0;
4211da177e4SLinus Torvalds }
4221da177e4SLinus Torvalds 
4231da177e4SLinus Torvalds static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
4241da177e4SLinus Torvalds {
4251da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
426bf4c6325SGustavo F. Padovan 	list_add_rcu(&c->list, &h->list);
427fcd89c09SVille Tervo 	switch (c->type) {
428fcd89c09SVille Tervo 	case ACL_LINK:
4291da177e4SLinus Torvalds 		h->acl_num++;
430fcd89c09SVille Tervo 		break;
431fcd89c09SVille Tervo 	case LE_LINK:
432fcd89c09SVille Tervo 		h->le_num++;
433fcd89c09SVille Tervo 		break;
434fcd89c09SVille Tervo 	case SCO_LINK:
435fcd89c09SVille Tervo 	case ESCO_LINK:
4361da177e4SLinus Torvalds 		h->sco_num++;
437fcd89c09SVille Tervo 		break;
438fcd89c09SVille Tervo 	}
4391da177e4SLinus Torvalds }
4401da177e4SLinus Torvalds 
4411da177e4SLinus Torvalds static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
4421da177e4SLinus Torvalds {
4431da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
444bf4c6325SGustavo F. Padovan 
445bf4c6325SGustavo F. Padovan 	list_del_rcu(&c->list);
446bf4c6325SGustavo F. Padovan 	synchronize_rcu();
447bf4c6325SGustavo F. Padovan 
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 
46252087a79SLuiz Augusto von Dentz static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type)
46352087a79SLuiz Augusto von Dentz {
46452087a79SLuiz Augusto von Dentz 	struct hci_conn_hash *h = &hdev->conn_hash;
46552087a79SLuiz Augusto von Dentz 	switch (type) {
46652087a79SLuiz Augusto von Dentz 	case ACL_LINK:
46752087a79SLuiz Augusto von Dentz 		return h->acl_num;
46852087a79SLuiz Augusto von Dentz 	case LE_LINK:
46952087a79SLuiz Augusto von Dentz 		return h->le_num;
47052087a79SLuiz Augusto von Dentz 	case SCO_LINK:
47152087a79SLuiz Augusto von Dentz 	case ESCO_LINK:
47252087a79SLuiz Augusto von Dentz 		return h->sco_num;
47352087a79SLuiz Augusto von Dentz 	default:
47452087a79SLuiz Augusto von Dentz 		return 0;
47552087a79SLuiz Augusto von Dentz 	}
47652087a79SLuiz Augusto von Dentz }
47752087a79SLuiz Augusto von Dentz 
4781da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
4791da177e4SLinus Torvalds 								__u16 handle)
4801da177e4SLinus Torvalds {
4811da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
4821da177e4SLinus Torvalds 	struct hci_conn  *c;
4831da177e4SLinus Torvalds 
484bf4c6325SGustavo F. Padovan 	rcu_read_lock();
485bf4c6325SGustavo F. Padovan 
486bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
487bf4c6325SGustavo F. Padovan 		if (c->handle == handle) {
488bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
4891da177e4SLinus Torvalds 			return c;
4901da177e4SLinus Torvalds 		}
491bf4c6325SGustavo F. Padovan 	}
492bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
493bf4c6325SGustavo F. Padovan 
4941da177e4SLinus Torvalds 	return NULL;
4951da177e4SLinus Torvalds }
4961da177e4SLinus Torvalds 
4971da177e4SLinus Torvalds static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
4981da177e4SLinus Torvalds 							__u8 type, bdaddr_t *ba)
4991da177e4SLinus Torvalds {
5001da177e4SLinus Torvalds 	struct hci_conn_hash *h = &hdev->conn_hash;
5011da177e4SLinus Torvalds 	struct hci_conn  *c;
5021da177e4SLinus Torvalds 
503bf4c6325SGustavo F. Padovan 	rcu_read_lock();
504bf4c6325SGustavo F. Padovan 
505bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
506bf4c6325SGustavo F. Padovan 		if (c->type == type && !bacmp(&c->dst, ba)) {
507bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5081da177e4SLinus Torvalds 			return c;
5091da177e4SLinus Torvalds 		}
510bf4c6325SGustavo F. Padovan 	}
511bf4c6325SGustavo F. Padovan 
512bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
513bf4c6325SGustavo F. Padovan 
5141da177e4SLinus Torvalds 	return NULL;
5151da177e4SLinus Torvalds }
5161da177e4SLinus Torvalds 
5174c67bc74SMarcel Holtmann static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
5184c67bc74SMarcel Holtmann 							__u8 type, __u16 state)
5194c67bc74SMarcel Holtmann {
5204c67bc74SMarcel Holtmann 	struct hci_conn_hash *h = &hdev->conn_hash;
5214c67bc74SMarcel Holtmann 	struct hci_conn  *c;
5224c67bc74SMarcel Holtmann 
523bf4c6325SGustavo F. Padovan 	rcu_read_lock();
524bf4c6325SGustavo F. Padovan 
525bf4c6325SGustavo F. Padovan 	list_for_each_entry_rcu(c, &h->list, list) {
526bf4c6325SGustavo F. Padovan 		if (c->type == type && c->state == state) {
527bf4c6325SGustavo F. Padovan 			rcu_read_unlock();
5284c67bc74SMarcel Holtmann 			return c;
5294c67bc74SMarcel Holtmann 		}
530bf4c6325SGustavo F. Padovan 	}
531bf4c6325SGustavo F. Padovan 
532bf4c6325SGustavo F. Padovan 	rcu_read_unlock();
533bf4c6325SGustavo F. Padovan 
5344c67bc74SMarcel Holtmann 	return NULL;
5354c67bc74SMarcel Holtmann }
5364c67bc74SMarcel Holtmann 
5374c67bc74SMarcel Holtmann void hci_acl_connect(struct hci_conn *conn);
5381da177e4SLinus Torvalds void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
5391da177e4SLinus Torvalds void hci_add_sco(struct hci_conn *conn, __u16 handle);
540b6a0dc82SMarcel Holtmann void hci_setup_sync(struct hci_conn *conn, __u16 handle);
541e73439d8SMarcel Holtmann void hci_sco_setup(struct hci_conn *conn, __u8 status);
5421da177e4SLinus Torvalds 
5431da177e4SLinus Torvalds struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
5441da177e4SLinus Torvalds int hci_conn_del(struct hci_conn *conn);
5451da177e4SLinus Torvalds void hci_conn_hash_flush(struct hci_dev *hdev);
546a9de9248SMarcel Holtmann void hci_conn_check_pending(struct hci_dev *hdev);
5471da177e4SLinus Torvalds 
54873d80debSLuiz Augusto von Dentz struct hci_chan *hci_chan_create(struct hci_conn *conn);
54973d80debSLuiz Augusto von Dentz int hci_chan_del(struct hci_chan *chan);
5502c33c06aSGustavo F. Padovan void hci_chan_list_flush(struct hci_conn *conn);
55173d80debSLuiz Augusto von Dentz 
5525a9d0a3fSWaldemar Rymarkiewicz struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst,
5535a9d0a3fSWaldemar Rymarkiewicz 						__u8 sec_level, __u8 auth_type);
554e7c29cb1SMarcel Holtmann int hci_conn_check_link_mode(struct hci_conn *conn);
555b3b1b061SWaldemar Rymarkiewicz int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level);
5560684e5f9SMarcel Holtmann int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type);
5571da177e4SLinus Torvalds int hci_conn_change_link_key(struct hci_conn *conn);
5588c1b2355SMarcel Holtmann int hci_conn_switch_role(struct hci_conn *conn, __u8 role);
5591da177e4SLinus Torvalds 
56014b12d0bSJaikumar Ganesh void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active);
5611da177e4SLinus Torvalds 
5629eba32b8SMarcel Holtmann void hci_conn_hold_device(struct hci_conn *conn);
5639eba32b8SMarcel Holtmann void hci_conn_put_device(struct hci_conn *conn);
5649eba32b8SMarcel Holtmann 
5651da177e4SLinus Torvalds static inline void hci_conn_hold(struct hci_conn *conn)
5661da177e4SLinus Torvalds {
5671da177e4SLinus Torvalds 	atomic_inc(&conn->refcnt);
56819c40e3bSGustavo F. Padovan 	cancel_delayed_work_sync(&conn->disc_work);
5691da177e4SLinus Torvalds }
5701da177e4SLinus Torvalds 
5711da177e4SLinus Torvalds static inline void hci_conn_put(struct hci_conn *conn)
5721da177e4SLinus Torvalds {
5731da177e4SLinus Torvalds 	if (atomic_dec_and_test(&conn->refcnt)) {
57404837f64SMarcel Holtmann 		unsigned long timeo;
575454d48ffSVinicius Costa Gomes 		if (conn->type == ACL_LINK || conn->type == LE_LINK) {
5766ac59344SMarcel Holtmann 			del_timer(&conn->idle_timer);
5776ac59344SMarcel Holtmann 			if (conn->state == BT_CONNECTED) {
578052b30b0SMarcel Holtmann 				timeo = msecs_to_jiffies(conn->disc_timeout);
57904837f64SMarcel Holtmann 				if (!conn->out)
580052b30b0SMarcel Holtmann 					timeo *= 2;
5815a9d0a3fSWaldemar Rymarkiewicz 			} else {
5826ac59344SMarcel Holtmann 				timeo = msecs_to_jiffies(10);
5835a9d0a3fSWaldemar Rymarkiewicz 			}
5845a9d0a3fSWaldemar Rymarkiewicz 		} else {
58504837f64SMarcel Holtmann 			timeo = msecs_to_jiffies(10);
5865a9d0a3fSWaldemar Rymarkiewicz 		}
58719c40e3bSGustavo F. Padovan 		cancel_delayed_work_sync(&conn->disc_work);
58819c40e3bSGustavo F. Padovan 		queue_delayed_work(conn->hdev->workqueue,
5891931782bSVinicius Costa Gomes 					&conn->disc_work, timeo);
5901da177e4SLinus Torvalds 	}
5911da177e4SLinus Torvalds }
5921da177e4SLinus Torvalds 
5931da177e4SLinus Torvalds /* ----- HCI Devices ----- */
594dc946bd8SDavid Herrmann static inline void hci_dev_put(struct hci_dev *d)
5951da177e4SLinus Torvalds {
5964c724c71SDavid Herrmann 	put_device(&d->dev);
597010666a1SDavid Herrmann }
5981da177e4SLinus Torvalds 
599dc946bd8SDavid Herrmann static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
6001da177e4SLinus Torvalds {
6014c724c71SDavid Herrmann 	get_device(&d->dev);
6021da177e4SLinus Torvalds 	return d;
6031da177e4SLinus Torvalds }
6041da177e4SLinus Torvalds 
60509fd0de5SGustavo F. Padovan #define hci_dev_lock(d)		mutex_lock(&d->lock)
60609fd0de5SGustavo F. Padovan #define hci_dev_unlock(d)	mutex_unlock(&d->lock)
6071da177e4SLinus Torvalds 
6081da177e4SLinus Torvalds struct hci_dev *hci_dev_get(int index);
6091da177e4SLinus Torvalds struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
6101da177e4SLinus Torvalds 
6111da177e4SLinus Torvalds struct hci_dev *hci_alloc_dev(void);
6121da177e4SLinus Torvalds void hci_free_dev(struct hci_dev *hdev);
6131da177e4SLinus Torvalds int hci_register_dev(struct hci_dev *hdev);
61459735631SDavid Herrmann void hci_unregister_dev(struct hci_dev *hdev);
6151da177e4SLinus Torvalds int hci_suspend_dev(struct hci_dev *hdev);
6161da177e4SLinus Torvalds int hci_resume_dev(struct hci_dev *hdev);
6171da177e4SLinus Torvalds int hci_dev_open(__u16 dev);
6181da177e4SLinus Torvalds int hci_dev_close(__u16 dev);
6191da177e4SLinus Torvalds int hci_dev_reset(__u16 dev);
6201da177e4SLinus Torvalds int hci_dev_reset_stat(__u16 dev);
6211da177e4SLinus Torvalds int hci_dev_cmd(unsigned int cmd, void __user *arg);
6221da177e4SLinus Torvalds int hci_get_dev_list(void __user *arg);
6231da177e4SLinus Torvalds int hci_get_dev_info(void __user *arg);
6241da177e4SLinus Torvalds int hci_get_conn_list(void __user *arg);
6251da177e4SLinus Torvalds int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
62640be492fSMarcel Holtmann int hci_get_auth_info(struct hci_dev *hdev, void __user *arg);
6271da177e4SLinus Torvalds int hci_inquiry(void __user *arg);
6281da177e4SLinus Torvalds 
629f0358568SJohan Hedberg struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
630f0358568SJohan Hedberg int hci_blacklist_clear(struct hci_dev *hdev);
631b2a66aadSAntti Julku int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr);
632b2a66aadSAntti Julku int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr);
633f0358568SJohan Hedberg 
6342aeb9a1aSJohan Hedberg int hci_uuids_clear(struct hci_dev *hdev);
6352aeb9a1aSJohan Hedberg 
63655ed8ca1SJohan Hedberg int hci_link_keys_clear(struct hci_dev *hdev);
63755ed8ca1SJohan Hedberg struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
638d25e28abSJohan Hedberg int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key,
639d25e28abSJohan Hedberg 			bdaddr_t *bdaddr, u8 *val, u8 type, u8 pin_len);
64075d262c2SVinicius Costa Gomes struct link_key *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]);
64175d262c2SVinicius Costa Gomes struct link_key *hci_find_link_key_type(struct hci_dev *hdev,
64275d262c2SVinicius Costa Gomes 					bdaddr_t *bdaddr, u8 type);
64375d262c2SVinicius Costa Gomes int hci_add_ltk(struct hci_dev *hdev, int new_key, bdaddr_t *bdaddr,
644726b4ffcSVinicius Costa Gomes 			u8 key_size, __le16 ediv, u8 rand[8], u8 ltk[16]);
64555ed8ca1SJohan Hedberg int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr);
64655ed8ca1SJohan Hedberg 
6472763eda6SSzymon Janc int hci_remote_oob_data_clear(struct hci_dev *hdev);
6482763eda6SSzymon Janc struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
6492763eda6SSzymon Janc 							bdaddr_t *bdaddr);
6502763eda6SSzymon Janc int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
6512763eda6SSzymon Janc 								u8 *randomizer);
6522763eda6SSzymon Janc int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
6532763eda6SSzymon Janc 
65435815085SAndre Guedes #define ADV_CLEAR_TIMEOUT (3*60*HZ) /* Three minutes */
65576c8686fSAndre Guedes int hci_adv_entries_clear(struct hci_dev *hdev);
65676c8686fSAndre Guedes struct adv_entry *hci_find_adv_entry(struct hci_dev *hdev, bdaddr_t *bdaddr);
65776c8686fSAndre Guedes int hci_add_adv_entry(struct hci_dev *hdev,
65876c8686fSAndre Guedes 					struct hci_ev_le_advertising_info *ev);
65976c8686fSAndre Guedes 
660ab81cbf9SJohan Hedberg void hci_del_off_timer(struct hci_dev *hdev);
661ab81cbf9SJohan Hedberg 
6621da177e4SLinus Torvalds void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
6631da177e4SLinus Torvalds 
66476bca880SMarcel Holtmann int hci_recv_frame(struct sk_buff *skb);
665ef222013SMarcel Holtmann int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count);
66699811510SSuraj Sumangala int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count);
667ef222013SMarcel Holtmann 
6680ac7e700SDavid Herrmann void hci_init_sysfs(struct hci_dev *hdev);
669ce242970SDavid Herrmann int hci_add_sysfs(struct hci_dev *hdev);
670ce242970SDavid Herrmann void hci_del_sysfs(struct hci_dev *hdev);
671a67e899cSMarcel Holtmann void hci_conn_init_sysfs(struct hci_conn *conn);
672b219e3acSMarcel Holtmann void hci_conn_add_sysfs(struct hci_conn *conn);
673b219e3acSMarcel Holtmann void hci_conn_del_sysfs(struct hci_conn *conn);
6741da177e4SLinus Torvalds 
675a91f2e39SMarcel Holtmann #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->parent = (pdev))
6761da177e4SLinus Torvalds 
6771da177e4SLinus Torvalds /* ----- LMP capabilities ----- */
67804837f64SMarcel Holtmann #define lmp_rswitch_capable(dev)   ((dev)->features[0] & LMP_RSWITCH)
67904837f64SMarcel Holtmann #define lmp_encrypt_capable(dev)   ((dev)->features[0] & LMP_ENCRYPT)
68004837f64SMarcel Holtmann #define lmp_sniff_capable(dev)     ((dev)->features[0] & LMP_SNIFF)
68104837f64SMarcel Holtmann #define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
6825b7f9909SMarcel Holtmann #define lmp_esco_capable(dev)      ((dev)->features[3] & LMP_ESCO)
683769be974SMarcel Holtmann #define lmp_ssp_capable(dev)       ((dev)->features[6] & LMP_SIMPLE_PAIR)
684e702112fSAndrei Emeltchenko #define lmp_no_flush_capable(dev)  ((dev)->features[6] & LMP_NO_FLUSH)
6856ed58ec5SVille Tervo #define lmp_le_capable(dev)        ((dev)->features[4] & LMP_LE)
6861da177e4SLinus Torvalds 
687eead27daSAndre Guedes /* ----- Extended LMP capabilities ----- */
68859e29406SAndre Guedes #define lmp_host_le_capable(dev)   ((dev)->host_features[0] & LMP_HOST_LE)
689eead27daSAndre Guedes 
6901da177e4SLinus Torvalds /* ----- HCI protocols ----- */
6915a9d0a3fSWaldemar Rymarkiewicz static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr,
6925a9d0a3fSWaldemar Rymarkiewicz 								__u8 type)
6931da177e4SLinus Torvalds {
694686ebf28SUlisses Furquim 	switch (type) {
695686ebf28SUlisses Furquim 	case ACL_LINK:
696686ebf28SUlisses Furquim 		return l2cap_connect_ind(hdev, bdaddr);
6971da177e4SLinus Torvalds 
698686ebf28SUlisses Furquim 	case SCO_LINK:
699686ebf28SUlisses Furquim 	case ESCO_LINK:
700686ebf28SUlisses Furquim 		return sco_connect_ind(hdev, bdaddr);
7011da177e4SLinus Torvalds 
702686ebf28SUlisses Furquim 	default:
703686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", type);
704686ebf28SUlisses Furquim 		return -EINVAL;
705686ebf28SUlisses Furquim 	}
7061da177e4SLinus Torvalds }
7071da177e4SLinus Torvalds 
7081da177e4SLinus Torvalds static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
7091da177e4SLinus Torvalds {
710686ebf28SUlisses Furquim 	switch (conn->type) {
711686ebf28SUlisses Furquim 	case ACL_LINK:
712686ebf28SUlisses Furquim 	case LE_LINK:
713686ebf28SUlisses Furquim 		l2cap_connect_cfm(conn, status);
714686ebf28SUlisses Furquim 		break;
7151da177e4SLinus Torvalds 
716686ebf28SUlisses Furquim 	case SCO_LINK:
717686ebf28SUlisses Furquim 	case ESCO_LINK:
718686ebf28SUlisses Furquim 		sco_connect_cfm(conn, status);
719686ebf28SUlisses Furquim 		break;
7201da177e4SLinus Torvalds 
721686ebf28SUlisses Furquim 	default:
722686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
723686ebf28SUlisses Furquim 		break;
724686ebf28SUlisses Furquim 	}
725e9a416b5SJohan Hedberg 
726e9a416b5SJohan Hedberg 	if (conn->connect_cfm_cb)
727e9a416b5SJohan Hedberg 		conn->connect_cfm_cb(conn, status);
7281da177e4SLinus Torvalds }
7291da177e4SLinus Torvalds 
7302950f21aSMarcel Holtmann static inline int hci_proto_disconn_ind(struct hci_conn *conn)
7312950f21aSMarcel Holtmann {
732686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
733686ebf28SUlisses Furquim 		return HCI_ERROR_REMOTE_USER_TERM;
7342950f21aSMarcel Holtmann 
735686ebf28SUlisses Furquim 	return l2cap_disconn_ind(conn);
7362950f21aSMarcel Holtmann }
7372950f21aSMarcel Holtmann 
7382950f21aSMarcel Holtmann static inline void hci_proto_disconn_cfm(struct hci_conn *conn, __u8 reason)
7391da177e4SLinus Torvalds {
740686ebf28SUlisses Furquim 	switch (conn->type) {
741686ebf28SUlisses Furquim 	case ACL_LINK:
742686ebf28SUlisses Furquim 	case LE_LINK:
743686ebf28SUlisses Furquim 		l2cap_disconn_cfm(conn, reason);
744686ebf28SUlisses Furquim 		break;
7451da177e4SLinus Torvalds 
746686ebf28SUlisses Furquim 	case SCO_LINK:
747686ebf28SUlisses Furquim 	case ESCO_LINK:
748686ebf28SUlisses Furquim 		sco_disconn_cfm(conn, reason);
749686ebf28SUlisses Furquim 		break;
7501da177e4SLinus Torvalds 
751686ebf28SUlisses Furquim 	default:
752686ebf28SUlisses Furquim 		BT_ERR("unknown link type %d", conn->type);
753686ebf28SUlisses Furquim 		break;
754686ebf28SUlisses Furquim 	}
755e9a416b5SJohan Hedberg 
756e9a416b5SJohan Hedberg 	if (conn->disconn_cfm_cb)
757e9a416b5SJohan Hedberg 		conn->disconn_cfm_cb(conn, reason);
7581da177e4SLinus Torvalds }
7591da177e4SLinus Torvalds 
7601da177e4SLinus Torvalds static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
7611da177e4SLinus Torvalds {
7628c1b2355SMarcel Holtmann 	__u8 encrypt;
7638c1b2355SMarcel Holtmann 
764686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
765686ebf28SUlisses Furquim 		return;
766686ebf28SUlisses Furquim 
76751a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
7688c1b2355SMarcel Holtmann 		return;
7698c1b2355SMarcel Holtmann 
7708c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
771686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
772e9a416b5SJohan Hedberg 
773e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
774e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
7751da177e4SLinus Torvalds }
7761da177e4SLinus Torvalds 
7775a9d0a3fSWaldemar Rymarkiewicz static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status,
7785a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
7791da177e4SLinus Torvalds {
780686ebf28SUlisses Furquim 	if (conn->type != ACL_LINK && conn->type != LE_LINK)
781686ebf28SUlisses Furquim 		return;
7821da177e4SLinus Torvalds 
783686ebf28SUlisses Furquim 	l2cap_security_cfm(conn, status, encrypt);
784e9a416b5SJohan Hedberg 
785e9a416b5SJohan Hedberg 	if (conn->security_cfm_cb)
786e9a416b5SJohan Hedberg 		conn->security_cfm_cb(conn, status);
7871da177e4SLinus Torvalds }
7881da177e4SLinus Torvalds 
7891da177e4SLinus Torvalds /* ----- HCI callbacks ----- */
7901da177e4SLinus Torvalds struct hci_cb {
7911da177e4SLinus Torvalds 	struct list_head list;
7921da177e4SLinus Torvalds 
7931da177e4SLinus Torvalds 	char *name;
7941da177e4SLinus Torvalds 
7955a9d0a3fSWaldemar Rymarkiewicz 	void (*security_cfm)	(struct hci_conn *conn, __u8 status,
7965a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt);
7971da177e4SLinus Torvalds 	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
7981da177e4SLinus Torvalds 	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
7991da177e4SLinus Torvalds };
8001da177e4SLinus Torvalds 
8011da177e4SLinus Torvalds static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
8021da177e4SLinus Torvalds {
8031da177e4SLinus Torvalds 	struct list_head *p;
8048c1b2355SMarcel Holtmann 	__u8 encrypt;
8051da177e4SLinus Torvalds 
8061da177e4SLinus Torvalds 	hci_proto_auth_cfm(conn, status);
8071da177e4SLinus Torvalds 
80851a8efd7SJohan Hedberg 	if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags))
8098c1b2355SMarcel Holtmann 		return;
8108c1b2355SMarcel Holtmann 
8118c1b2355SMarcel Holtmann 	encrypt = (conn->link_mode & HCI_LM_ENCRYPT) ? 0x01 : 0x00;
8128c1b2355SMarcel Holtmann 
813f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8141da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8151da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8168c1b2355SMarcel Holtmann 		if (cb->security_cfm)
8178c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
8181da177e4SLinus Torvalds 	}
819f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8201da177e4SLinus Torvalds }
8211da177e4SLinus Torvalds 
8225a9d0a3fSWaldemar Rymarkiewicz static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status,
8235a9d0a3fSWaldemar Rymarkiewicz 								__u8 encrypt)
8241da177e4SLinus Torvalds {
8251da177e4SLinus Torvalds 	struct list_head *p;
8261da177e4SLinus Torvalds 
827435fef20SMarcel Holtmann 	if (conn->sec_level == BT_SECURITY_SDP)
828435fef20SMarcel Holtmann 		conn->sec_level = BT_SECURITY_LOW;
829435fef20SMarcel Holtmann 
83088167aedSVinicius Costa Gomes 	if (conn->pending_sec_level > conn->sec_level)
83188167aedSVinicius Costa Gomes 		conn->sec_level = conn->pending_sec_level;
83288167aedSVinicius Costa Gomes 
8339719f8afSMarcel Holtmann 	hci_proto_encrypt_cfm(conn, status, encrypt);
8341da177e4SLinus Torvalds 
835f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8361da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8371da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8388c1b2355SMarcel Holtmann 		if (cb->security_cfm)
8398c1b2355SMarcel Holtmann 			cb->security_cfm(conn, status, encrypt);
8401da177e4SLinus Torvalds 	}
841f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8421da177e4SLinus Torvalds }
8431da177e4SLinus Torvalds 
8441da177e4SLinus Torvalds static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
8451da177e4SLinus Torvalds {
8461da177e4SLinus Torvalds 	struct list_head *p;
8471da177e4SLinus Torvalds 
848f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8491da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8501da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8511da177e4SLinus Torvalds 		if (cb->key_change_cfm)
8521da177e4SLinus Torvalds 			cb->key_change_cfm(conn, status);
8531da177e4SLinus Torvalds 	}
854f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8551da177e4SLinus Torvalds }
8561da177e4SLinus Torvalds 
8575a9d0a3fSWaldemar Rymarkiewicz static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status,
8585a9d0a3fSWaldemar Rymarkiewicz 								__u8 role)
8591da177e4SLinus Torvalds {
8601da177e4SLinus Torvalds 	struct list_head *p;
8611da177e4SLinus Torvalds 
862f20d09d5SGustavo F. Padovan 	read_lock(&hci_cb_list_lock);
8631da177e4SLinus Torvalds 	list_for_each(p, &hci_cb_list) {
8641da177e4SLinus Torvalds 		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
8651da177e4SLinus Torvalds 		if (cb->role_switch_cfm)
8661da177e4SLinus Torvalds 			cb->role_switch_cfm(conn, status, role);
8671da177e4SLinus Torvalds 	}
868f20d09d5SGustavo F. Padovan 	read_unlock(&hci_cb_list_lock);
8691da177e4SLinus Torvalds }
8701da177e4SLinus Torvalds 
8716759a675SJohan Hedberg static inline bool eir_has_data_type(u8 *data, size_t data_len, u8 type)
8726759a675SJohan Hedberg {
8736759a675SJohan Hedberg 	u8 field_len;
8746759a675SJohan Hedberg 	size_t parsed;
8756759a675SJohan Hedberg 
8766759a675SJohan Hedberg 	for (parsed = 0; parsed < data_len - 1; parsed += field_len) {
8776759a675SJohan Hedberg 		field_len = data[0];
8786759a675SJohan Hedberg 
8796759a675SJohan Hedberg 		if (field_len == 0)
8806759a675SJohan Hedberg 			break;
8816759a675SJohan Hedberg 
8826759a675SJohan Hedberg 		parsed += field_len + 1;
8836759a675SJohan Hedberg 
8846759a675SJohan Hedberg 		if (parsed > data_len)
8856759a675SJohan Hedberg 			break;
8866759a675SJohan Hedberg 
8876759a675SJohan Hedberg 		if (data[1] == type)
8886759a675SJohan Hedberg 			return true;
8896759a675SJohan Hedberg 
8906759a675SJohan Hedberg 		data += field_len + 1;
8916759a675SJohan Hedberg 	}
8926759a675SJohan Hedberg 
8936759a675SJohan Hedberg 	return false;
8946759a675SJohan Hedberg }
8956759a675SJohan Hedberg 
8961dc06093SJohan Hedberg static inline u16 eir_append_data(u8 *eir, u16 eir_len, u8 type, u8 *data,
8971dc06093SJohan Hedberg 								u8 data_len)
8981dc06093SJohan Hedberg {
8991dc06093SJohan Hedberg 	eir[eir_len++] = sizeof(type) + data_len;
9001dc06093SJohan Hedberg 	eir[eir_len++] = type;
9011dc06093SJohan Hedberg 	memcpy(&eir[eir_len], data, data_len);
9021dc06093SJohan Hedberg 	eir_len += data_len;
9031dc06093SJohan Hedberg 
9041dc06093SJohan Hedberg 	return eir_len;
9051dc06093SJohan Hedberg }
9061dc06093SJohan Hedberg 
9071da177e4SLinus Torvalds int hci_register_cb(struct hci_cb *hcb);
9081da177e4SLinus Torvalds int hci_unregister_cb(struct hci_cb *hcb);
9091da177e4SLinus Torvalds 
9101da177e4SLinus Torvalds int hci_register_notifier(struct notifier_block *nb);
9111da177e4SLinus Torvalds int hci_unregister_notifier(struct notifier_block *nb);
9121da177e4SLinus Torvalds 
913a9de9248SMarcel Holtmann int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, void *param);
91473d80debSLuiz Augusto von Dentz void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags);
9150d861d8bSGustavo F. Padovan void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
9161da177e4SLinus Torvalds 
917a9de9248SMarcel Holtmann void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode);
9181da177e4SLinus Torvalds 
9191da177e4SLinus Torvalds void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
9201da177e4SLinus Torvalds 
9211da177e4SLinus Torvalds /* ----- HCI Sockets ----- */
922eec8d2bcSJohan Hedberg void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb,
923eec8d2bcSJohan Hedberg 							struct sock *skip_sk);
9241da177e4SLinus Torvalds 
9250381101fSJohan Hedberg /* Management interface */
9260381101fSJohan Hedberg int mgmt_control(struct sock *sk, struct msghdr *msg, size_t len);
927744cf19eSJohan Hedberg int mgmt_index_added(struct hci_dev *hdev);
928744cf19eSJohan Hedberg int mgmt_index_removed(struct hci_dev *hdev);
929744cf19eSJohan Hedberg int mgmt_powered(struct hci_dev *hdev, u8 powered);
930744cf19eSJohan Hedberg int mgmt_discoverable(struct hci_dev *hdev, u8 discoverable);
931744cf19eSJohan Hedberg int mgmt_connectable(struct hci_dev *hdev, u8 connectable);
932744cf19eSJohan Hedberg int mgmt_write_scan_failed(struct hci_dev *hdev, u8 scan, u8 status);
933744cf19eSJohan Hedberg int mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key,
934744cf19eSJohan Hedberg 								u8 persistent);
935afc747a6SJohan Hedberg int mgmt_device_connected(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
93648264f06SJohan Hedberg 								u8 addr_type);
937afc747a6SJohan Hedberg int mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr,
938afc747a6SJohan Hedberg 						u8 link_type, u8 addr_type);
93937d9ef76SJohan Hedberg int mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
94048264f06SJohan Hedberg int mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
94148264f06SJohan Hedberg 						u8 addr_type, u8 status);
942744cf19eSJohan Hedberg int mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure);
943744cf19eSJohan Hedberg int mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
944c35938b2SSzymon Janc 								u8 status);
945744cf19eSJohan Hedberg int mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
946744cf19eSJohan Hedberg 								u8 status);
947744cf19eSJohan Hedberg int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr,
948744cf19eSJohan Hedberg 						__le32 value, u8 confirm_hint);
949744cf19eSJohan Hedberg int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
950744cf19eSJohan Hedberg 								u8 status);
951744cf19eSJohan Hedberg int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev,
952744cf19eSJohan Hedberg 						bdaddr_t *bdaddr, u8 status);
953604086b7SBrian Gix int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr);
954604086b7SBrian Gix int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr,
955604086b7SBrian Gix 								u8 status);
956604086b7SBrian Gix int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev,
957604086b7SBrian Gix 						bdaddr_t *bdaddr, u8 status);
958744cf19eSJohan Hedberg int mgmt_auth_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 status);
959744cf19eSJohan Hedberg int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
960744cf19eSJohan Hedberg int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
961744cf19eSJohan Hedberg 						u8 *randomizer, u8 status);
96248264f06SJohan Hedberg int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
963561aafbcSJohan Hedberg 					u8 addr_type, u8 *dev_class, s8 rssi,
964e319d2e7SJohan Hedberg 					u8 cfm_name, u8 *eir, u16 eir_len);
965744cf19eSJohan Hedberg int mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *name);
9667a135109SAndre Guedes int mgmt_start_discovery_failed(struct hci_dev *hdev, u8 status);
967e6d465cbSAndre Guedes int mgmt_stop_discovery_failed(struct hci_dev *hdev, u8 status);
968744cf19eSJohan Hedberg int mgmt_discovering(struct hci_dev *hdev, u8 discovering);
969744cf19eSJohan Hedberg int mgmt_device_blocked(struct hci_dev *hdev, bdaddr_t *bdaddr);
970744cf19eSJohan Hedberg int mgmt_device_unblocked(struct hci_dev *hdev, bdaddr_t *bdaddr);
9710381101fSJohan Hedberg 
9721da177e4SLinus Torvalds /* HCI info for socket */
9731da177e4SLinus Torvalds #define hci_pi(sk) ((struct hci_pinfo *) sk)
9741da177e4SLinus Torvalds 
97514c0b608SJohan Hedberg /* HCI socket flags */
97614c0b608SJohan Hedberg #define HCI_PI_MGMT_INIT	0
97714c0b608SJohan Hedberg 
9781da177e4SLinus Torvalds struct hci_pinfo {
9791da177e4SLinus Torvalds 	struct bt_sock    bt;
9801da177e4SLinus Torvalds 	struct hci_dev    *hdev;
9811da177e4SLinus Torvalds 	struct hci_filter filter;
9821da177e4SLinus Torvalds 	__u32             cmsg_mask;
983c02178d2SJohan Hedberg 	unsigned short   channel;
98414c0b608SJohan Hedberg 	unsigned long     flags;
9851da177e4SLinus Torvalds };
9861da177e4SLinus Torvalds 
9871da177e4SLinus Torvalds /* HCI security filter */
9881da177e4SLinus Torvalds #define HCI_SFLT_MAX_OGF  5
9891da177e4SLinus Torvalds 
9901da177e4SLinus Torvalds struct hci_sec_filter {
9911da177e4SLinus Torvalds 	__u32 type_mask;
9921da177e4SLinus Torvalds 	__u32 event_mask[2];
9931da177e4SLinus Torvalds 	__u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
9941da177e4SLinus Torvalds };
9951da177e4SLinus Torvalds 
9961da177e4SLinus Torvalds /* ----- HCI requests ----- */
9971da177e4SLinus Torvalds #define HCI_REQ_DONE	  0
9981da177e4SLinus Torvalds #define HCI_REQ_PEND	  1
9991da177e4SLinus Torvalds #define HCI_REQ_CANCELED  2
10001da177e4SLinus Torvalds 
1001a6a67efdSThomas Gleixner #define hci_req_lock(d)		mutex_lock(&d->req_lock)
1002a6a67efdSThomas Gleixner #define hci_req_unlock(d)	mutex_unlock(&d->req_lock)
10031da177e4SLinus Torvalds 
100423bb5763SJohan Hedberg void hci_req_complete(struct hci_dev *hdev, __u16 cmd, int result);
10051da177e4SLinus Torvalds 
10062ce603ebSClaudio Takahasi void hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max,
10072ce603ebSClaudio Takahasi 					u16 latency, u16 to_multiplier);
1008a7a595f6SVinicius Costa Gomes void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
1009a7a595f6SVinicius Costa Gomes 							__u8 ltk[16]);
1010a7a595f6SVinicius Costa Gomes void hci_le_ltk_reply(struct hci_conn *conn, u8 ltk[16]);
1011a7a595f6SVinicius Costa Gomes void hci_le_ltk_neg_reply(struct hci_conn *conn);
1012a7a595f6SVinicius Costa Gomes 
10132519a1fcSAndre Guedes int hci_do_inquiry(struct hci_dev *hdev, u8 length);
1014023d5049SAndre Guedes int hci_cancel_inquiry(struct hci_dev *hdev);
10152519a1fcSAndre Guedes 
10161da177e4SLinus Torvalds #endif /* __HCI_CORE_H */
1017