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) 125594b31eaSFrederic Danis void bt_warn(const char *fmt, ...); 126594b31eaSFrederic Danis __printf(1, 2) 1272b0bf6c8SJoe Perches void bt_err(const char *fmt, ...); 128e781b7f7SSzymon Janc __printf(1, 2) 129e781b7f7SSzymon Janc void bt_err_ratelimited(const char *fmt, ...); 130e1447d8dSJoe Perches 1313ed7003eSJoe Perches #define BT_INFO(fmt, ...) bt_info(fmt "\n", ##__VA_ARGS__) 132594b31eaSFrederic Danis #define BT_WARN(fmt, ...) bt_warn(fmt "\n", ##__VA_ARGS__) 1333ed7003eSJoe Perches #define BT_ERR(fmt, ...) bt_err(fmt "\n", ##__VA_ARGS__) 1343ed7003eSJoe Perches #define BT_DBG(fmt, ...) pr_debug(fmt "\n", ##__VA_ARGS__) 1351da177e4SLinus Torvalds 136e781b7f7SSzymon Janc #define BT_ERR_RATELIMITED(fmt, ...) bt_err_ratelimited(fmt "\n", ##__VA_ARGS__) 137e781b7f7SSzymon Janc 1386f558b70SLoic Poulain #define bt_dev_info(hdev, fmt, ...) \ 1396f558b70SLoic Poulain BT_INFO("%s: " fmt, (hdev)->name, ##__VA_ARGS__) 140594b31eaSFrederic Danis #define bt_dev_warn(hdev, fmt, ...) \ 141594b31eaSFrederic Danis BT_WARN("%s: " fmt, (hdev)->name, ##__VA_ARGS__) 1426f558b70SLoic Poulain #define bt_dev_err(hdev, fmt, ...) \ 1436f558b70SLoic Poulain BT_ERR("%s: " fmt, (hdev)->name, ##__VA_ARGS__) 1446f558b70SLoic Poulain #define bt_dev_dbg(hdev, fmt, ...) \ 1456f558b70SLoic Poulain BT_DBG("%s: " fmt, (hdev)->name, ##__VA_ARGS__) 1466f558b70SLoic Poulain 1471da177e4SLinus Torvalds /* Connection and socket states */ 1481da177e4SLinus Torvalds enum { 1491da177e4SLinus Torvalds BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 1501da177e4SLinus Torvalds BT_OPEN, 1511da177e4SLinus Torvalds BT_BOUND, 1521da177e4SLinus Torvalds BT_LISTEN, 1531da177e4SLinus Torvalds BT_CONNECT, 1541da177e4SLinus Torvalds BT_CONNECT2, 1551da177e4SLinus Torvalds BT_CONFIG, 1561da177e4SLinus Torvalds BT_DISCONN, 1571da177e4SLinus Torvalds BT_CLOSED 1581da177e4SLinus Torvalds }; 1591da177e4SLinus Torvalds 16020d1803aSAndrei Emeltchenko /* If unused will be removed by compiler */ 16120d1803aSAndrei Emeltchenko static inline const char *state_to_string(int state) 16220d1803aSAndrei Emeltchenko { 16320d1803aSAndrei Emeltchenko switch (state) { 16420d1803aSAndrei Emeltchenko case BT_CONNECTED: 16520d1803aSAndrei Emeltchenko return "BT_CONNECTED"; 16620d1803aSAndrei Emeltchenko case BT_OPEN: 16720d1803aSAndrei Emeltchenko return "BT_OPEN"; 16820d1803aSAndrei Emeltchenko case BT_BOUND: 16920d1803aSAndrei Emeltchenko return "BT_BOUND"; 17020d1803aSAndrei Emeltchenko case BT_LISTEN: 17120d1803aSAndrei Emeltchenko return "BT_LISTEN"; 17220d1803aSAndrei Emeltchenko case BT_CONNECT: 17320d1803aSAndrei Emeltchenko return "BT_CONNECT"; 17420d1803aSAndrei Emeltchenko case BT_CONNECT2: 17520d1803aSAndrei Emeltchenko return "BT_CONNECT2"; 17620d1803aSAndrei Emeltchenko case BT_CONFIG: 17720d1803aSAndrei Emeltchenko return "BT_CONFIG"; 17820d1803aSAndrei Emeltchenko case BT_DISCONN: 17920d1803aSAndrei Emeltchenko return "BT_DISCONN"; 18020d1803aSAndrei Emeltchenko case BT_CLOSED: 18120d1803aSAndrei Emeltchenko return "BT_CLOSED"; 18220d1803aSAndrei Emeltchenko } 18320d1803aSAndrei Emeltchenko 18420d1803aSAndrei Emeltchenko return "invalid state"; 18520d1803aSAndrei Emeltchenko } 18620d1803aSAndrei Emeltchenko 1871da177e4SLinus Torvalds /* BD Address */ 1881da177e4SLinus Torvalds typedef struct { 1891da177e4SLinus Torvalds __u8 b[6]; 19066c853ccSGustavo F. Padovan } __packed bdaddr_t; 1911da177e4SLinus Torvalds 192591f47f3SAndre Guedes /* BD Address type */ 193591f47f3SAndre Guedes #define BDADDR_BREDR 0x00 194591f47f3SAndre Guedes #define BDADDR_LE_PUBLIC 0x01 195591f47f3SAndre Guedes #define BDADDR_LE_RANDOM 0x02 196591f47f3SAndre Guedes 197679efe2bSJohan Hedberg static inline bool bdaddr_type_is_valid(__u8 type) 198679efe2bSJohan Hedberg { 199679efe2bSJohan Hedberg switch (type) { 200679efe2bSJohan Hedberg case BDADDR_BREDR: 201679efe2bSJohan Hedberg case BDADDR_LE_PUBLIC: 202679efe2bSJohan Hedberg case BDADDR_LE_RANDOM: 203679efe2bSJohan Hedberg return true; 204679efe2bSJohan Hedberg } 205679efe2bSJohan Hedberg 206679efe2bSJohan Hedberg return false; 207679efe2bSJohan Hedberg } 208679efe2bSJohan Hedberg 209679efe2bSJohan Hedberg static inline bool bdaddr_type_is_le(__u8 type) 210679efe2bSJohan Hedberg { 211679efe2bSJohan Hedberg switch (type) { 212679efe2bSJohan Hedberg case BDADDR_LE_PUBLIC: 213679efe2bSJohan Hedberg case BDADDR_LE_RANDOM: 214679efe2bSJohan Hedberg return true; 215679efe2bSJohan Hedberg } 216679efe2bSJohan Hedberg 217679efe2bSJohan Hedberg return false; 218679efe2bSJohan Hedberg } 219679efe2bSJohan Hedberg 2201da177e4SLinus Torvalds #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 221a59ac2f7SMarcel Holtmann #define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds /* Copy, swap, convert BD Address */ 224f53c20e9SDavid Herrmann static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2) 2251da177e4SLinus Torvalds { 2261da177e4SLinus Torvalds return memcmp(ba1, ba2, sizeof(bdaddr_t)); 2271da177e4SLinus Torvalds } 228f53c20e9SDavid Herrmann static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src) 2291da177e4SLinus Torvalds { 2301da177e4SLinus Torvalds memcpy(dst, src, sizeof(bdaddr_t)); 2311da177e4SLinus Torvalds } 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds void baswap(bdaddr_t *dst, bdaddr_t *src); 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds /* Common socket structures and functions */ 2361da177e4SLinus Torvalds 2371da177e4SLinus Torvalds #define bt_sk(__sk) ((struct bt_sock *) __sk) 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds struct bt_sock { 2401da177e4SLinus Torvalds struct sock sk; 2411da177e4SLinus Torvalds struct list_head accept_q; 2421da177e4SLinus Torvalds struct sock *parent; 243c5daa683SGustavo Padovan unsigned long flags; 244d9763698SMarcel Holtmann void (*skb_msg_name)(struct sk_buff *, void *, int *); 245c5daa683SGustavo Padovan }; 246c5daa683SGustavo Padovan 247c5daa683SGustavo Padovan enum { 248c5daa683SGustavo Padovan BT_SK_DEFER_SETUP, 249c5daa683SGustavo Padovan BT_SK_SUSPEND, 2501da177e4SLinus Torvalds }; 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds struct bt_sock_list { 2531da177e4SLinus Torvalds struct hlist_head head; 2541da177e4SLinus Torvalds rwlock_t lock; 255256a06c8SMasatake YAMATO #ifdef CONFIG_PROC_FS 256256a06c8SMasatake YAMATO int (* custom_seq_show)(struct seq_file *, void *); 257256a06c8SMasatake YAMATO #endif 2581da177e4SLinus Torvalds }; 2591da177e4SLinus Torvalds 260ec1b4cf7SStephen Hemminger int bt_sock_register(int proto, const struct net_proto_family *ops); 261be9f97f0SDavid Herrmann void bt_sock_unregister(int proto); 2621da177e4SLinus Torvalds void bt_sock_link(struct bt_sock_list *l, struct sock *s); 2631da177e4SLinus Torvalds void bt_sock_unlink(struct bt_sock_list *l, struct sock *s); 2641b784140SYing Xue int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, 2651b784140SYing Xue int flags); 2661b784140SYing Xue int bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg, 2671b784140SYing Xue size_t len, int flags); 2681da177e4SLinus Torvalds uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait); 2693241ad82SMarcel Holtmann int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 2701da177e4SLinus Torvalds int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); 271e793dcf0SJohan Hedberg int bt_sock_wait_ready(struct sock *sk, unsigned long flags); 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds void bt_accept_enqueue(struct sock *parent, struct sock *sk); 2741da177e4SLinus Torvalds void bt_accept_unlink(struct sock *sk); 2751da177e4SLinus Torvalds struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock); 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds /* Skb helpers */ 27800e3112cSMat Martineau struct l2cap_ctrl { 27907758991SMarcel Holtmann __u8 sframe:1, 28000e3112cSMat Martineau poll:1, 28100e3112cSMat Martineau final:1, 28200e3112cSMat Martineau fcs:1, 28300e3112cSMat Martineau sar:2, 28400e3112cSMat Martineau super:2; 28500e3112cSMat Martineau __u16 reqseq; 28600e3112cSMat Martineau __u16 txseq; 28700e3112cSMat Martineau __u8 retries; 288a4368ff3SJohan Hedberg __le16 psm; 289a4368ff3SJohan Hedberg bdaddr_t bdaddr; 290a4368ff3SJohan Hedberg struct l2cap_chan *chan; 29100e3112cSMat Martineau }; 29200e3112cSMat Martineau 2933119ae95SJohan Hedberg struct hci_dev; 2943119ae95SJohan Hedberg 2951904a853SMarcel Holtmann typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode); 296e6214487SJohan Hedberg typedef void (*hci_req_complete_skb_t)(struct hci_dev *hdev, u8 status, 297e6214487SJohan Hedberg u16 opcode, struct sk_buff *skb); 2983119ae95SJohan Hedberg 299*44d27137SJohan Hedberg #define HCI_REQ_START BIT(0) 300*44d27137SJohan Hedberg #define HCI_REQ_SKB BIT(1) 301*44d27137SJohan Hedberg 302242c0ebdSMarcel Holtmann struct hci_ctrl { 303242c0ebdSMarcel Holtmann __u16 opcode; 304*44d27137SJohan Hedberg u8 req_flags; 305242c0ebdSMarcel Holtmann u8 req_event; 306*44d27137SJohan Hedberg union { 307242c0ebdSMarcel Holtmann hci_req_complete_t req_complete; 308242c0ebdSMarcel Holtmann hci_req_complete_skb_t req_complete_skb; 309db6e3e8dSJohan Hedberg }; 310*44d27137SJohan Hedberg }; 311db6e3e8dSJohan Hedberg 3121da177e4SLinus Torvalds struct bt_skb_cb { 3130d48d939SMarcel Holtmann __u8 pkt_type; 3146368c235SEyal Birger __u8 force_active; 31533e882a5SSuraj Sumangala __u16 expect; 3166368c235SEyal Birger __u8 incoming:1; 317db6e3e8dSJohan Hedberg union { 318a4368ff3SJohan Hedberg struct l2cap_ctrl l2cap; 319242c0ebdSMarcel Holtmann struct hci_ctrl hci; 320db6e3e8dSJohan Hedberg }; 3211da177e4SLinus Torvalds }; 3221c2acffbSGustavo F. Padovan #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb)) 3231da177e4SLinus Torvalds 324f5c4a42aSMarcel Holtmann #define hci_skb_pkt_type(skb) bt_cb((skb))->pkt_type 325f5c4a42aSMarcel Holtmann #define hci_skb_expect(skb) bt_cb((skb))->expect 326f5c4a42aSMarcel Holtmann #define hci_skb_opcode(skb) bt_cb((skb))->hci.opcode 327f5c4a42aSMarcel Holtmann 328dd0fc66fSAl Viro static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how) 3291da177e4SLinus Torvalds { 3301da177e4SLinus Torvalds struct sk_buff *skb; 3311da177e4SLinus Torvalds 332c3c7ea65SGustavo Padovan skb = alloc_skb(len + BT_SKB_RESERVE, how); 3335fcc86bdSJohan Hedberg if (skb) 3341da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 3351da177e4SLinus Torvalds return skb; 3361da177e4SLinus Torvalds } 3371da177e4SLinus Torvalds 3385a9d0a3fSWaldemar Rymarkiewicz static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk, 3395a9d0a3fSWaldemar Rymarkiewicz unsigned long len, int nb, int *err) 3401da177e4SLinus Torvalds { 3411da177e4SLinus Torvalds struct sk_buff *skb; 3421da177e4SLinus Torvalds 343c3c7ea65SGustavo Padovan skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err); 3445fcc86bdSJohan Hedberg if (skb) 3451da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 346e454c844SGustavo F. Padovan 347e454c844SGustavo F. Padovan if (!skb && *err) 348e454c844SGustavo F. Padovan return NULL; 349e454c844SGustavo F. Padovan 350e454c844SGustavo F. Padovan *err = sock_error(sk); 351e454c844SGustavo F. Padovan if (*err) 352e454c844SGustavo F. Padovan goto out; 353e454c844SGustavo F. Padovan 354e454c844SGustavo F. Padovan if (sk->sk_shutdown) { 355e454c844SGustavo F. Padovan *err = -ECONNRESET; 356e454c844SGustavo F. Padovan goto out; 357e454c844SGustavo F. Padovan } 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvalds return skb; 360e454c844SGustavo F. Padovan 361e454c844SGustavo F. Padovan out: 362e454c844SGustavo F. Padovan kfree_skb(skb); 363e454c844SGustavo F. Padovan return NULL; 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds 366e175072fSJoe Perches int bt_to_errno(__u16 code); 3671da177e4SLinus Torvalds 3686befc644SMarcel Holtmann void hci_sock_set_flag(struct sock *sk, int nr); 3696befc644SMarcel Holtmann void hci_sock_clear_flag(struct sock *sk, int nr); 370c85be545SMarcel Holtmann int hci_sock_test_flag(struct sock *sk, int nr); 371d0f172b1SJohan Hedberg unsigned short hci_sock_get_channel(struct sock *sk); 3726befc644SMarcel Holtmann 373e74e58f8SJoe Perches int hci_sock_init(void); 374e74e58f8SJoe Perches void hci_sock_cleanup(void); 3756516455dSMarcel Holtmann 376e74e58f8SJoe Perches int bt_sysfs_init(void); 377e74e58f8SJoe Perches void bt_sysfs_cleanup(void); 3786516455dSMarcel Holtmann 379e74e58f8SJoe Perches int bt_procfs_init(struct net *net, const char *name, 380256a06c8SMasatake YAMATO struct bt_sock_list *sk_list, 381256a06c8SMasatake YAMATO int (*seq_show)(struct seq_file *, void *)); 382e74e58f8SJoe Perches void bt_procfs_cleanup(struct net *net, const char *name); 383256a06c8SMasatake YAMATO 384aef7d97cSMarcel Holtmann extern struct dentry *bt_debugfs; 385be9d1227SMarcel Holtmann 38664274518SGustavo F. Padovan int l2cap_init(void); 38764274518SGustavo F. Padovan void l2cap_exit(void); 38864274518SGustavo F. Padovan 389ff50e8afSArron Wang #if IS_ENABLED(CONFIG_BT_BREDR) 39064274518SGustavo F. Padovan int sco_init(void); 39164274518SGustavo F. Padovan void sco_exit(void); 392ff50e8afSArron Wang #else 393ff50e8afSArron Wang static inline int sco_init(void) 394ff50e8afSArron Wang { 395ff50e8afSArron Wang return 0; 396ff50e8afSArron Wang } 397ff50e8afSArron Wang 398ff50e8afSArron Wang static inline void sco_exit(void) 399ff50e8afSArron Wang { 400ff50e8afSArron Wang } 401ff50e8afSArron Wang #endif 40264274518SGustavo F. Padovan 4036d785aa3SJohan Hedberg int mgmt_init(void); 4046d785aa3SJohan Hedberg void mgmt_exit(void); 4056d785aa3SJohan Hedberg 406d22015aaSOctavian Purdila void bt_sock_reclassify_lock(struct sock *sk, int proto); 407d22015aaSOctavian Purdila 4081da177e4SLinus Torvalds #endif /* __BLUETOOTH_H */ 409