xref: /openbmc/linux/include/net/bluetooth/bluetooth.h (revision e781b7f7fcc141d69f63d4eef70d249549dfaeda)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds    BlueZ - Bluetooth protocol stack for Linux
31da177e4SLinus Torvalds    Copyright (C) 2000-2001 Qualcomm Incorporated
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 __BLUETOOTH_H
261da177e4SLinus Torvalds #define __BLUETOOTH_H
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds #include <linux/poll.h>
291da177e4SLinus Torvalds #include <net/sock.h>
30256a06c8SMasatake YAMATO #include <linux/seq_file.h>
311da177e4SLinus Torvalds 
321da177e4SLinus Torvalds #ifndef AF_BLUETOOTH
331da177e4SLinus Torvalds #define AF_BLUETOOTH	31
341da177e4SLinus Torvalds #define PF_BLUETOOTH	AF_BLUETOOTH
351da177e4SLinus Torvalds #endif
361da177e4SLinus Torvalds 
37d095c1ebSAndrei Emeltchenko /* Bluetooth versions */
38d095c1ebSAndrei Emeltchenko #define BLUETOOTH_VER_1_1	1
39d095c1ebSAndrei Emeltchenko #define BLUETOOTH_VER_1_2	2
40d095c1ebSAndrei Emeltchenko #define BLUETOOTH_VER_2_0	3
41d095c1ebSAndrei Emeltchenko 
421da177e4SLinus Torvalds /* Reserv for core and drivers use */
431da177e4SLinus Torvalds #define BT_SKB_RESERVE	8
441da177e4SLinus Torvalds 
451da177e4SLinus Torvalds #define BTPROTO_L2CAP	0
461da177e4SLinus Torvalds #define BTPROTO_HCI	1
471da177e4SLinus Torvalds #define BTPROTO_SCO	2
481da177e4SLinus Torvalds #define BTPROTO_RFCOMM	3
491da177e4SLinus Torvalds #define BTPROTO_BNEP	4
501da177e4SLinus Torvalds #define BTPROTO_CMTP	5
511da177e4SLinus Torvalds #define BTPROTO_HIDP	6
521da177e4SLinus Torvalds #define BTPROTO_AVDTP	7
531da177e4SLinus Torvalds 
541da177e4SLinus Torvalds #define SOL_HCI		0
551da177e4SLinus Torvalds #define SOL_L2CAP	6
561da177e4SLinus Torvalds #define SOL_SCO		17
571da177e4SLinus Torvalds #define SOL_RFCOMM	18
581da177e4SLinus Torvalds 
598c1b2355SMarcel Holtmann #define BT_SECURITY	4
608c1b2355SMarcel Holtmann struct bt_security {
618c1b2355SMarcel Holtmann 	__u8 level;
628f360119SVinicius Costa Gomes 	__u8 key_size;
638c1b2355SMarcel Holtmann };
648c1b2355SMarcel Holtmann #define BT_SECURITY_SDP		0
658c1b2355SMarcel Holtmann #define BT_SECURITY_LOW		1
668c1b2355SMarcel Holtmann #define BT_SECURITY_MEDIUM	2
678c1b2355SMarcel Holtmann #define BT_SECURITY_HIGH	3
687b5a9241SMarcel Holtmann #define BT_SECURITY_FIPS	4
698c1b2355SMarcel Holtmann 
70c4f912e1SMarcel Holtmann #define BT_DEFER_SETUP	7
71c4f912e1SMarcel Holtmann 
72e702112fSAndrei Emeltchenko #define BT_FLUSHABLE	8
73e702112fSAndrei Emeltchenko 
74e702112fSAndrei Emeltchenko #define BT_FLUSHABLE_OFF	0
75e702112fSAndrei Emeltchenko #define BT_FLUSHABLE_ON		1
76e702112fSAndrei Emeltchenko 
7714b12d0bSJaikumar Ganesh #define BT_POWER	9
7814b12d0bSJaikumar Ganesh struct bt_power {
7914b12d0bSJaikumar Ganesh 	__u8 force_active;
8014b12d0bSJaikumar Ganesh };
8114b12d0bSJaikumar Ganesh #define BT_POWER_FORCE_ACTIVE_OFF 0
8214b12d0bSJaikumar Ganesh #define BT_POWER_FORCE_ACTIVE_ON  1
8314b12d0bSJaikumar Ganesh 
84c14968b0SMat Martineau #define BT_CHANNEL_POLICY	10
85c14968b0SMat Martineau 
86c14968b0SMat Martineau /* BR/EDR only (default policy)
87c14968b0SMat Martineau  *   AMP controllers cannot be used.
88c14968b0SMat Martineau  *   Channel move requests from the remote device are denied.
89c14968b0SMat Martineau  *   If the L2CAP channel is currently using AMP, move the channel to BR/EDR.
90c14968b0SMat Martineau  */
91c14968b0SMat Martineau #define BT_CHANNEL_POLICY_BREDR_ONLY		0
92c14968b0SMat Martineau 
93c14968b0SMat Martineau /* BR/EDR Preferred
94c14968b0SMat Martineau  *   Allow use of AMP controllers.
95c14968b0SMat Martineau  *   If the L2CAP channel is currently on AMP, move it to BR/EDR.
96c14968b0SMat Martineau  *   Channel move requests from the remote device are allowed.
97c14968b0SMat Martineau  */
98c14968b0SMat Martineau #define BT_CHANNEL_POLICY_BREDR_PREFERRED	1
99c14968b0SMat Martineau 
100c14968b0SMat Martineau /* AMP Preferred
101c14968b0SMat Martineau  *   Allow use of AMP controllers
102c14968b0SMat Martineau  *   If the L2CAP channel is currently on BR/EDR and AMP controller
103c14968b0SMat Martineau  *     resources are available, initiate a channel move to AMP.
104c14968b0SMat Martineau  *   Channel move requests from the remote device are allowed.
105c14968b0SMat Martineau  *   If the L2CAP socket has not been connected yet, try to create
106c14968b0SMat Martineau  *     and configure the channel directly on an AMP controller rather
107c14968b0SMat Martineau  *     than BR/EDR.
108c14968b0SMat Martineau  */
109c14968b0SMat Martineau #define BT_CHANNEL_POLICY_AMP_PREFERRED		2
110c14968b0SMat Martineau 
111ad10b1a4SFrédéric Dalleau #define BT_VOICE		11
112ad10b1a4SFrédéric Dalleau struct bt_voice {
113ad10b1a4SFrédéric Dalleau 	__u16 setting;
114ad10b1a4SFrédéric Dalleau };
115ad10b1a4SFrédéric Dalleau 
116ad10b1a4SFrédéric Dalleau #define BT_VOICE_TRANSPARENT			0x0003
117ad10b1a4SFrédéric Dalleau #define BT_VOICE_CVSD_16BIT			0x0060
118ad10b1a4SFrédéric Dalleau 
1191f435424SJohan Hedberg #define BT_SNDMTU		12
1201f435424SJohan Hedberg #define BT_RCVMTU		13
1211f435424SJohan Hedberg 
1223ed7003eSJoe Perches __printf(1, 2)
1232b0bf6c8SJoe Perches void bt_info(const char *fmt, ...);
1243ed7003eSJoe Perches __printf(1, 2)
1252b0bf6c8SJoe Perches void bt_err(const char *fmt, ...);
126*e781b7f7SSzymon Janc __printf(1, 2)
127*e781b7f7SSzymon Janc void bt_err_ratelimited(const char *fmt, ...);
128e1447d8dSJoe Perches 
1293ed7003eSJoe Perches #define BT_INFO(fmt, ...)	bt_info(fmt "\n", ##__VA_ARGS__)
1303ed7003eSJoe Perches #define BT_ERR(fmt, ...)	bt_err(fmt "\n", ##__VA_ARGS__)
1313ed7003eSJoe Perches #define BT_DBG(fmt, ...)	pr_debug(fmt "\n", ##__VA_ARGS__)
1321da177e4SLinus Torvalds 
133*e781b7f7SSzymon Janc #define BT_ERR_RATELIMITED(fmt, ...) bt_err_ratelimited(fmt "\n", ##__VA_ARGS__)
134*e781b7f7SSzymon Janc 
1356f558b70SLoic Poulain #define bt_dev_info(hdev, fmt, ...)				\
1366f558b70SLoic Poulain 	BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
1376f558b70SLoic Poulain #define bt_dev_err(hdev, fmt, ...)				\
1386f558b70SLoic Poulain 	BT_ERR("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
1396f558b70SLoic Poulain #define bt_dev_dbg(hdev, fmt, ...)				\
1406f558b70SLoic Poulain 	BT_DBG("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
1416f558b70SLoic Poulain 
1421da177e4SLinus Torvalds /* Connection and socket states */
1431da177e4SLinus Torvalds enum {
1441da177e4SLinus Torvalds 	BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
1451da177e4SLinus Torvalds 	BT_OPEN,
1461da177e4SLinus Torvalds 	BT_BOUND,
1471da177e4SLinus Torvalds 	BT_LISTEN,
1481da177e4SLinus Torvalds 	BT_CONNECT,
1491da177e4SLinus Torvalds 	BT_CONNECT2,
1501da177e4SLinus Torvalds 	BT_CONFIG,
1511da177e4SLinus Torvalds 	BT_DISCONN,
1521da177e4SLinus Torvalds 	BT_CLOSED
1531da177e4SLinus Torvalds };
1541da177e4SLinus Torvalds 
15520d1803aSAndrei Emeltchenko /* If unused will be removed by compiler */
15620d1803aSAndrei Emeltchenko static inline const char *state_to_string(int state)
15720d1803aSAndrei Emeltchenko {
15820d1803aSAndrei Emeltchenko 	switch (state) {
15920d1803aSAndrei Emeltchenko 	case BT_CONNECTED:
16020d1803aSAndrei Emeltchenko 		return "BT_CONNECTED";
16120d1803aSAndrei Emeltchenko 	case BT_OPEN:
16220d1803aSAndrei Emeltchenko 		return "BT_OPEN";
16320d1803aSAndrei Emeltchenko 	case BT_BOUND:
16420d1803aSAndrei Emeltchenko 		return "BT_BOUND";
16520d1803aSAndrei Emeltchenko 	case BT_LISTEN:
16620d1803aSAndrei Emeltchenko 		return "BT_LISTEN";
16720d1803aSAndrei Emeltchenko 	case BT_CONNECT:
16820d1803aSAndrei Emeltchenko 		return "BT_CONNECT";
16920d1803aSAndrei Emeltchenko 	case BT_CONNECT2:
17020d1803aSAndrei Emeltchenko 		return "BT_CONNECT2";
17120d1803aSAndrei Emeltchenko 	case BT_CONFIG:
17220d1803aSAndrei Emeltchenko 		return "BT_CONFIG";
17320d1803aSAndrei Emeltchenko 	case BT_DISCONN:
17420d1803aSAndrei Emeltchenko 		return "BT_DISCONN";
17520d1803aSAndrei Emeltchenko 	case BT_CLOSED:
17620d1803aSAndrei Emeltchenko 		return "BT_CLOSED";
17720d1803aSAndrei Emeltchenko 	}
17820d1803aSAndrei Emeltchenko 
17920d1803aSAndrei Emeltchenko 	return "invalid state";
18020d1803aSAndrei Emeltchenko }
18120d1803aSAndrei Emeltchenko 
1821da177e4SLinus Torvalds /* BD Address */
1831da177e4SLinus Torvalds typedef struct {
1841da177e4SLinus Torvalds 	__u8 b[6];
18566c853ccSGustavo F. Padovan } __packed bdaddr_t;
1861da177e4SLinus Torvalds 
187591f47f3SAndre Guedes /* BD Address type */
188591f47f3SAndre Guedes #define BDADDR_BREDR		0x00
189591f47f3SAndre Guedes #define BDADDR_LE_PUBLIC	0x01
190591f47f3SAndre Guedes #define BDADDR_LE_RANDOM	0x02
191591f47f3SAndre Guedes 
192679efe2bSJohan Hedberg static inline bool bdaddr_type_is_valid(__u8 type)
193679efe2bSJohan Hedberg {
194679efe2bSJohan Hedberg 	switch (type) {
195679efe2bSJohan Hedberg 	case BDADDR_BREDR:
196679efe2bSJohan Hedberg 	case BDADDR_LE_PUBLIC:
197679efe2bSJohan Hedberg 	case BDADDR_LE_RANDOM:
198679efe2bSJohan Hedberg 		return true;
199679efe2bSJohan Hedberg 	}
200679efe2bSJohan Hedberg 
201679efe2bSJohan Hedberg 	return false;
202679efe2bSJohan Hedberg }
203679efe2bSJohan Hedberg 
204679efe2bSJohan Hedberg static inline bool bdaddr_type_is_le(__u8 type)
205679efe2bSJohan Hedberg {
206679efe2bSJohan Hedberg 	switch (type) {
207679efe2bSJohan Hedberg 	case BDADDR_LE_PUBLIC:
208679efe2bSJohan Hedberg 	case BDADDR_LE_RANDOM:
209679efe2bSJohan Hedberg 		return true;
210679efe2bSJohan Hedberg 	}
211679efe2bSJohan Hedberg 
212679efe2bSJohan Hedberg 	return false;
213679efe2bSJohan Hedberg }
214679efe2bSJohan Hedberg 
2151da177e4SLinus Torvalds #define BDADDR_ANY  (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
216a59ac2f7SMarcel Holtmann #define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
2171da177e4SLinus Torvalds 
2181da177e4SLinus Torvalds /* Copy, swap, convert BD Address */
219f53c20e9SDavid Herrmann static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
2201da177e4SLinus Torvalds {
2211da177e4SLinus Torvalds 	return memcmp(ba1, ba2, sizeof(bdaddr_t));
2221da177e4SLinus Torvalds }
223f53c20e9SDavid Herrmann static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
2241da177e4SLinus Torvalds {
2251da177e4SLinus Torvalds 	memcpy(dst, src, sizeof(bdaddr_t));
2261da177e4SLinus Torvalds }
2271da177e4SLinus Torvalds 
2281da177e4SLinus Torvalds void baswap(bdaddr_t *dst, bdaddr_t *src);
2291da177e4SLinus Torvalds 
2301da177e4SLinus Torvalds /* Common socket structures and functions */
2311da177e4SLinus Torvalds 
2321da177e4SLinus Torvalds #define bt_sk(__sk) ((struct bt_sock *) __sk)
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds struct bt_sock {
2351da177e4SLinus Torvalds 	struct sock sk;
2361da177e4SLinus Torvalds 	struct list_head accept_q;
2371da177e4SLinus Torvalds 	struct sock *parent;
238c5daa683SGustavo Padovan 	unsigned long flags;
239d9763698SMarcel Holtmann 	void (*skb_msg_name)(struct sk_buff *, void *, int *);
240c5daa683SGustavo Padovan };
241c5daa683SGustavo Padovan 
242c5daa683SGustavo Padovan enum {
243c5daa683SGustavo Padovan 	BT_SK_DEFER_SETUP,
244c5daa683SGustavo Padovan 	BT_SK_SUSPEND,
2451da177e4SLinus Torvalds };
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds struct bt_sock_list {
2481da177e4SLinus Torvalds 	struct hlist_head head;
2491da177e4SLinus Torvalds 	rwlock_t          lock;
250256a06c8SMasatake YAMATO #ifdef CONFIG_PROC_FS
251256a06c8SMasatake YAMATO         int (* custom_seq_show)(struct seq_file *, void *);
252256a06c8SMasatake YAMATO #endif
2531da177e4SLinus Torvalds };
2541da177e4SLinus Torvalds 
255ec1b4cf7SStephen Hemminger int  bt_sock_register(int proto, const struct net_proto_family *ops);
256be9f97f0SDavid Herrmann void bt_sock_unregister(int proto);
2571da177e4SLinus Torvalds void bt_sock_link(struct bt_sock_list *l, struct sock *s);
2581da177e4SLinus Torvalds void bt_sock_unlink(struct bt_sock_list *l, struct sock *s);
2591b784140SYing Xue int  bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
2601b784140SYing Xue 		     int flags);
2611b784140SYing Xue int  bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
2621b784140SYing Xue 			    size_t len, int flags);
2631da177e4SLinus Torvalds uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
2643241ad82SMarcel Holtmann int  bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
2651da177e4SLinus Torvalds int  bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
266e793dcf0SJohan Hedberg int  bt_sock_wait_ready(struct sock *sk, unsigned long flags);
2671da177e4SLinus Torvalds 
2681da177e4SLinus Torvalds void bt_accept_enqueue(struct sock *parent, struct sock *sk);
2691da177e4SLinus Torvalds void bt_accept_unlink(struct sock *sk);
2701da177e4SLinus Torvalds struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock);
2711da177e4SLinus Torvalds 
2721da177e4SLinus Torvalds /* Skb helpers */
27300e3112cSMat Martineau struct l2cap_ctrl {
27407758991SMarcel Holtmann 	__u8	sframe:1,
27500e3112cSMat Martineau 		poll:1,
27600e3112cSMat Martineau 		final:1,
27700e3112cSMat Martineau 		fcs:1,
27800e3112cSMat Martineau 		sar:2,
27900e3112cSMat Martineau 		super:2;
28000e3112cSMat Martineau 	__u16	reqseq;
28100e3112cSMat Martineau 	__u16	txseq;
28200e3112cSMat Martineau 	__u8	retries;
283a4368ff3SJohan Hedberg 	__le16  psm;
284a4368ff3SJohan Hedberg 	bdaddr_t bdaddr;
285a4368ff3SJohan Hedberg 	struct l2cap_chan *chan;
28600e3112cSMat Martineau };
28700e3112cSMat Martineau 
2883119ae95SJohan Hedberg struct hci_dev;
2893119ae95SJohan Hedberg 
2901904a853SMarcel Holtmann typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode);
291e6214487SJohan Hedberg typedef void (*hci_req_complete_skb_t)(struct hci_dev *hdev, u8 status,
292e6214487SJohan Hedberg 				       u16 opcode, struct sk_buff *skb);
2933119ae95SJohan Hedberg 
294db6e3e8dSJohan Hedberg struct req_ctrl {
295db6e3e8dSJohan Hedberg 	bool start;
296db6e3e8dSJohan Hedberg 	u8 event;
297db6e3e8dSJohan Hedberg 	hci_req_complete_t complete;
298e6214487SJohan Hedberg 	hci_req_complete_skb_t complete_skb;
299db6e3e8dSJohan Hedberg };
300db6e3e8dSJohan Hedberg 
3011da177e4SLinus Torvalds struct bt_skb_cb {
3020d48d939SMarcel Holtmann 	__u8 pkt_type;
3036368c235SEyal Birger 	__u8 force_active;
30443e73e4eSMarcel Holtmann 	__u16 opcode;
30533e882a5SSuraj Sumangala 	__u16 expect;
3066368c235SEyal Birger 	__u8 incoming:1;
307db6e3e8dSJohan Hedberg 	union {
308a4368ff3SJohan Hedberg 		struct l2cap_ctrl l2cap;
309db6e3e8dSJohan Hedberg 		struct req_ctrl req;
310db6e3e8dSJohan Hedberg 	};
3111da177e4SLinus Torvalds };
3121c2acffbSGustavo F. Padovan #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
3131da177e4SLinus Torvalds 
314dd0fc66fSAl Viro static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
3151da177e4SLinus Torvalds {
3161da177e4SLinus Torvalds 	struct sk_buff *skb;
3171da177e4SLinus Torvalds 
318c3c7ea65SGustavo Padovan 	skb = alloc_skb(len + BT_SKB_RESERVE, how);
319c3c7ea65SGustavo Padovan 	if (skb) {
3201da177e4SLinus Torvalds 		skb_reserve(skb, BT_SKB_RESERVE);
3211da177e4SLinus Torvalds 		bt_cb(skb)->incoming  = 0;
3221da177e4SLinus Torvalds 	}
3231da177e4SLinus Torvalds 	return skb;
3241da177e4SLinus Torvalds }
3251da177e4SLinus Torvalds 
3265a9d0a3fSWaldemar Rymarkiewicz static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
3275a9d0a3fSWaldemar Rymarkiewicz 					unsigned long len, int nb, int *err)
3281da177e4SLinus Torvalds {
3291da177e4SLinus Torvalds 	struct sk_buff *skb;
3301da177e4SLinus Torvalds 
331c3c7ea65SGustavo Padovan 	skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err);
332c3c7ea65SGustavo Padovan 	if (skb) {
3331da177e4SLinus Torvalds 		skb_reserve(skb, BT_SKB_RESERVE);
3341da177e4SLinus Torvalds 		bt_cb(skb)->incoming  = 0;
3351da177e4SLinus Torvalds 	}
336e454c844SGustavo F. Padovan 
337e454c844SGustavo F. Padovan 	if (!skb && *err)
338e454c844SGustavo F. Padovan 		return NULL;
339e454c844SGustavo F. Padovan 
340e454c844SGustavo F. Padovan 	*err = sock_error(sk);
341e454c844SGustavo F. Padovan 	if (*err)
342e454c844SGustavo F. Padovan 		goto out;
343e454c844SGustavo F. Padovan 
344e454c844SGustavo F. Padovan 	if (sk->sk_shutdown) {
345e454c844SGustavo F. Padovan 		*err = -ECONNRESET;
346e454c844SGustavo F. Padovan 		goto out;
347e454c844SGustavo F. Padovan 	}
3481da177e4SLinus Torvalds 
3491da177e4SLinus Torvalds 	return skb;
350e454c844SGustavo F. Padovan 
351e454c844SGustavo F. Padovan out:
352e454c844SGustavo F. Padovan 	kfree_skb(skb);
353e454c844SGustavo F. Padovan 	return NULL;
3541da177e4SLinus Torvalds }
3551da177e4SLinus Torvalds 
356e175072fSJoe Perches int bt_to_errno(__u16 code);
3571da177e4SLinus Torvalds 
3586befc644SMarcel Holtmann void hci_sock_set_flag(struct sock *sk, int nr);
3596befc644SMarcel Holtmann void hci_sock_clear_flag(struct sock *sk, int nr);
360c85be545SMarcel Holtmann int hci_sock_test_flag(struct sock *sk, int nr);
361d0f172b1SJohan Hedberg unsigned short hci_sock_get_channel(struct sock *sk);
3626befc644SMarcel Holtmann 
363e74e58f8SJoe Perches int hci_sock_init(void);
364e74e58f8SJoe Perches void hci_sock_cleanup(void);
3656516455dSMarcel Holtmann 
366e74e58f8SJoe Perches int bt_sysfs_init(void);
367e74e58f8SJoe Perches void bt_sysfs_cleanup(void);
3686516455dSMarcel Holtmann 
369e74e58f8SJoe Perches int bt_procfs_init(struct net *net, const char *name,
370256a06c8SMasatake YAMATO 		   struct bt_sock_list *sk_list,
371256a06c8SMasatake YAMATO 		   int (*seq_show)(struct seq_file *, void *));
372e74e58f8SJoe Perches void bt_procfs_cleanup(struct net *net, const char *name);
373256a06c8SMasatake YAMATO 
374aef7d97cSMarcel Holtmann extern struct dentry *bt_debugfs;
375be9d1227SMarcel Holtmann 
37664274518SGustavo F. Padovan int l2cap_init(void);
37764274518SGustavo F. Padovan void l2cap_exit(void);
37864274518SGustavo F. Padovan 
379ff50e8afSArron Wang #if IS_ENABLED(CONFIG_BT_BREDR)
38064274518SGustavo F. Padovan int sco_init(void);
38164274518SGustavo F. Padovan void sco_exit(void);
382ff50e8afSArron Wang #else
383ff50e8afSArron Wang static inline int sco_init(void)
384ff50e8afSArron Wang {
385ff50e8afSArron Wang 	return 0;
386ff50e8afSArron Wang }
387ff50e8afSArron Wang 
388ff50e8afSArron Wang static inline void sco_exit(void)
389ff50e8afSArron Wang {
390ff50e8afSArron Wang }
391ff50e8afSArron Wang #endif
39264274518SGustavo F. Padovan 
3936d785aa3SJohan Hedberg int mgmt_init(void);
3946d785aa3SJohan Hedberg void mgmt_exit(void);
3956d785aa3SJohan Hedberg 
396d22015aaSOctavian Purdila void bt_sock_reclassify_lock(struct sock *sk, int proto);
397d22015aaSOctavian Purdila 
3981da177e4SLinus Torvalds #endif /* __BLUETOOTH_H */
399