xref: /linux/include/net/bluetooth/bluetooth.h (revision 37a93dd5c49b5fda807fd204edf2547c3493319c)
1 /*
2    BlueZ - Bluetooth protocol stack for Linux
3    Copyright (C) 2000-2001 Qualcomm Incorporated
4    Copyright 2023 NXP
5 
6    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
7 
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License version 2 as
10    published by the Free Software Foundation;
11 
12    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
13    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
15    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
16    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
17    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 
21    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
22    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
23    SOFTWARE IS DISCLAIMED.
24 */
25 
26 #ifndef __BLUETOOTH_H
27 #define __BLUETOOTH_H
28 
29 #include <linux/poll.h>
30 #include <net/sock.h>
31 #include <linux/seq_file.h>
32 #include <linux/ethtool.h>
33 
34 #define BT_SUBSYS_VERSION	2
35 #define BT_SUBSYS_REVISION	22
36 
37 #ifndef AF_BLUETOOTH
38 #define AF_BLUETOOTH	31
39 #define PF_BLUETOOTH	AF_BLUETOOTH
40 #endif
41 
42 /* Bluetooth versions */
43 #define BLUETOOTH_VER_1_1	1
44 #define BLUETOOTH_VER_1_2	2
45 #define BLUETOOTH_VER_2_0	3
46 #define BLUETOOTH_VER_2_1	4
47 #define BLUETOOTH_VER_4_0	6
48 
49 /* Reserv for core and drivers use */
50 #define BT_SKB_RESERVE	8
51 
52 #define BTPROTO_L2CAP	0
53 #define BTPROTO_HCI	1
54 #define BTPROTO_SCO	2
55 #define BTPROTO_RFCOMM	3
56 #define BTPROTO_BNEP	4
57 #define BTPROTO_CMTP	5
58 #define BTPROTO_HIDP	6
59 #define BTPROTO_AVDTP	7
60 #define BTPROTO_ISO	8
61 #define BTPROTO_LAST	BTPROTO_ISO
62 
63 #define SOL_HCI		0
64 #define SOL_L2CAP	6
65 #define SOL_SCO		17
66 #define SOL_RFCOMM	18
67 
68 #define BT_SECURITY	4
69 struct bt_security {
70 	__u8 level;
71 	__u8 key_size;
72 };
73 #define BT_SECURITY_SDP		0
74 #define BT_SECURITY_LOW		1
75 #define BT_SECURITY_MEDIUM	2
76 #define BT_SECURITY_HIGH	3
77 #define BT_SECURITY_FIPS	4
78 
79 #define BT_DEFER_SETUP	7
80 
81 #define BT_FLUSHABLE	8
82 
83 #define BT_FLUSHABLE_OFF	0
84 #define BT_FLUSHABLE_ON		1
85 
86 #define BT_POWER	9
87 struct bt_power {
88 	__u8 force_active;
89 };
90 #define BT_POWER_FORCE_ACTIVE_OFF 0
91 #define BT_POWER_FORCE_ACTIVE_ON  1
92 
93 #define BT_CHANNEL_POLICY	10
94 
95 /* BR/EDR only (default policy)
96  *   AMP controllers cannot be used.
97  *   Channel move requests from the remote device are denied.
98  *   If the L2CAP channel is currently using AMP, move the channel to BR/EDR.
99  */
100 #define BT_CHANNEL_POLICY_BREDR_ONLY		0
101 
102 /* BR/EDR Preferred
103  *   Allow use of AMP controllers.
104  *   If the L2CAP channel is currently on AMP, move it to BR/EDR.
105  *   Channel move requests from the remote device are allowed.
106  */
107 #define BT_CHANNEL_POLICY_BREDR_PREFERRED	1
108 
109 /* AMP Preferred
110  *   Allow use of AMP controllers
111  *   If the L2CAP channel is currently on BR/EDR and AMP controller
112  *     resources are available, initiate a channel move to AMP.
113  *   Channel move requests from the remote device are allowed.
114  *   If the L2CAP socket has not been connected yet, try to create
115  *     and configure the channel directly on an AMP controller rather
116  *     than BR/EDR.
117  */
118 #define BT_CHANNEL_POLICY_AMP_PREFERRED		2
119 
120 #define BT_VOICE		11
121 struct bt_voice {
122 	__u16 setting;
123 };
124 
125 #define BT_VOICE_TRANSPARENT			0x0003
126 #define BT_VOICE_CVSD_16BIT			0x0060
127 #define BT_VOICE_TRANSPARENT_16BIT		0x0063
128 
129 #define BT_SNDMTU		12
130 #define BT_RCVMTU		13
131 #define BT_PHY			14
132 
133 #define BT_PHY_BR_1M_1SLOT	BIT(0)
134 #define BT_PHY_BR_1M_3SLOT	BIT(1)
135 #define BT_PHY_BR_1M_5SLOT	BIT(2)
136 #define BT_PHY_EDR_2M_1SLOT	BIT(3)
137 #define BT_PHY_EDR_2M_3SLOT	BIT(4)
138 #define BT_PHY_EDR_2M_5SLOT	BIT(5)
139 #define BT_PHY_EDR_3M_1SLOT	BIT(6)
140 #define BT_PHY_EDR_3M_3SLOT	BIT(7)
141 #define BT_PHY_EDR_3M_5SLOT	BIT(8)
142 #define BT_PHY_LE_1M_TX		BIT(9)
143 #define BT_PHY_LE_1M_RX		BIT(10)
144 #define BT_PHY_LE_2M_TX		BIT(11)
145 #define BT_PHY_LE_2M_RX		BIT(12)
146 #define BT_PHY_LE_CODED_TX	BIT(13)
147 #define BT_PHY_LE_CODED_RX	BIT(14)
148 
149 #define BT_PHY_BREDR_MASK	(BT_PHY_BR_1M_1SLOT | BT_PHY_BR_1M_3SLOT | \
150 				 BT_PHY_BR_1M_5SLOT | BT_PHY_EDR_2M_1SLOT | \
151 				 BT_PHY_EDR_2M_3SLOT | BT_PHY_EDR_2M_5SLOT | \
152 				 BT_PHY_EDR_3M_1SLOT | BT_PHY_EDR_3M_3SLOT | \
153 				 BT_PHY_EDR_3M_5SLOT)
154 #define BT_PHY_LE_MASK		(BT_PHY_LE_1M_TX | BT_PHY_LE_1M_RX | \
155 				 BT_PHY_LE_2M_TX | BT_PHY_LE_2M_RX | \
156 				 BT_PHY_LE_CODED_TX | BT_PHY_LE_CODED_RX)
157 
158 #define BT_MODE			15
159 
160 #define BT_MODE_BASIC		0x00
161 #define BT_MODE_ERTM		0x01
162 #define BT_MODE_STREAMING	0x02
163 #define BT_MODE_LE_FLOWCTL	0x03
164 #define BT_MODE_EXT_FLOWCTL	0x04
165 
166 #define BT_PKT_STATUS           16
167 
168 #define BT_SCM_PKT_STATUS	0x03
169 #define BT_SCM_ERROR		0x04
170 
171 #define BT_ISO_QOS		17
172 
173 #define BT_ISO_QOS_CIG_UNSET	0xff
174 #define BT_ISO_QOS_CIS_UNSET	0xff
175 
176 #define BT_ISO_QOS_BIG_UNSET	0xff
177 #define BT_ISO_QOS_BIS_UNSET	0xff
178 
179 #define BT_ISO_SYNC_TIMEOUT	0x07d0 /* 20 secs */
180 
181 struct bt_iso_io_qos {
182 	__u32 interval;
183 	__u16 latency;
184 	__u16 sdu;
185 	__u8  phys;
186 	__u8  rtn;
187 };
188 
189 struct bt_iso_ucast_qos {
190 	__u8  cig;
191 	__u8  cis;
192 	__u8  sca;
193 	__u8  packing;
194 	__u8  framing;
195 	struct bt_iso_io_qos in;
196 	struct bt_iso_io_qos out;
197 };
198 
199 struct bt_iso_bcast_qos {
200 	__u8  big;
201 	__u8  bis;
202 	__u8  sync_factor;
203 	__u8  packing;
204 	__u8  framing;
205 	struct bt_iso_io_qos in;
206 	struct bt_iso_io_qos out;
207 	__u8  encryption;
208 	__u8  bcode[16];
209 	__u8  options;
210 	__u16 skip;
211 	__u16 sync_timeout;
212 	__u8  sync_cte_type;
213 	__u8  mse;
214 	__u16 timeout;
215 };
216 
217 struct bt_iso_qos {
218 	union {
219 		struct bt_iso_ucast_qos ucast;
220 		struct bt_iso_bcast_qos bcast;
221 	};
222 };
223 
224 #define BT_ISO_PHY_1M		BIT(0)
225 #define BT_ISO_PHY_2M		BIT(1)
226 #define BT_ISO_PHY_CODED	BIT(2)
227 #define BT_ISO_PHY_ANY		(BT_ISO_PHY_1M | BT_ISO_PHY_2M | \
228 				 BT_ISO_PHY_CODED)
229 
230 #define BT_CODEC	19
231 
232 struct	bt_codec_caps {
233 	__u8	len;
234 	__u8	data[];
235 } __packed;
236 
237 struct bt_codec {
238 	__u8	id;
239 	__u16	cid;
240 	__u16	vid;
241 	__u8	data_path;
242 	__u8	num_caps;
243 } __packed;
244 
245 struct bt_codecs {
246 	__u8		num_codecs;
247 	struct bt_codec	codecs[];
248 } __packed;
249 
250 #define BT_CODEC_CVSD		0x02
251 #define BT_CODEC_TRANSPARENT	0x03
252 #define BT_CODEC_MSBC		0x05
253 
254 #define BT_ISO_BASE		20
255 
256 /* Socket option value 21 reserved */
257 
258 #define BT_PKT_SEQNUM		22
259 
260 #define BT_SCM_PKT_SEQNUM	0x05
261 
262 __printf(1, 2)
263 void bt_info(const char *fmt, ...);
264 __printf(1, 2)
265 void bt_warn(const char *fmt, ...);
266 __printf(1, 2)
267 void bt_err(const char *fmt, ...);
268 #if IS_ENABLED(CONFIG_BT_FEATURE_DEBUG)
269 void bt_dbg_set(bool enable);
270 bool bt_dbg_get(void);
271 __printf(1, 2)
272 void bt_dbg(const char *fmt, ...);
273 #endif
274 __printf(1, 2)
275 void bt_warn_ratelimited(const char *fmt, ...);
276 __printf(1, 2)
277 void bt_err_ratelimited(const char *fmt, ...);
278 
279 #define BT_INFO(fmt, ...)	bt_info(fmt "\n", ##__VA_ARGS__)
280 #define BT_WARN(fmt, ...)	bt_warn(fmt "\n", ##__VA_ARGS__)
281 #define BT_ERR(fmt, ...)	bt_err(fmt "\n", ##__VA_ARGS__)
282 
283 #if IS_ENABLED(CONFIG_BT_FEATURE_DEBUG)
284 #define BT_DBG(fmt, ...) \
285 	bt_dbg("%s:%d: " fmt "\n", __func__, __LINE__, ##__VA_ARGS__)
286 #else
287 #define BT_DBG(fmt, ...)	pr_debug(fmt "\n", ##__VA_ARGS__)
288 #endif
289 
290 #define bt_dev_name(hdev) ((hdev) ? (hdev)->name : "null")
291 
292 #define bt_dev_info(hdev, fmt, ...)				\
293 	BT_INFO("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
294 #define bt_dev_warn(hdev, fmt, ...)				\
295 	BT_WARN("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
296 #define bt_dev_err(hdev, fmt, ...)				\
297 	BT_ERR("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
298 #define bt_dev_dbg(hdev, fmt, ...)				\
299 	BT_DBG("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
300 
301 #define bt_dev_warn_ratelimited(hdev, fmt, ...)			\
302 	bt_warn_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
303 #define bt_dev_err_ratelimited(hdev, fmt, ...)			\
304 	bt_err_ratelimited("%s: " fmt, bt_dev_name(hdev), ##__VA_ARGS__)
305 
306 /* Connection and socket states */
307 enum bt_sock_state {
308 	BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
309 	BT_OPEN,
310 	BT_BOUND,
311 	BT_LISTEN,
312 	BT_CONNECT,
313 	BT_CONNECT2,
314 	BT_CONFIG,
315 	BT_DISCONN,
316 	BT_CLOSED
317 };
318 
319 /* If unused will be removed by compiler */
320 static inline const char *state_to_string(int state)
321 {
322 	switch (state) {
323 	case BT_CONNECTED:
324 		return "BT_CONNECTED";
325 	case BT_OPEN:
326 		return "BT_OPEN";
327 	case BT_BOUND:
328 		return "BT_BOUND";
329 	case BT_LISTEN:
330 		return "BT_LISTEN";
331 	case BT_CONNECT:
332 		return "BT_CONNECT";
333 	case BT_CONNECT2:
334 		return "BT_CONNECT2";
335 	case BT_CONFIG:
336 		return "BT_CONFIG";
337 	case BT_DISCONN:
338 		return "BT_DISCONN";
339 	case BT_CLOSED:
340 		return "BT_CLOSED";
341 	}
342 
343 	return "invalid state";
344 }
345 
346 /* BD Address */
347 typedef struct {
348 	__u8 b[6];
349 } __packed bdaddr_t;
350 
351 /* BD Address type */
352 #define BDADDR_BREDR		0x00
353 #define BDADDR_LE_PUBLIC	0x01
354 #define BDADDR_LE_RANDOM	0x02
355 
356 static inline bool bdaddr_type_is_valid(u8 type)
357 {
358 	switch (type) {
359 	case BDADDR_BREDR:
360 	case BDADDR_LE_PUBLIC:
361 	case BDADDR_LE_RANDOM:
362 		return true;
363 	}
364 
365 	return false;
366 }
367 
368 static inline bool bdaddr_type_is_le(u8 type)
369 {
370 	switch (type) {
371 	case BDADDR_LE_PUBLIC:
372 	case BDADDR_LE_RANDOM:
373 		return true;
374 	}
375 
376 	return false;
377 }
378 
379 #define BDADDR_ANY  (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}})
380 #define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}})
381 
382 /* Copy, swap, convert BD Address */
383 static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2)
384 {
385 	return memcmp(ba1, ba2, sizeof(bdaddr_t));
386 }
387 static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src)
388 {
389 	memcpy(dst, src, sizeof(bdaddr_t));
390 }
391 
392 void baswap(bdaddr_t *dst, const bdaddr_t *src);
393 
394 /* Common socket structures and functions */
395 
396 #define bt_sk(__sk) ((struct bt_sock *) __sk)
397 
398 struct bt_sock {
399 	struct sock sk;
400 	struct list_head accept_q;
401 	struct sock *parent;
402 	unsigned long flags;
403 	void (*skb_msg_name)(struct sk_buff *, void *, int *);
404 	void (*skb_put_cmsg)(struct sk_buff *, struct msghdr *, struct sock *);
405 };
406 
407 enum {
408 	BT_SK_DEFER_SETUP,
409 	BT_SK_SUSPEND,
410 	BT_SK_PKT_STATUS,
411 	BT_SK_PKT_SEQNUM,
412 };
413 
414 struct bt_sock_list {
415 	struct hlist_head head;
416 	rwlock_t          lock;
417 #ifdef CONFIG_PROC_FS
418         int (* custom_seq_show)(struct seq_file *, void *);
419 #endif
420 };
421 
422 int  bt_sock_register(int proto, const struct net_proto_family *ops);
423 void bt_sock_unregister(int proto);
424 void bt_sock_link(struct bt_sock_list *l, struct sock *s);
425 void bt_sock_unlink(struct bt_sock_list *l, struct sock *s);
426 bool bt_sock_linked(struct bt_sock_list *l, struct sock *s);
427 struct sock *bt_sock_alloc(struct net *net, struct socket *sock,
428 			   struct proto *prot, int proto, gfp_t prio, int kern);
429 int  bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
430 		     int flags);
431 int  bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
432 			    size_t len, int flags);
433 __poll_t bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
434 int  bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
435 int  bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
436 int  bt_sock_wait_ready(struct sock *sk, unsigned int msg_flags);
437 
438 void bt_accept_enqueue(struct sock *parent, struct sock *sk, bool bh);
439 void bt_accept_unlink(struct sock *sk);
440 struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock);
441 
442 /* Skb helpers */
443 struct l2cap_ctrl {
444 	u8	sframe:1,
445 		poll:1,
446 		final:1,
447 		fcs:1,
448 		sar:2,
449 		super:2;
450 
451 	u16	reqseq;
452 	u16	txseq;
453 	u8	retries;
454 	__le16  psm;
455 	bdaddr_t bdaddr;
456 	struct l2cap_chan *chan;
457 };
458 
459 struct hci_dev;
460 
461 typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode);
462 typedef void (*hci_req_complete_skb_t)(struct hci_dev *hdev, u8 status,
463 				       u16 opcode, struct sk_buff *skb);
464 
465 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
466 			  hci_req_complete_t *req_complete,
467 			  hci_req_complete_skb_t *req_complete_skb);
468 
469 int hci_ethtool_ts_info(unsigned int index, int sk_proto,
470 			struct kernel_ethtool_ts_info *ts_info);
471 
472 #define HCI_REQ_START	BIT(0)
473 #define HCI_REQ_SKB	BIT(1)
474 
475 struct hci_ctrl {
476 	struct sock *sk;
477 	u16 opcode;
478 	u8 req_flags;
479 	u8 req_event;
480 	union {
481 		hci_req_complete_t req_complete;
482 		hci_req_complete_skb_t req_complete_skb;
483 	};
484 };
485 
486 struct mgmt_ctrl {
487 	struct hci_dev *hdev;
488 	u16 opcode;
489 };
490 
491 struct bt_skb_cb {
492 	u8 pkt_type;
493 	u8 force_active;
494 	u16 expect;
495 	u16 pkt_seqnum;
496 	u8 incoming:1;
497 	u8 pkt_status:2;
498 	union {
499 		struct l2cap_ctrl l2cap;
500 		struct hci_ctrl hci;
501 		struct mgmt_ctrl mgmt;
502 		struct scm_creds creds;
503 	};
504 };
505 #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
506 
507 #define hci_skb_pkt_type(skb) bt_cb((skb))->pkt_type
508 #define hci_skb_pkt_status(skb) bt_cb((skb))->pkt_status
509 #define hci_skb_pkt_seqnum(skb) bt_cb((skb))->pkt_seqnum
510 #define hci_skb_expect(skb) bt_cb((skb))->expect
511 #define hci_skb_opcode(skb) bt_cb((skb))->hci.opcode
512 #define hci_skb_event(skb) bt_cb((skb))->hci.req_event
513 #define hci_skb_sk(skb) bt_cb((skb))->hci.sk
514 
515 static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
516 {
517 	struct sk_buff *skb;
518 
519 	skb = alloc_skb(len + BT_SKB_RESERVE, how);
520 	if (skb)
521 		skb_reserve(skb, BT_SKB_RESERVE);
522 	return skb;
523 }
524 
525 static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
526 					unsigned long len, int nb, int *err)
527 {
528 	struct sk_buff *skb;
529 
530 	skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err);
531 	if (skb)
532 		skb_reserve(skb, BT_SKB_RESERVE);
533 
534 	if (!skb && *err)
535 		return NULL;
536 
537 	*err = sock_error(sk);
538 	if (*err)
539 		goto out;
540 
541 	if (sk->sk_shutdown) {
542 		*err = -ECONNRESET;
543 		goto out;
544 	}
545 
546 	return skb;
547 
548 out:
549 	kfree_skb(skb);
550 	return NULL;
551 }
552 
553 /* Shall not be called with lock_sock held */
554 static inline struct sk_buff *bt_skb_sendmsg(struct sock *sk,
555 					     struct msghdr *msg,
556 					     size_t len, size_t mtu,
557 					     size_t headroom, size_t tailroom)
558 {
559 	struct sk_buff *skb;
560 	size_t size = min_t(size_t, len, mtu);
561 	int err;
562 
563 	skb = bt_skb_send_alloc(sk, size + headroom + tailroom,
564 				msg->msg_flags & MSG_DONTWAIT, &err);
565 	if (!skb)
566 		return ERR_PTR(err);
567 
568 	skb_reserve(skb, headroom);
569 	skb_tailroom_reserve(skb, mtu, tailroom);
570 
571 	if (!copy_from_iter_full(skb_put(skb, size), size, &msg->msg_iter)) {
572 		kfree_skb(skb);
573 		return ERR_PTR(-EFAULT);
574 	}
575 
576 	skb->priority = READ_ONCE(sk->sk_priority);
577 
578 	return skb;
579 }
580 
581 /* Similar to bt_skb_sendmsg but can split the msg into multiple fragments
582  * accourding to the MTU.
583  */
584 static inline struct sk_buff *bt_skb_sendmmsg(struct sock *sk,
585 					      struct msghdr *msg,
586 					      size_t len, size_t mtu,
587 					      size_t headroom, size_t tailroom)
588 {
589 	struct sk_buff *skb, **frag;
590 
591 	skb = bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom);
592 	if (IS_ERR(skb))
593 		return skb;
594 
595 	len -= skb->len;
596 	if (!len)
597 		return skb;
598 
599 	/* Add remaining data over MTU as continuation fragments */
600 	frag = &skb_shinfo(skb)->frag_list;
601 	while (len) {
602 		struct sk_buff *tmp;
603 
604 		tmp = bt_skb_sendmsg(sk, msg, len, mtu, headroom, tailroom);
605 		if (IS_ERR(tmp)) {
606 			return skb;
607 		}
608 
609 		len -= tmp->len;
610 
611 		*frag = tmp;
612 		frag = &(*frag)->next;
613 	}
614 
615 	return skb;
616 }
617 
618 int bt_to_errno(u16 code);
619 __u8 bt_status(int err);
620 
621 void hci_sock_set_flag(struct sock *sk, int nr);
622 void hci_sock_clear_flag(struct sock *sk, int nr);
623 int hci_sock_test_flag(struct sock *sk, int nr);
624 unsigned short hci_sock_get_channel(struct sock *sk);
625 u32 hci_sock_get_cookie(struct sock *sk);
626 
627 int hci_sock_init(void);
628 void hci_sock_cleanup(void);
629 
630 int bt_sysfs_init(void);
631 void bt_sysfs_cleanup(void);
632 
633 int bt_procfs_init(struct net *net, const char *name,
634 		   struct bt_sock_list *sk_list,
635 		   int (*seq_show)(struct seq_file *, void *));
636 void bt_procfs_cleanup(struct net *net, const char *name);
637 
638 extern struct dentry *bt_debugfs;
639 
640 int l2cap_init(void);
641 void l2cap_exit(void);
642 
643 #if IS_ENABLED(CONFIG_BT_BREDR)
644 int sco_init(void);
645 void sco_exit(void);
646 #else
647 static inline int sco_init(void)
648 {
649 	return 0;
650 }
651 
652 static inline void sco_exit(void)
653 {
654 }
655 #endif
656 
657 #if IS_ENABLED(CONFIG_BT_LE)
658 int iso_init(void);
659 int iso_exit(void);
660 bool iso_inited(void);
661 #else
662 static inline int iso_init(void)
663 {
664 	return 0;
665 }
666 
667 static inline int iso_exit(void)
668 {
669 	return 0;
670 }
671 
672 static inline bool iso_inited(void)
673 {
674 	return false;
675 }
676 #endif
677 
678 int mgmt_init(void);
679 void mgmt_exit(void);
680 void mgmt_cleanup(struct sock *sk);
681 
682 void bt_sock_reclassify_lock(struct sock *sk, int proto);
683 
684 #endif /* __BLUETOOTH_H */
685