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 32*9e8305b3SMarcel Holtmann #define BT_SUBSYS_VERSION 2 33*9e8305b3SMarcel Holtmann #define BT_SUBSYS_REVISION 21 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 1501da177e4SLinus Torvalds /* Connection and socket states */ 1511da177e4SLinus Torvalds enum { 1521da177e4SLinus Torvalds BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */ 1531da177e4SLinus Torvalds BT_OPEN, 1541da177e4SLinus Torvalds BT_BOUND, 1551da177e4SLinus Torvalds BT_LISTEN, 1561da177e4SLinus Torvalds BT_CONNECT, 1571da177e4SLinus Torvalds BT_CONNECT2, 1581da177e4SLinus Torvalds BT_CONFIG, 1591da177e4SLinus Torvalds BT_DISCONN, 1601da177e4SLinus Torvalds BT_CLOSED 1611da177e4SLinus Torvalds }; 1621da177e4SLinus Torvalds 16320d1803aSAndrei Emeltchenko /* If unused will be removed by compiler */ 16420d1803aSAndrei Emeltchenko static inline const char *state_to_string(int state) 16520d1803aSAndrei Emeltchenko { 16620d1803aSAndrei Emeltchenko switch (state) { 16720d1803aSAndrei Emeltchenko case BT_CONNECTED: 16820d1803aSAndrei Emeltchenko return "BT_CONNECTED"; 16920d1803aSAndrei Emeltchenko case BT_OPEN: 17020d1803aSAndrei Emeltchenko return "BT_OPEN"; 17120d1803aSAndrei Emeltchenko case BT_BOUND: 17220d1803aSAndrei Emeltchenko return "BT_BOUND"; 17320d1803aSAndrei Emeltchenko case BT_LISTEN: 17420d1803aSAndrei Emeltchenko return "BT_LISTEN"; 17520d1803aSAndrei Emeltchenko case BT_CONNECT: 17620d1803aSAndrei Emeltchenko return "BT_CONNECT"; 17720d1803aSAndrei Emeltchenko case BT_CONNECT2: 17820d1803aSAndrei Emeltchenko return "BT_CONNECT2"; 17920d1803aSAndrei Emeltchenko case BT_CONFIG: 18020d1803aSAndrei Emeltchenko return "BT_CONFIG"; 18120d1803aSAndrei Emeltchenko case BT_DISCONN: 18220d1803aSAndrei Emeltchenko return "BT_DISCONN"; 18320d1803aSAndrei Emeltchenko case BT_CLOSED: 18420d1803aSAndrei Emeltchenko return "BT_CLOSED"; 18520d1803aSAndrei Emeltchenko } 18620d1803aSAndrei Emeltchenko 18720d1803aSAndrei Emeltchenko return "invalid state"; 18820d1803aSAndrei Emeltchenko } 18920d1803aSAndrei Emeltchenko 1901da177e4SLinus Torvalds /* BD Address */ 1911da177e4SLinus Torvalds typedef struct { 1921da177e4SLinus Torvalds __u8 b[6]; 19366c853ccSGustavo F. Padovan } __packed bdaddr_t; 1941da177e4SLinus Torvalds 195591f47f3SAndre Guedes /* BD Address type */ 196591f47f3SAndre Guedes #define BDADDR_BREDR 0x00 197591f47f3SAndre Guedes #define BDADDR_LE_PUBLIC 0x01 198591f47f3SAndre Guedes #define BDADDR_LE_RANDOM 0x02 199591f47f3SAndre Guedes 200679efe2bSJohan Hedberg static inline bool bdaddr_type_is_valid(__u8 type) 201679efe2bSJohan Hedberg { 202679efe2bSJohan Hedberg switch (type) { 203679efe2bSJohan Hedberg case BDADDR_BREDR: 204679efe2bSJohan Hedberg case BDADDR_LE_PUBLIC: 205679efe2bSJohan Hedberg case BDADDR_LE_RANDOM: 206679efe2bSJohan Hedberg return true; 207679efe2bSJohan Hedberg } 208679efe2bSJohan Hedberg 209679efe2bSJohan Hedberg return false; 210679efe2bSJohan Hedberg } 211679efe2bSJohan Hedberg 212679efe2bSJohan Hedberg static inline bool bdaddr_type_is_le(__u8 type) 213679efe2bSJohan Hedberg { 214679efe2bSJohan Hedberg switch (type) { 215679efe2bSJohan Hedberg case BDADDR_LE_PUBLIC: 216679efe2bSJohan Hedberg case BDADDR_LE_RANDOM: 217679efe2bSJohan Hedberg return true; 218679efe2bSJohan Hedberg } 219679efe2bSJohan Hedberg 220679efe2bSJohan Hedberg return false; 221679efe2bSJohan Hedberg } 222679efe2bSJohan Hedberg 2231da177e4SLinus Torvalds #define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0}}) 224a59ac2f7SMarcel Holtmann #define BDADDR_NONE (&(bdaddr_t) {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}) 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds /* Copy, swap, convert BD Address */ 227f53c20e9SDavid Herrmann static inline int bacmp(const bdaddr_t *ba1, const bdaddr_t *ba2) 2281da177e4SLinus Torvalds { 2291da177e4SLinus Torvalds return memcmp(ba1, ba2, sizeof(bdaddr_t)); 2301da177e4SLinus Torvalds } 231f53c20e9SDavid Herrmann static inline void bacpy(bdaddr_t *dst, const bdaddr_t *src) 2321da177e4SLinus Torvalds { 2331da177e4SLinus Torvalds memcpy(dst, src, sizeof(bdaddr_t)); 2341da177e4SLinus Torvalds } 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds void baswap(bdaddr_t *dst, bdaddr_t *src); 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds /* Common socket structures and functions */ 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds #define bt_sk(__sk) ((struct bt_sock *) __sk) 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds struct bt_sock { 2431da177e4SLinus Torvalds struct sock sk; 2441da177e4SLinus Torvalds struct list_head accept_q; 2451da177e4SLinus Torvalds struct sock *parent; 246c5daa683SGustavo Padovan unsigned long flags; 247d9763698SMarcel Holtmann void (*skb_msg_name)(struct sk_buff *, void *, int *); 248c5daa683SGustavo Padovan }; 249c5daa683SGustavo Padovan 250c5daa683SGustavo Padovan enum { 251c5daa683SGustavo Padovan BT_SK_DEFER_SETUP, 252c5daa683SGustavo Padovan BT_SK_SUSPEND, 2531da177e4SLinus Torvalds }; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds struct bt_sock_list { 2561da177e4SLinus Torvalds struct hlist_head head; 2571da177e4SLinus Torvalds rwlock_t lock; 258256a06c8SMasatake YAMATO #ifdef CONFIG_PROC_FS 259256a06c8SMasatake YAMATO int (* custom_seq_show)(struct seq_file *, void *); 260256a06c8SMasatake YAMATO #endif 2611da177e4SLinus Torvalds }; 2621da177e4SLinus Torvalds 263ec1b4cf7SStephen Hemminger int bt_sock_register(int proto, const struct net_proto_family *ops); 264be9f97f0SDavid Herrmann void bt_sock_unregister(int proto); 2651da177e4SLinus Torvalds void bt_sock_link(struct bt_sock_list *l, struct sock *s); 2661da177e4SLinus Torvalds void bt_sock_unlink(struct bt_sock_list *l, struct sock *s); 2671b784140SYing Xue int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, 2681b784140SYing Xue int flags); 2691b784140SYing Xue int bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg, 2701b784140SYing Xue size_t len, int flags); 2711da177e4SLinus Torvalds uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait); 2723241ad82SMarcel Holtmann int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg); 2731da177e4SLinus Torvalds int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo); 274e793dcf0SJohan Hedberg int bt_sock_wait_ready(struct sock *sk, unsigned long flags); 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds void bt_accept_enqueue(struct sock *parent, struct sock *sk); 2771da177e4SLinus Torvalds void bt_accept_unlink(struct sock *sk); 2781da177e4SLinus Torvalds struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock); 2791da177e4SLinus Torvalds 2801da177e4SLinus Torvalds /* Skb helpers */ 28100e3112cSMat Martineau struct l2cap_ctrl { 28207758991SMarcel Holtmann __u8 sframe:1, 28300e3112cSMat Martineau poll:1, 28400e3112cSMat Martineau final:1, 28500e3112cSMat Martineau fcs:1, 28600e3112cSMat Martineau sar:2, 28700e3112cSMat Martineau super:2; 28800e3112cSMat Martineau __u16 reqseq; 28900e3112cSMat Martineau __u16 txseq; 29000e3112cSMat Martineau __u8 retries; 291a4368ff3SJohan Hedberg __le16 psm; 292a4368ff3SJohan Hedberg bdaddr_t bdaddr; 293a4368ff3SJohan Hedberg struct l2cap_chan *chan; 29400e3112cSMat Martineau }; 29500e3112cSMat Martineau 2963119ae95SJohan Hedberg struct hci_dev; 2973119ae95SJohan Hedberg 2981904a853SMarcel Holtmann typedef void (*hci_req_complete_t)(struct hci_dev *hdev, u8 status, u16 opcode); 299e6214487SJohan Hedberg typedef void (*hci_req_complete_skb_t)(struct hci_dev *hdev, u8 status, 300e6214487SJohan Hedberg u16 opcode, struct sk_buff *skb); 3013119ae95SJohan Hedberg 30244d27137SJohan Hedberg #define HCI_REQ_START BIT(0) 30344d27137SJohan Hedberg #define HCI_REQ_SKB BIT(1) 30444d27137SJohan Hedberg 305242c0ebdSMarcel Holtmann struct hci_ctrl { 306242c0ebdSMarcel Holtmann __u16 opcode; 30744d27137SJohan Hedberg u8 req_flags; 308242c0ebdSMarcel Holtmann u8 req_event; 30944d27137SJohan Hedberg union { 310242c0ebdSMarcel Holtmann hci_req_complete_t req_complete; 311242c0ebdSMarcel Holtmann hci_req_complete_skb_t req_complete_skb; 312db6e3e8dSJohan Hedberg }; 31344d27137SJohan Hedberg }; 314db6e3e8dSJohan Hedberg 3151da177e4SLinus Torvalds struct bt_skb_cb { 3160d48d939SMarcel Holtmann __u8 pkt_type; 3176368c235SEyal Birger __u8 force_active; 31833e882a5SSuraj Sumangala __u16 expect; 3196368c235SEyal Birger __u8 incoming:1; 320db6e3e8dSJohan Hedberg union { 321a4368ff3SJohan Hedberg struct l2cap_ctrl l2cap; 322242c0ebdSMarcel Holtmann struct hci_ctrl hci; 323db6e3e8dSJohan Hedberg }; 3241da177e4SLinus Torvalds }; 3251c2acffbSGustavo F. Padovan #define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb)) 3261da177e4SLinus Torvalds 327f5c4a42aSMarcel Holtmann #define hci_skb_pkt_type(skb) bt_cb((skb))->pkt_type 328f5c4a42aSMarcel Holtmann #define hci_skb_expect(skb) bt_cb((skb))->expect 329f5c4a42aSMarcel Holtmann #define hci_skb_opcode(skb) bt_cb((skb))->hci.opcode 330f5c4a42aSMarcel Holtmann 331dd0fc66fSAl Viro static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how) 3321da177e4SLinus Torvalds { 3331da177e4SLinus Torvalds struct sk_buff *skb; 3341da177e4SLinus Torvalds 335c3c7ea65SGustavo Padovan skb = alloc_skb(len + BT_SKB_RESERVE, how); 3365fcc86bdSJohan Hedberg if (skb) 3371da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 3381da177e4SLinus Torvalds return skb; 3391da177e4SLinus Torvalds } 3401da177e4SLinus Torvalds 3415a9d0a3fSWaldemar Rymarkiewicz static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk, 3425a9d0a3fSWaldemar Rymarkiewicz unsigned long len, int nb, int *err) 3431da177e4SLinus Torvalds { 3441da177e4SLinus Torvalds struct sk_buff *skb; 3451da177e4SLinus Torvalds 346c3c7ea65SGustavo Padovan skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err); 3475fcc86bdSJohan Hedberg if (skb) 3481da177e4SLinus Torvalds skb_reserve(skb, BT_SKB_RESERVE); 349e454c844SGustavo F. Padovan 350e454c844SGustavo F. Padovan if (!skb && *err) 351e454c844SGustavo F. Padovan return NULL; 352e454c844SGustavo F. Padovan 353e454c844SGustavo F. Padovan *err = sock_error(sk); 354e454c844SGustavo F. Padovan if (*err) 355e454c844SGustavo F. Padovan goto out; 356e454c844SGustavo F. Padovan 357e454c844SGustavo F. Padovan if (sk->sk_shutdown) { 358e454c844SGustavo F. Padovan *err = -ECONNRESET; 359e454c844SGustavo F. Padovan goto out; 360e454c844SGustavo F. Padovan } 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvalds return skb; 363e454c844SGustavo F. Padovan 364e454c844SGustavo F. Padovan out: 365e454c844SGustavo F. Padovan kfree_skb(skb); 366e454c844SGustavo F. Padovan return NULL; 3671da177e4SLinus Torvalds } 3681da177e4SLinus Torvalds 369e175072fSJoe Perches int bt_to_errno(__u16 code); 3701da177e4SLinus Torvalds 3716befc644SMarcel Holtmann void hci_sock_set_flag(struct sock *sk, int nr); 3726befc644SMarcel Holtmann void hci_sock_clear_flag(struct sock *sk, int nr); 373c85be545SMarcel Holtmann int hci_sock_test_flag(struct sock *sk, int nr); 374d0f172b1SJohan Hedberg unsigned short hci_sock_get_channel(struct sock *sk); 37570ecce91SMarcel Holtmann u32 hci_sock_get_cookie(struct sock *sk); 3766befc644SMarcel Holtmann 377e74e58f8SJoe Perches int hci_sock_init(void); 378e74e58f8SJoe Perches void hci_sock_cleanup(void); 3796516455dSMarcel Holtmann 380e74e58f8SJoe Perches int bt_sysfs_init(void); 381e74e58f8SJoe Perches void bt_sysfs_cleanup(void); 3826516455dSMarcel Holtmann 383e74e58f8SJoe Perches int bt_procfs_init(struct net *net, const char *name, 384256a06c8SMasatake YAMATO struct bt_sock_list *sk_list, 385256a06c8SMasatake YAMATO int (*seq_show)(struct seq_file *, void *)); 386e74e58f8SJoe Perches void bt_procfs_cleanup(struct net *net, const char *name); 387256a06c8SMasatake YAMATO 388aef7d97cSMarcel Holtmann extern struct dentry *bt_debugfs; 389be9d1227SMarcel Holtmann 39064274518SGustavo F. Padovan int l2cap_init(void); 39164274518SGustavo F. Padovan void l2cap_exit(void); 39264274518SGustavo F. Padovan 393ff50e8afSArron Wang #if IS_ENABLED(CONFIG_BT_BREDR) 39464274518SGustavo F. Padovan int sco_init(void); 39564274518SGustavo F. Padovan void sco_exit(void); 396ff50e8afSArron Wang #else 397ff50e8afSArron Wang static inline int sco_init(void) 398ff50e8afSArron Wang { 399ff50e8afSArron Wang return 0; 400ff50e8afSArron Wang } 401ff50e8afSArron Wang 402ff50e8afSArron Wang static inline void sco_exit(void) 403ff50e8afSArron Wang { 404ff50e8afSArron Wang } 405ff50e8afSArron Wang #endif 40664274518SGustavo F. Padovan 4076d785aa3SJohan Hedberg int mgmt_init(void); 4086d785aa3SJohan Hedberg void mgmt_exit(void); 4096d785aa3SJohan Hedberg 410d22015aaSOctavian Purdila void bt_sock_reclassify_lock(struct sock *sk, int proto); 411d22015aaSOctavian Purdila 4121da177e4SLinus Torvalds #endif /* __BLUETOOTH_H */ 413