| .. | .. |
|---|
| 29 | 29 | |
|---|
| 30 | 30 | #include <asm/unaligned.h> |
|---|
| 31 | 31 | #include <linux/atomic.h> |
|---|
| 32 | +#include <linux/android_kabi.h> |
|---|
| 32 | 33 | |
|---|
| 33 | 34 | /* L2CAP defaults */ |
|---|
| 34 | 35 | #define L2CAP_DEFAULT_MTU 672 |
|---|
| .. | .. |
|---|
| 47 | 48 | #define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF |
|---|
| 48 | 49 | #define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */ |
|---|
| 49 | 50 | #define L2CAP_LE_MIN_MTU 23 |
|---|
| 51 | +#define L2CAP_ECRED_CONN_SCID_MAX 5 |
|---|
| 50 | 52 | |
|---|
| 51 | 53 | #define L2CAP_DISC_TIMEOUT msecs_to_jiffies(100) |
|---|
| 52 | 54 | #define L2CAP_DISC_REJ_TIMEOUT msecs_to_jiffies(5000) |
|---|
| .. | .. |
|---|
| 119 | 121 | #define L2CAP_LE_CONN_REQ 0x14 |
|---|
| 120 | 122 | #define L2CAP_LE_CONN_RSP 0x15 |
|---|
| 121 | 123 | #define L2CAP_LE_CREDITS 0x16 |
|---|
| 124 | +#define L2CAP_ECRED_CONN_REQ 0x17 |
|---|
| 125 | +#define L2CAP_ECRED_CONN_RSP 0x18 |
|---|
| 126 | +#define L2CAP_ECRED_RECONF_REQ 0x19 |
|---|
| 127 | +#define L2CAP_ECRED_RECONF_RSP 0x1a |
|---|
| 122 | 128 | |
|---|
| 123 | 129 | /* L2CAP extended feature mask */ |
|---|
| 124 | 130 | #define L2CAP_FEAT_FLOWCTL 0x00000001 |
|---|
| .. | .. |
|---|
| 277 | 283 | #define L2CAP_CR_SEC_BLOCK 0x0003 |
|---|
| 278 | 284 | #define L2CAP_CR_NO_MEM 0x0004 |
|---|
| 279 | 285 | #define L2CAP_CR_BAD_AMP 0x0005 |
|---|
| 280 | | -#define L2CAP_CR_AUTHENTICATION 0x0005 |
|---|
| 281 | | -#define L2CAP_CR_AUTHORIZATION 0x0006 |
|---|
| 282 | | -#define L2CAP_CR_BAD_KEY_SIZE 0x0007 |
|---|
| 283 | | -#define L2CAP_CR_ENCRYPTION 0x0008 |
|---|
| 284 | | -#define L2CAP_CR_INVALID_SCID 0x0009 |
|---|
| 285 | | -#define L2CAP_CR_SCID_IN_USE 0x000A |
|---|
| 286 | +#define L2CAP_CR_INVALID_SCID 0x0006 |
|---|
| 287 | +#define L2CAP_CR_SCID_IN_USE 0x0007 |
|---|
| 288 | + |
|---|
| 289 | +/* credit based connect results */ |
|---|
| 290 | +#define L2CAP_CR_LE_SUCCESS 0x0000 |
|---|
| 291 | +#define L2CAP_CR_LE_BAD_PSM 0x0002 |
|---|
| 292 | +#define L2CAP_CR_LE_NO_MEM 0x0004 |
|---|
| 293 | +#define L2CAP_CR_LE_AUTHENTICATION 0x0005 |
|---|
| 294 | +#define L2CAP_CR_LE_AUTHORIZATION 0x0006 |
|---|
| 295 | +#define L2CAP_CR_LE_BAD_KEY_SIZE 0x0007 |
|---|
| 296 | +#define L2CAP_CR_LE_ENCRYPTION 0x0008 |
|---|
| 297 | +#define L2CAP_CR_LE_INVALID_SCID 0x0009 |
|---|
| 298 | +#define L2CAP_CR_LE_SCID_IN_USE 0X000A |
|---|
| 299 | +#define L2CAP_CR_LE_UNACCEPT_PARAMS 0X000B |
|---|
| 300 | +#define L2CAP_CR_LE_INVALID_PARAMS 0X000C |
|---|
| 286 | 301 | |
|---|
| 287 | 302 | /* connect/create channel status */ |
|---|
| 288 | 303 | #define L2CAP_CS_NO_INFO 0x0000 |
|---|
| .. | .. |
|---|
| 292 | 307 | struct l2cap_conf_req { |
|---|
| 293 | 308 | __le16 dcid; |
|---|
| 294 | 309 | __le16 flags; |
|---|
| 295 | | - __u8 data[0]; |
|---|
| 310 | + __u8 data[]; |
|---|
| 296 | 311 | } __packed; |
|---|
| 297 | 312 | |
|---|
| 298 | 313 | struct l2cap_conf_rsp { |
|---|
| 299 | 314 | __le16 scid; |
|---|
| 300 | 315 | __le16 flags; |
|---|
| 301 | 316 | __le16 result; |
|---|
| 302 | | - __u8 data[0]; |
|---|
| 317 | + __u8 data[]; |
|---|
| 303 | 318 | } __packed; |
|---|
| 304 | 319 | |
|---|
| 305 | 320 | #define L2CAP_CONF_SUCCESS 0x0000 |
|---|
| .. | .. |
|---|
| 315 | 330 | struct l2cap_conf_opt { |
|---|
| 316 | 331 | __u8 type; |
|---|
| 317 | 332 | __u8 len; |
|---|
| 318 | | - __u8 val[0]; |
|---|
| 333 | + __u8 val[]; |
|---|
| 319 | 334 | } __packed; |
|---|
| 320 | 335 | #define L2CAP_CONF_OPT_SIZE 2 |
|---|
| 321 | 336 | |
|---|
| .. | .. |
|---|
| 352 | 367 | * ever be used in the BR/EDR configuration phase. |
|---|
| 353 | 368 | */ |
|---|
| 354 | 369 | #define L2CAP_MODE_LE_FLOWCTL 0x80 |
|---|
| 370 | +#define L2CAP_MODE_EXT_FLOWCTL 0x81 |
|---|
| 355 | 371 | |
|---|
| 356 | 372 | struct l2cap_conf_efs { |
|---|
| 357 | 373 | __u8 id; |
|---|
| .. | .. |
|---|
| 385 | 401 | struct l2cap_info_rsp { |
|---|
| 386 | 402 | __le16 type; |
|---|
| 387 | 403 | __le16 result; |
|---|
| 388 | | - __u8 data[0]; |
|---|
| 404 | + __u8 data[]; |
|---|
| 389 | 405 | } __packed; |
|---|
| 390 | 406 | |
|---|
| 391 | 407 | struct l2cap_create_chan_req { |
|---|
| .. | .. |
|---|
| 455 | 471 | #define L2CAP_CONN_PARAM_ACCEPTED 0x0000 |
|---|
| 456 | 472 | #define L2CAP_CONN_PARAM_REJECTED 0x0001 |
|---|
| 457 | 473 | |
|---|
| 458 | | -#define L2CAP_LE_MAX_CREDITS 10 |
|---|
| 459 | | -#define L2CAP_LE_DEFAULT_MPS 230 |
|---|
| 460 | | - |
|---|
| 461 | 474 | struct l2cap_le_conn_req { |
|---|
| 462 | 475 | __le16 psm; |
|---|
| 463 | 476 | __le16 scid; |
|---|
| .. | .. |
|---|
| 477 | 490 | struct l2cap_le_credits { |
|---|
| 478 | 491 | __le16 cid; |
|---|
| 479 | 492 | __le16 credits; |
|---|
| 493 | +} __packed; |
|---|
| 494 | + |
|---|
| 495 | +#define L2CAP_ECRED_MIN_MTU 64 |
|---|
| 496 | +#define L2CAP_ECRED_MIN_MPS 64 |
|---|
| 497 | +#define L2CAP_ECRED_MAX_CID 5 |
|---|
| 498 | + |
|---|
| 499 | +struct l2cap_ecred_conn_req { |
|---|
| 500 | + __le16 psm; |
|---|
| 501 | + __le16 mtu; |
|---|
| 502 | + __le16 mps; |
|---|
| 503 | + __le16 credits; |
|---|
| 504 | + __le16 scid[]; |
|---|
| 505 | +} __packed; |
|---|
| 506 | + |
|---|
| 507 | +struct l2cap_ecred_conn_rsp { |
|---|
| 508 | + __le16 mtu; |
|---|
| 509 | + __le16 mps; |
|---|
| 510 | + __le16 credits; |
|---|
| 511 | + __le16 result; |
|---|
| 512 | + __le16 dcid[]; |
|---|
| 513 | +}; |
|---|
| 514 | + |
|---|
| 515 | +struct l2cap_ecred_reconf_req { |
|---|
| 516 | + __le16 mtu; |
|---|
| 517 | + __le16 mps; |
|---|
| 518 | + __le16 scid[]; |
|---|
| 519 | +} __packed; |
|---|
| 520 | + |
|---|
| 521 | +#define L2CAP_RECONF_SUCCESS 0x0000 |
|---|
| 522 | +#define L2CAP_RECONF_INVALID_MTU 0x0001 |
|---|
| 523 | +#define L2CAP_RECONF_INVALID_MPS 0x0002 |
|---|
| 524 | + |
|---|
| 525 | +struct l2cap_ecred_reconf_rsp { |
|---|
| 526 | + __le16 result; |
|---|
| 480 | 527 | } __packed; |
|---|
| 481 | 528 | |
|---|
| 482 | 529 | /* ----- L2CAP channels and connections ----- */ |
|---|
| .. | .. |
|---|
| 598 | 645 | void *data; |
|---|
| 599 | 646 | const struct l2cap_ops *ops; |
|---|
| 600 | 647 | struct mutex lock; |
|---|
| 648 | + |
|---|
| 649 | + ANDROID_KABI_RESERVE(1); |
|---|
| 650 | + ANDROID_KABI_RESERVE(2); |
|---|
| 601 | 651 | }; |
|---|
| 602 | 652 | |
|---|
| 603 | 653 | struct l2cap_ops { |
|---|
| .. | .. |
|---|
| 616 | 666 | void (*suspend) (struct l2cap_chan *chan); |
|---|
| 617 | 667 | void (*set_shutdown) (struct l2cap_chan *chan); |
|---|
| 618 | 668 | long (*get_sndtimeo) (struct l2cap_chan *chan); |
|---|
| 669 | + struct pid *(*get_peer_pid) (struct l2cap_chan *chan); |
|---|
| 619 | 670 | struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan, |
|---|
| 620 | 671 | unsigned long hdr_len, |
|---|
| 621 | 672 | unsigned long len, int nb); |
|---|
| 622 | 673 | int (*filter) (struct l2cap_chan * chan, |
|---|
| 623 | 674 | struct sk_buff *skb); |
|---|
| 675 | + |
|---|
| 676 | + ANDROID_KABI_RESERVE(1); |
|---|
| 677 | + ANDROID_KABI_RESERVE(2); |
|---|
| 624 | 678 | }; |
|---|
| 625 | 679 | |
|---|
| 626 | 680 | struct l2cap_conn { |
|---|
| .. | .. |
|---|
| 656 | 710 | struct mutex chan_lock; |
|---|
| 657 | 711 | struct kref ref; |
|---|
| 658 | 712 | struct list_head users; |
|---|
| 713 | + |
|---|
| 714 | + ANDROID_KABI_RESERVE(1); |
|---|
| 715 | + ANDROID_KABI_RESERVE(2); |
|---|
| 659 | 716 | }; |
|---|
| 660 | 717 | |
|---|
| 661 | 718 | struct l2cap_user { |
|---|
| .. | .. |
|---|
| 722 | 779 | FLAG_EFS_ENABLE, |
|---|
| 723 | 780 | FLAG_DEFER_SETUP, |
|---|
| 724 | 781 | FLAG_LE_CONN_REQ_SENT, |
|---|
| 782 | + FLAG_ECRED_CONN_REQ_SENT, |
|---|
| 725 | 783 | FLAG_PENDING_SECURITY, |
|---|
| 726 | 784 | FLAG_HOLD_HCI_CONN, |
|---|
| 727 | 785 | }; |
|---|
| .. | .. |
|---|
| 798 | 856 | }; |
|---|
| 799 | 857 | |
|---|
| 800 | 858 | void l2cap_chan_hold(struct l2cap_chan *c); |
|---|
| 859 | +struct l2cap_chan *l2cap_chan_hold_unless_zero(struct l2cap_chan *c); |
|---|
| 801 | 860 | void l2cap_chan_put(struct l2cap_chan *c); |
|---|
| 802 | 861 | |
|---|
| 803 | 862 | static inline void l2cap_chan_lock(struct l2cap_chan *chan) |
|---|
| .. | .. |
|---|
| 915 | 974 | } |
|---|
| 916 | 975 | |
|---|
| 917 | 976 | extern bool disable_ertm; |
|---|
| 977 | +extern bool enable_ecred; |
|---|
| 918 | 978 | |
|---|
| 919 | 979 | int l2cap_init_sockets(void); |
|---|
| 920 | 980 | void l2cap_cleanup_sockets(void); |
|---|
| 921 | 981 | bool l2cap_is_socket(struct socket *sock); |
|---|
| 922 | 982 | |
|---|
| 923 | 983 | void __l2cap_le_connect_rsp_defer(struct l2cap_chan *chan); |
|---|
| 984 | +void __l2cap_ecred_conn_rsp_defer(struct l2cap_chan *chan); |
|---|
| 924 | 985 | void __l2cap_connect_rsp_defer(struct l2cap_chan *chan); |
|---|
| 925 | 986 | |
|---|
| 926 | 987 | int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm); |
|---|
| .. | .. |
|---|
| 930 | 991 | void l2cap_chan_close(struct l2cap_chan *chan, int reason); |
|---|
| 931 | 992 | int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, |
|---|
| 932 | 993 | bdaddr_t *dst, u8 dst_type); |
|---|
| 994 | +int l2cap_chan_reconfigure(struct l2cap_chan *chan, __u16 mtu); |
|---|
| 933 | 995 | int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); |
|---|
| 934 | 996 | void l2cap_chan_busy(struct l2cap_chan *chan, int busy); |
|---|
| 935 | 997 | int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator); |
|---|
| .. | .. |
|---|
| 937 | 999 | int l2cap_ertm_init(struct l2cap_chan *chan); |
|---|
| 938 | 1000 | void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); |
|---|
| 939 | 1001 | void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan); |
|---|
| 1002 | +typedef void (*l2cap_chan_func_t)(struct l2cap_chan *chan, void *data); |
|---|
| 1003 | +void l2cap_chan_list(struct l2cap_conn *conn, l2cap_chan_func_t func, |
|---|
| 1004 | + void *data); |
|---|
| 940 | 1005 | void l2cap_chan_del(struct l2cap_chan *chan, int err); |
|---|
| 941 | 1006 | void l2cap_send_conn_req(struct l2cap_chan *chan); |
|---|
| 942 | 1007 | void l2cap_move_start(struct l2cap_chan *chan); |
|---|