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