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 
329e8305b3SMarcel Holtmann #define BT_SUBSYS_VERSION	2
334037a774SMarcel Holtmann #define BT_SUBSYS_REVISION	22
34dd31506dSMarcel Holtmann 
351da177e4SLinus Torvalds #ifndef AF_BLUETOOTH
361da177e4SLinus Torvalds #define AF_BLUETOOTH	31
371da177e4SLinus Torvalds #define PF_BLUETOOTH	AF_BLUETOOTH
381da177e4SLinus Torvalds #endif
391da177e4SLinus Torvalds 
40d095c1ebSAndrei Emeltchenko /* Bluetooth versions */
41d095c1ebSAndrei Emeltchenko #define BLUETOOTH_VER_1_1	1
42d095c1ebSAndrei Emeltchenko #define BLUETOOTH_VER_1_2	2
43d095c1ebSAndrei Emeltchenko #define BLUETOOTH_VER_2_0	3
44d095c1ebSAndrei Emeltchenko 
451da177e4SLinus Torvalds /* Reserv for core and drivers use */
461da177e4SLinus Torvalds #define BT_SKB_RESERVE	8
471da177e4SLinus Torvalds 
481da177e4SLinus Torvalds #define BTPROTO_L2CAP	0
491da177e4SLinus Torvalds #define BTPROTO_HCI	1
501da177e4SLinus Torvalds #define BTPROTO_SCO	2
511da177e4SLinus Torvalds #define BTPROTO_RFCOMM	3
521da177e4SLinus Torvalds #define BTPROTO_BNEP	4
531da177e4SLinus Torvalds #define BTPROTO_CMTP	5
541da177e4SLinus Torvalds #define BTPROTO_HIDP	6
551da177e4SLinus Torvalds #define BTPROTO_AVDTP	7
561da177e4SLinus Torvalds 
571da177e4SLinus Torvalds #define SOL_HCI		0
581da177e4SLinus Torvalds #define SOL_L2CAP	6
591da177e4SLinus Torvalds #define SOL_SCO		17
601da177e4SLinus Torvalds #define SOL_RFCOMM	18
611da177e4SLinus Torvalds 
628c1b2355SMarcel Holtmann #define BT_SECURITY	4
638c1b2355SMarcel Holtmann struct bt_security {
648c1b2355SMarcel Holtmann 	__u8 level;
658f360119SVinicius Costa Gomes 	__u8 key_size;
668c1b2355SMarcel Holtmann };
678c1b2355SMarcel Holtmann #define BT_SECURITY_SDP		0
688c1b2355SMarcel Holtmann #define BT_SECURITY_LOW		1
698c1b2355SMarcel Holtmann #define BT_SECURITY_MEDIUM	2
708c1b2355SMarcel Holtmann #define BT_SECURITY_HIGH	3
717b5a9241SMarcel Holtmann #define BT_SECURITY_FIPS	4
728c1b2355SMarcel Holtmann 
73c4f912e1SMarcel Holtmann #define BT_DEFER_SETUP	7
74c4f912e1SMarcel Holtmann 
75e702112fSAndrei Emeltchenko #define BT_FLUSHABLE	8
76e702112fSAndrei Emeltchenko 
77e702112fSAndrei Emeltchenko #define BT_FLUSHABLE_OFF	0
78e702112fSAndrei Emeltchenko #define BT_FLUSHABLE_ON		1
79e702112fSAndrei Emeltchenko 
8014b12d0bSJaikumar Ganesh #define BT_POWER	9
8114b12d0bSJaikumar Ganesh struct bt_power {
8214b12d0bSJaikumar Ganesh 	__u8 force_active;
8314b12d0bSJaikumar Ganesh };
8414b12d0bSJaikumar Ganesh #define BT_POWER_FORCE_ACTIVE_OFF 0
8514b12d0bSJaikumar Ganesh #define BT_POWER_FORCE_ACTIVE_ON  1
8614b12d0bSJaikumar Ganesh 
87c14968b0SMat Martineau #define BT_CHANNEL_POLICY	10
88c14968b0SMat Martineau 
89c14968b0SMat Martineau /* BR/EDR only (default policy)
90c14968b0SMat Martineau  *   AMP controllers cannot be used.
91c14968b0SMat Martineau  *   Channel move requests from the remote device are denied.
92c14968b0SMat Martineau  *   If the L2CAP channel is currently using AMP, move the channel to BR/EDR.
93c14968b0SMat Martineau  */
94c14968b0SMat Martineau #define BT_CHANNEL_POLICY_BREDR_ONLY		0
95c14968b0SMat Martineau 
96c14968b0SMat Martineau /* BR/EDR Preferred
97c14968b0SMat Martineau  *   Allow use of AMP controllers.
98c14968b0SMat Martineau  *   If the L2CAP channel is currently on AMP, move it to BR/EDR.
99c14968b0SMat Martineau  *   Channel move requests from the remote device are allowed.
100c14968b0SMat Martineau  */
101c14968b0SMat Martineau #define BT_CHANNEL_POLICY_BREDR_PREFERRED	1
102c14968b0SMat Martineau 
103c14968b0SMat Martineau /* AMP Preferred
104c14968b0SMat Martineau  *   Allow use of AMP controllers
105c14968b0SMat Martineau  *   If the L2CAP channel is currently on BR/EDR and AMP controller
106c14968b0SMat Martineau  *     resources are available, initiate a channel move to AMP.
107c14968b0SMat Martineau  *   Channel move requests from the remote device are allowed.
108c14968b0SMat Martineau  *   If the L2CAP socket has not been connected yet, try to create
109c14968b0SMat Martineau  *     and configure the channel directly on an AMP controller rather
110c14968b0SMat Martineau  *     than BR/EDR.
111c14968b0SMat Martineau  */
112c14968b0SMat Martineau #define BT_CHANNEL_POLICY_AMP_PREFERRED		2
113c14968b0SMat Martineau 
114ad10b1a4SFrédéric Dalleau #define BT_VOICE		11
115ad10b1a4SFrédéric Dalleau struct bt_voice {
116ad10b1a4SFrédéric Dalleau 	__u16 setting;
117ad10b1a4SFrédéric Dalleau };
118ad10b1a4SFrédéric Dalleau 
119ad10b1a4SFrédéric Dalleau #define BT_VOICE_TRANSPARENT			0x0003
120ad10b1a4SFrédéric Dalleau #define BT_VOICE_CVSD_16BIT			0x0060
121ad10b1a4SFrédéric Dalleau 
1221f435424SJohan Hedberg #define BT_SNDMTU		12
1231f435424SJohan Hedberg #define BT_RCVMTU		13
1241f435424SJohan Hedberg 
1253ed7003eSJoe Perches __printf(1, 2)
1262b0bf6c8SJoe Perches void bt_info(const char *fmt, ...);
1273ed7003eSJoe Perches __printf(1, 2)
128594b31eaSFrederic Danis void bt_warn(const char *fmt, ...);
129594b31eaSFrederic Danis __printf(1, 2)
1302b0bf6c8SJoe Perches void bt_err(const char *fmt, ...);
131e781b7f7SSzymon Janc __printf(1, 2)
132e781b7f7SSzymon Janc void bt_err_ratelimited(const char *fmt, ...);
133e1447d8dSJoe Perches 
1343ed7003eSJoe Perches #define BT_INFO(fmt, ...)	bt_info(fmt "\n", ##__VA_ARGS__)
135594b31eaSFrederic Danis #define BT_WARN(fmt, ...)	bt_warn(fmt "\n", ##__VA_ARGS__)
1363ed7003eSJoe Perches #define BT_ERR(fmt, ...)	bt_err(fmt "\n", ##__VA_ARGS__)
1373ed7003eSJoe Perches #define BT_DBG(fmt, ...)	pr_debug(fmt "\n", ##__VA_ARGS__)
1381da177e4SLinus Torvalds 
139e781b7f7SSzymon Janc #define BT_ERR_RATELIMITED(fmt, ...) bt_err_ratelimited(fmt "\n", ##__VA_ARGS__)
140e781b7f7SSzymon Janc 
1416f558b70SLoic Poulain #define bt_dev_info(hdev, fmt, ...)				\
1426f558b70SLoic Poulain 	BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
143594b31eaSFrederic Danis #define bt_dev_warn(hdev, fmt, ...)				\
144594b31eaSFrederic Danis 	BT_WARN("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
1456f558b70SLoic Poulain #define bt_dev_err(hdev, fmt, ...)				\
1466f558b70SLoic Poulain 	BT_ERR("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
1476f558b70SLoic Poulain #define bt_dev_dbg(hdev, fmt, ...)				\
1486f558b70SLoic Poulain 	BT_DBG("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
1496f558b70SLoic Poulain 
1502064ee33SMarcel Holtmann #define bt_dev_err_ratelimited(hdev, fmt, ...)			\
1512064ee33SMarcel Holtmann 	BT_ERR_RATELIMITED("%s: " fmt, (hdev)->name, ##__VA_ARGS__)
1522064ee33SMarcel Holtmann 
1531da177e4SLinus Torvalds /* Connection and socket states */
1541da177e4SLinus Torvalds enum {
1551da177e4SLinus Torvalds 	BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
1561da177e4SLinus Torvalds 	BT_OPEN,
1571da177e4SLinus Torvalds 	BT_BOUND,
1581da177e4SLinus Torvalds 	BT_LISTEN,
1591da177e4SLinus Torvalds 	BT_CONNECT,
1601da177e4SLinus Torvalds 	BT_CONNECT2,
1611da177e4SLinus Torvalds 	BT_CONFIG,
1621da177e4SLinus Torvalds 	BT_DISCONN,
1631da177e4SLinus Torvalds 	BT_CLOSED
1641da177e4SLinus Torvalds };
1651da177e4SLinus Torvalds 
16620d1803aSAndrei Emeltchenko /* If unused will be removed by compiler */
16720d1803aSAndrei Emeltchenko static inline const char *state_to_string(int state)
16820d1803aSAndrei Emeltchenko {
16920d1803aSAndrei Emeltchenko 	switch (state) {
17020d1803aSAndrei Emeltchenko 	case BT_CONNECTED:
17120d1803aSAndrei Emeltchenko 		return "BT_CONNECTED";
17220d1803aSAndrei Emeltchenko 	case BT_OPEN:
17320d1803aSAndrei Emeltchenko 		return "BT_OPEN";
17420d1803aSAndrei Emeltchenko 	case BT_BOUND:
17520d1803aSAndrei Emeltchenko 		return "BT_BOUND";
17620d1803aSAndrei Emeltchenko 	case BT_LISTEN:
17720d1803aSAndrei Emeltchenko 		return "BT_LISTEN";
17820d1803aSAndrei Emeltchenko 	case BT_CONNECT:
17920d1803aSAndrei Emeltchenko 		return "BT_CONNECT";
18020d1803aSAndrei Emeltchenko 	case BT_CONNECT2:
18120d1803aSAndrei Emeltchenko 		return "BT_CONNECT2";
18220d1803aSAndrei Emeltchenko 	case BT_CONFIG:
18320d1803aSAndrei Emeltchenko 		return "BT_CONFIG";
18420d1803aSAndrei Emeltchenko 	case BT_DISCONN:
18520d1803aSAndrei Emeltchenko 		return "BT_DISCONN";
18620d1803aSAndrei Emeltchenko 	case BT_CLOSED:
18720d1803aSAndrei Emeltchenko 		return "BT_CLOSED";
18820d1803aSAndrei Emeltchenko 	}
18920d1803aSAndrei Emeltchenko 
19020d1803aSAndrei Emeltchenko 	return "invalid state";
19120d1803aSAndrei Emeltchenko }
19220d1803aSAndrei Emeltchenko 
1931da177e4SLinus Torvalds /* BD Address */
1941da177e4SLinus Torvalds typedef struct {
1951da177e4SLinus Torvalds 	__u8 b[6];
19666c853ccSGustavo F. Padovan } __packed bdaddr_t;
1971da177e4SLinus Torvalds 
198591f47f3SAndre Guedes /* BD Address type */
199591f47f3SAndre Guedes #define BDADDR_BREDR		0x00
200591f47f3SAndre Guedes #define BDADDR_LE_PUBLIC	0x01
201591f47f3SAndre Guedes #define BDADDR_LE_RANDOM	0x02
202591f47f3SAndre Guedes 
20321fcf572SPavel Machek static inline bool bdaddr_type_is_valid(u8 type)
204679efe2bSJohan Hedberg {
205679efe2bSJohan Hedberg 	switch (type) {
206679efe2bSJohan Hedberg 	case BDADDR_BREDR:
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 
21521fcf572SPavel Machek static inline bool bdaddr_type_is_le(u8 type)
216679efe2bSJohan Hedberg {
217679efe2bSJohan Hedberg 	switch (type) {
218679efe2bSJohan Hedberg 	case BDADDR_LE_PUBLIC:
219679efe2bSJohan Hedberg 	case BDADDR_LE_RANDOM:
220679efe2bSJohan Hedberg 		return true;
221679efe2bSJohan Hedberg 	}
222679efe2bSJohan Hedberg 
223679efe2bSJohan Hedberg 	return false;
224679efe2bSJohan Hedberg }
225679efe2bSJohan Hedberg 
2261da177e4SLinus Torvalds #define BDADDR_ANY  (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
227a59ac2f7SMarcel Holtmann #define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
2281da177e4SLinus Torvalds 
2291da177e4SLinus Torvalds /* Copy, swap, convert BD Address */
230f53c20e9SDavid Herrmann static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
2311da177e4SLinus Torvalds {
2321da177e4SLinus Torvalds 	return memcmp(ba1, ba2, sizeof(bdaddr_t));
2331da177e4SLinus Torvalds }
234f53c20e9SDavid Herrmann static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
2351da177e4SLinus Torvalds {
2361da177e4SLinus Torvalds 	memcpy(dst, src, sizeof(bdaddr_t));
2371da177e4SLinus Torvalds }
2381da177e4SLinus Torvalds 
23965bce462SLoic Poulain void baswap(bdaddr_t *dst, const bdaddr_t *src);
2401da177e4SLinus Torvalds 
2411da177e4SLinus Torvalds /* Common socket structures and functions */
2421da177e4SLinus Torvalds 
2431da177e4SLinus Torvalds #define bt_sk(__sk) ((struct bt_sock *) __sk)
2441da177e4SLinus Torvalds 
2451da177e4SLinus Torvalds struct bt_sock {
2461da177e4SLinus Torvalds 	struct sock sk;
2471da177e4SLinus Torvalds 	struct list_head accept_q;
2481da177e4SLinus Torvalds 	struct sock *parent;
249c5daa683SGustavo Padovan 	unsigned long flags;
250d9763698SMarcel Holtmann 	void (*skb_msg_name)(struct sk_buff *, void *, int *);
251c5daa683SGustavo Padovan };
252c5daa683SGustavo Padovan 
253c5daa683SGustavo Padovan enum {
254c5daa683SGustavo Padovan 	BT_SK_DEFER_SETUP,
255c5daa683SGustavo Padovan 	BT_SK_SUSPEND,
2561da177e4SLinus Torvalds };
2571da177e4SLinus Torvalds 
2581da177e4SLinus Torvalds struct bt_sock_list {
2591da177e4SLinus Torvalds 	struct hlist_head head;
2601da177e4SLinus Torvalds 	rwlock_t          lock;
261256a06c8SMasatake YAMATO #ifdef CONFIG_PROC_FS
262256a06c8SMasatake YAMATO         int (* custom_seq_show)(struct seq_file *, void *);
263256a06c8SMasatake YAMATO #endif
2641da177e4SLinus Torvalds };
2651da177e4SLinus Torvalds 
266ec1b4cf7SStephen Hemminger int  bt_sock_register(int proto, const struct net_proto_family *ops);
267be9f97f0SDavid Herrmann void bt_sock_unregister(int proto);
2681da177e4SLinus Torvalds void bt_sock_link(struct bt_sock_list *l, struct sock *s);
2691da177e4SLinus Torvalds void bt_sock_unlink(struct bt_sock_list *l, struct sock *s);
2701b784140SYing Xue int  bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
2711b784140SYing Xue 		     int flags);
2721b784140SYing Xue int  bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
2731b784140SYing Xue 			    size_t len, int flags);
2741da177e4SLinus Torvalds uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
2753241ad82SMarcel Holtmann int  bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
2761da177e4SLinus Torvalds int  bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
277e793dcf0SJohan Hedberg int  bt_sock_wait_ready(struct sock *sk, unsigned long flags);
2781da177e4SLinus Torvalds 
2791da177e4SLinus Torvalds void bt_accept_enqueue(struct sock *parent, struct sock *sk);
2801da177e4SLinus Torvalds void bt_accept_unlink(struct sock *sk);
2811da177e4SLinus Torvalds struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock);
2821da177e4SLinus Torvalds 
2831da177e4SLinus Torvalds /* Skb helpers */
28400e3112cSMat Martineau struct l2cap_ctrl {
28521fcf572SPavel Machek 	u8	sframe:1,
28600e3112cSMat Martineau 		poll:1,
28700e3112cSMat Martineau 		final:1,
28800e3112cSMat Martineau 		fcs:1,
28900e3112cSMat Martineau 		sar:2,
29000e3112cSMat Martineau 		super:2;
29121fcf572SPavel Machek 
29221fcf572SPavel Machek 	u16	reqseq;
29321fcf572SPavel Machek 	u16	txseq;
29421fcf572SPavel Machek 	u8	retries;
295a4368ff3SJohan Hedberg 	__le16  psm;
296a4368ff3SJohan Hedberg 	bdaddr_t bdaddr;
297a4368ff3SJohan Hedberg 	struct l2cap_chan *chan;
29800e3112cSMat Martineau };
29900e3112cSMat Martineau 
3003119ae95SJohan Hedberg struct hci_dev;
3013119ae95SJohan Hedberg 
3021904a853SMarcel Holtmann typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode);
303e6214487SJohan Hedberg typedef void (*hci_req_complete_skb_t)(struct hci_dev *hdev, u8 status,
304e6214487SJohan Hedberg 				       u16 opcode, struct sk_buff *skb);
3053119ae95SJohan Hedberg 
30644d27137SJohan Hedberg #define HCI_REQ_START	BIT(0)
30744d27137SJohan Hedberg #define HCI_REQ_SKB	BIT(1)
30844d27137SJohan Hedberg 
309242c0ebdSMarcel Holtmann struct hci_ctrl {
31021fcf572SPavel Machek 	u16 opcode;
31144d27137SJohan Hedberg 	u8 req_flags;
312242c0ebdSMarcel Holtmann 	u8 req_event;
31344d27137SJohan Hedberg 	union {
314242c0ebdSMarcel Holtmann 		hci_req_complete_t req_complete;
315242c0ebdSMarcel Holtmann 		hci_req_complete_skb_t req_complete_skb;
316db6e3e8dSJohan Hedberg 	};
31744d27137SJohan Hedberg };
318db6e3e8dSJohan Hedberg 
3191da177e4SLinus Torvalds struct bt_skb_cb {
32021fcf572SPavel Machek 	u8 pkt_type;
32121fcf572SPavel Machek 	u8 force_active;
32221fcf572SPavel Machek 	u16 expect;
32321fcf572SPavel Machek 	u8 incoming:1;
324db6e3e8dSJohan Hedberg 	union {
325a4368ff3SJohan Hedberg 		struct l2cap_ctrl l2cap;
326242c0ebdSMarcel Holtmann 		struct hci_ctrl hci;
327db6e3e8dSJohan Hedberg 	};
3281da177e4SLinus Torvalds };
3291c2acffbSGustavo F. Padovan #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
3301da177e4SLinus Torvalds 
331f5c4a42aSMarcel Holtmann #define hci_skb_pkt_type(skb) bt_cb((skb))->pkt_type
332f5c4a42aSMarcel Holtmann #define hci_skb_expect(skb) bt_cb((skb))->expect
333f5c4a42aSMarcel Holtmann #define hci_skb_opcode(skb) bt_cb((skb))->hci.opcode
334f5c4a42aSMarcel Holtmann 
335dd0fc66fSAl Viro static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
3361da177e4SLinus Torvalds {
3371da177e4SLinus Torvalds 	struct sk_buff *skb;
3381da177e4SLinus Torvalds 
339c3c7ea65SGustavo Padovan 	skb = alloc_skb(len + BT_SKB_RESERVE, how);
3405fcc86bdSJohan Hedberg 	if (skb)
3411da177e4SLinus Torvalds 		skb_reserve(skb, BT_SKB_RESERVE);
3421da177e4SLinus Torvalds 	return skb;
3431da177e4SLinus Torvalds }
3441da177e4SLinus Torvalds 
3455a9d0a3fSWaldemar Rymarkiewicz static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
3465a9d0a3fSWaldemar Rymarkiewicz 					unsigned long len, int nb, int *err)
3471da177e4SLinus Torvalds {
3481da177e4SLinus Torvalds 	struct sk_buff *skb;
3491da177e4SLinus Torvalds 
350c3c7ea65SGustavo Padovan 	skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err);
3515fcc86bdSJohan Hedberg 	if (skb)
3521da177e4SLinus Torvalds 		skb_reserve(skb, BT_SKB_RESERVE);
353e454c844SGustavo F. Padovan 
354e454c844SGustavo F. Padovan 	if (!skb && *err)
355e454c844SGustavo F. Padovan 		return NULL;
356e454c844SGustavo F. Padovan 
357e454c844SGustavo F. Padovan 	*err = sock_error(sk);
358e454c844SGustavo F. Padovan 	if (*err)
359e454c844SGustavo F. Padovan 		goto out;
360e454c844SGustavo F. Padovan 
361e454c844SGustavo F. Padovan 	if (sk->sk_shutdown) {
362e454c844SGustavo F. Padovan 		*err = -ECONNRESET;
363e454c844SGustavo F. Padovan 		goto out;
364e454c844SGustavo F. Padovan 	}
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds 	return skb;
367e454c844SGustavo F. Padovan 
368e454c844SGustavo F. Padovan out:
369e454c844SGustavo F. Padovan 	kfree_skb(skb);
370e454c844SGustavo F. Padovan 	return NULL;
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds 
37321fcf572SPavel Machek int bt_to_errno(u16 code);
3741da177e4SLinus Torvalds 
3756befc644SMarcel Holtmann void hci_sock_set_flag(struct sock *sk, int nr);
3766befc644SMarcel Holtmann void hci_sock_clear_flag(struct sock *sk, int nr);
377c85be545SMarcel Holtmann int hci_sock_test_flag(struct sock *sk, int nr);
378d0f172b1SJohan Hedberg unsigned short hci_sock_get_channel(struct sock *sk);
37970ecce91SMarcel Holtmann u32 hci_sock_get_cookie(struct sock *sk);
3806befc644SMarcel Holtmann 
381e74e58f8SJoe Perches int hci_sock_init(void);
382e74e58f8SJoe Perches void hci_sock_cleanup(void);
3836516455dSMarcel Holtmann 
384e74e58f8SJoe Perches int bt_sysfs_init(void);
385e74e58f8SJoe Perches void bt_sysfs_cleanup(void);
3866516455dSMarcel Holtmann 
387e74e58f8SJoe Perches int bt_procfs_init(struct net *net, const char *name,
388256a06c8SMasatake YAMATO 		   struct bt_sock_list *sk_list,
389256a06c8SMasatake YAMATO 		   int (*seq_show)(struct seq_file *, void *));
390e74e58f8SJoe Perches void bt_procfs_cleanup(struct net *net, const char *name);
391256a06c8SMasatake YAMATO 
392aef7d97cSMarcel Holtmann extern struct dentry *bt_debugfs;
393be9d1227SMarcel Holtmann 
39464274518SGustavo F. Padovan int l2cap_init(void);
39564274518SGustavo F. Padovan void l2cap_exit(void);
39664274518SGustavo F. Padovan 
397ff50e8afSArron Wang #if IS_ENABLED(CONFIG_BT_BREDR)
39864274518SGustavo F. Padovan int sco_init(void);
39964274518SGustavo F. Padovan void sco_exit(void);
400ff50e8afSArron Wang #else
401ff50e8afSArron Wang static inline int sco_init(void)
402ff50e8afSArron Wang {
403ff50e8afSArron Wang 	return 0;
404ff50e8afSArron Wang }
405ff50e8afSArron Wang 
406ff50e8afSArron Wang static inline void sco_exit(void)
407ff50e8afSArron Wang {
408ff50e8afSArron Wang }
409ff50e8afSArron Wang #endif
41064274518SGustavo F. Padovan 
4116d785aa3SJohan Hedberg int mgmt_init(void);
4126d785aa3SJohan Hedberg void mgmt_exit(void);
4136d785aa3SJohan Hedberg 
414d22015aaSOctavian Purdila void bt_sock_reclassify_lock(struct sock *sk, int proto);
415d22015aaSOctavian Purdila 
4161da177e4SLinus Torvalds #endif /* __BLUETOOTH_H */
417