M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@@ -0,0 +1,293 @@
/*
Copyright (c) 2010-2012 The Linux Foundation. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 and
only version 2 as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#ifndef __AMP_H
#define __AMP_H
/* AMP defaults */
#define A2MP_RSP_TIMEOUT (8000) /* 8 seconds */
/* A2MP Protocol */
/* A2MP command codes */
#define A2MP_COMMAND_REJ 0x01
#define A2MP_DISCOVER_REQ 0x02
#define A2MP_DISCOVER_RSP 0x03
#define A2MP_CHANGE_NOTIFY 0x04
#define A2MP_CHANGE_RSP 0x05
#define A2MP_GETINFO_REQ 0x06
#define A2MP_GETINFO_RSP 0x07
#define A2MP_GETAMPASSOC_REQ 0x08
#define A2MP_GETAMPASSOC_RSP 0x09
#define A2MP_CREATEPHYSLINK_REQ 0x0A
#define A2MP_CREATEPHYSLINK_RSP 0x0B
#define A2MP_DISCONNPHYSLINK_REQ 0x0C
#define A2MP_DISCONNPHYSLINK_RSP 0x0D
struct a2mp_cmd_hdr {
__u8 code;
__u8 ident;
__le16 len;
} __packed;
struct a2mp_cmd_rej {
__le16 reason;
} __packed;
struct a2mp_discover_req {
__le16 mtu;
__le16 ext_feat;
} __packed;
struct a2mp_cl {
__u8 id;
__u8 type;
__u8 status;
} __packed;
struct a2mp_discover_rsp {
__le16 mtu;
__le16 ext_feat;
struct a2mp_cl cl[0];
} __packed;
struct a2mp_getinfo_req {
__u8 id;
} __packed;
struct a2mp_getinfo_rsp {
__u8 id;
__u8 status;
__le32 total_bw;
__le32 max_bw;
__le32 min_latency;
__le16 pal_cap;
__le16 assoc_size;
} __packed;
struct a2mp_getampassoc_req {
__u8 id;
} __packed;
struct a2mp_getampassoc_rsp {
__u8 id;
__u8 status;
__u8 amp_assoc[0];
} __packed;
struct a2mp_createphyslink_req {
__u8 local_id;
__u8 remote_id;
__u8 amp_assoc[0];
} __packed;
struct a2mp_createphyslink_rsp {
__u8 local_id;
__u8 remote_id;
__u8 status;
} __packed;
struct a2mp_disconnphyslink_req {
__u8 local_id;
__u8 remote_id;
} __packed;
struct a2mp_disconnphyslink_rsp {
__u8 local_id;
__u8 remote_id;
__u8 status;
} __packed;
/* L2CAP-AMP module interface */
int amp_init(void);
void amp_exit(void);
/* L2CAP-AMP fixed channel interface */
void amp_conn_ind(struct hci_conn *hcon, struct sk_buff *skb);
/* L2CAP-AMP link interface */
void amp_create_physical(struct l2cap_conn *conn, struct sock *sk);
void amp_accept_physical(struct l2cap_conn *conn, u8 id, struct sock *sk);
/* AMP manager internals */
struct amp_ctrl {
struct amp_mgr *mgr;
__u8 id;
__u8 type;
__u8 status;
__u32 total_bw;
__u32 max_bw;
__u32 min_latency;
__u16 pal_cap;
__u16 max_assoc_size;
};
struct amp_mgr {
struct list_head list;
__u8 discovered;
__u8 next_ident;
struct l2cap_conn *l2cap_conn;
struct socket *a2mp_sock;
struct list_head ctx_list;
rwlock_t ctx_list_lock;
struct amp_ctrl *ctrls; /* @@ TODO s.b. list of controllers */
struct sk_buff *skb;
__u8 connected;
};
/* AMP Manager signalling contexts */
#define AMP_GETAMPASSOC 1
#define AMP_CREATEPHYSLINK 2
#define AMP_ACCEPTPHYSLINK 3
#define AMP_CREATELOGLINK 4
#define AMP_ACCEPTLOGLINK 5
/* Get AMP Assoc sequence */
#define AMP_GAA_INIT 0
#define AMP_GAA_RLAA_COMPLETE 1
struct amp_gaa_state {
__u8 req_ident;
__u16 len_so_far;
__u8 *assoc;
};
/* Create Physical Link sequence */
#define AMP_CPL_INIT 0
#define AMP_CPL_DISC_RSP 1
#define AMP_CPL_GETINFO_RSP 2
#define AMP_CPL_GAA_RSP 3
#define AMP_CPL_CPL_STATUS 4
#define AMP_CPL_WRA_COMPLETE 5
#define AMP_CPL_CHANNEL_SELECT 6
#define AMP_CPL_RLA_COMPLETE 7
#define AMP_CPL_PL_COMPLETE 8
#define AMP_CPL_PL_CANCEL 9
struct amp_cpl_state {
__u8 remote_id;
__u16 max_len;
__u8 *remote_assoc;
__u8 *local_assoc;
__u16 len_so_far;
__u16 rem_len;
__u8 phy_handle;
};
/* Accept Physical Link sequence */
#define AMP_APL_INIT 0
#define AMP_APL_APL_STATUS 1
#define AMP_APL_WRA_COMPLETE 2
#define AMP_APL_PL_COMPLETE 3
struct amp_apl_state {
__u8 remote_id;
__u8 req_ident;
__u8 *remote_assoc;
__u16 len_so_far;
__u16 rem_len;
__u8 phy_handle;
};
/* Create/Accept Logical Link sequence */
#define AMP_LOG_INIT 0
#define AMP_LOG_LL_STATUS 1
#define AMP_LOG_LL_COMPLETE 2
struct amp_log_state {
__u8 remote_id;
};
/* Possible event types a context may wait for */
#define AMP_INIT 0x01
#define AMP_HCI_EVENT 0x02
#define AMP_HCI_CMD_CMPLT 0x04
#define AMP_HCI_CMD_STATUS 0x08
#define AMP_A2MP_RSP 0x10
#define AMP_KILLED 0x20
#define AMP_CANCEL 0x40
struct amp_ctx {
struct list_head list;
struct amp_mgr *mgr;
struct hci_dev *hdev;
__u8 type;
__u8 state;
union {
struct amp_gaa_state gaa;
struct amp_cpl_state cpl;
struct amp_apl_state apl;
} d;
__u8 evt_type;
__u8 evt_code;
__u16 opcode;
__u8 id;
__u8 rsp_ident;
struct sock *sk;
struct amp_ctx *deferred;
struct timer_list timer;
};
/* AMP work */
struct amp_work_pl_timeout {
struct work_struct work;
struct amp_ctrl *ctrl;
};
struct amp_work_ctx_timeout {
struct work_struct work;
struct amp_ctx *ctx;
};
struct amp_work_data_ready {
struct work_struct work;
struct sock *sk;
int bytes;
};
struct amp_work_state_change {
struct work_struct work;
struct sock *sk;
};
struct amp_work_conn_ind {
struct work_struct work;
struct hci_conn *hcon;
struct sk_buff *skb;
};
struct amp_work_create_physical {
struct work_struct work;
struct l2cap_conn *conn;
u8 id;
struct sock *sk;
};
struct amp_work_accept_physical {
struct work_struct work;
struct l2cap_conn *conn;
u8 id;
struct sock *sk;
};
struct amp_work_cmd_cmplt {
struct work_struct work;
struct hci_dev *hdev;
u16 opcode;
struct sk_buff *skb;
};
struct amp_work_cmd_status {
struct work_struct work;
struct hci_dev *hdev;
u16 opcode;
u8 status;
};
struct amp_work_event {
struct work_struct work;
struct hci_dev *hdev;
u8 event;
struct sk_buff *skb;
};
#endif /* __AMP_H */

View File

@@ -0,0 +1,296 @@
/*
BlueZ - Bluetooth protocol stack for Linux
Copyright (c) 2000-2001, 2010-2013 The Linux Foundation. All rights reserved.
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
#ifndef __BLUETOOTH_H
#define __BLUETOOTH_H
#include <linux/types.h>
#include <asm/byteorder.h>
#include <linux/list.h>
#include <linux/poll.h>
#include <net/sock.h>
#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
#define PF_BLUETOOTH AF_BLUETOOTH
#endif
/* Reserv for core and drivers use */
#define BT_SKB_RESERVE 8
#define BT_SKB_RESERVE_80211 32
#define BTPROTO_L2CAP 0
#define BTPROTO_HCI 1
#define BTPROTO_SCO 2
#define BTPROTO_RFCOMM 3
#define BTPROTO_BNEP 4
#define BTPROTO_CMTP 5
#define BTPROTO_HIDP 6
#define BTPROTO_AVDTP 7
#define SOL_HCI 0
#define SOL_L2CAP 6
#define SOL_SCO 17
#define SOL_RFCOMM 18
#define BT_SECURITY 4
struct bt_security {
__u8 level;
__u8 key_size;
};
#define BT_SECURITY_SDP 0
#define BT_SECURITY_LOW 1
#define BT_SECURITY_MEDIUM 2
#define BT_SECURITY_HIGH 3
#define BT_SECURITY_VERY_HIGH 4
#define BT_DEFER_SETUP 7
#define BT_FLUSHABLE 8
#define BT_POWER 9
struct bt_power {
__u8 force_active;
};
#define BT_AMP_POLICY 10
/* Require BR/EDR (default policy)
* AMP controllers cannot be used
* Channel move requests from the remote device are denied
* If the L2CAP channel is currently using AMP, move the channel to BR/EDR
*/
#define BT_AMP_POLICY_REQUIRE_BR_EDR 0
/* Prefer BR/EDR
* Allow use of AMP controllers
* If the L2CAP channel is currently on AMP, move it to BR/EDR
* Channel move requests from the remote device are allowed
*/
#define BT_AMP_POLICY_PREFER_BR_EDR 1
/* Prefer AMP
* Allow use of AMP controllers
* If the L2CAP channel is currently on BR/EDR and AMP controller
* resources are available, initiate a channel move to AMP
* Channel move requests from the remote device are allowed
* If the L2CAP socket has not been connected yet, try to create
* and configure the channel directly on an AMP controller rather
* than BR/EDR
*/
#define BT_AMP_POLICY_PREFER_AMP 2
#define BT_LE_PARAMS 100
#define BT_LE_SCAN_WINDOW_MIN 0x0004
#define BT_LE_SCAN_WINDOW_MAX 0x4000
#define BT_LE_SCAN_WINDOW_DEF 0x0004
#define BT_LE_SCAN_INTERVAL_MIN 0x0004
#define BT_LE_SCAN_INTERVAL_MAX 0x4000
#define BT_LE_SCAN_INTERVAL_DEF 0x0008
#define BT_LE_CONN_INTERVAL_MIN 0x0006
#define BT_LE_CONN_INTERVAL_MAX 0x0C80
#define BT_LE_CONN_INTERVAL_MIN_DEF 0x0008
#define BT_LE_CONN_INTERVAL_MAX_DEF 0x0100
#define BT_LE_LATENCY_MAX 0x01F4
#define BT_LE_LATENCY_DEF 0x0000
#define BT_LE_SUP_TO_MIN 0x000A
#define BT_LE_SUP_TO_MAX 0x0C80
#define BT_LE_SUP_TO_DEFAULT 0X03E8
#define BT_INFO(fmt, arg...) printk(KERN_INFO "Bluetooth: " fmt "\n" , ## arg)
#define BT_ERR(fmt, arg...) printk(KERN_ERR "%s: " fmt "\n" , __func__ , ## arg)
#define BT_DBG(fmt, arg...) pr_debug("%s: " fmt "\n" , __func__ , ## arg)
/* Connection and socket states */
enum {
BT_CONNECTED = 1, /* Equal to TCP_ESTABLISHED to make net code happy */
BT_OPEN,
BT_BOUND,
BT_LISTEN,
BT_CONNECT,
BT_CONNECT2,
BT_CONFIG,
BT_DISCONN,
BT_CLOSED
};
/* BD Address */
typedef struct {
__u8 b[6];
} __packed bdaddr_t;
#define BDADDR_ANY (&(bdaddr_t) {{0, 0, 0, 0, 0, 0} })
#define BDADDR_LOCAL (&(bdaddr_t) {{0, 0, 0, 0xff, 0xff, 0xff} })
/* Copy, swap, convert BD Address */
static inline int bacmp(bdaddr_t *ba1, bdaddr_t *ba2)
{
return memcmp(ba1, ba2, sizeof(bdaddr_t));
}
static inline void bacpy(bdaddr_t *dst, bdaddr_t *src)
{
memcpy(dst, src, sizeof(bdaddr_t));
}
void baswap(bdaddr_t *dst, bdaddr_t *src);
char *batostr(bdaddr_t *ba);
bdaddr_t *strtoba(char *str);
/* Common socket structures and functions */
#define bt_sk(__sk) ((struct bt_sock *) __sk)
struct bt_le_params {
__u8 prohibit_remote_chg;
__u8 filter_policy;
__u16 scan_interval;
__u16 scan_window;
__u16 interval_min;
__u16 interval_max;
__u16 latency;
__u16 supervision_timeout;
__u16 min_ce_len;
__u16 max_ce_len;
__u16 conn_timeout;
};
struct bt_sock {
struct sock sk;
bdaddr_t src;
bdaddr_t dst;
struct list_head accept_q;
struct sock *parent;
u32 defer_setup;
struct bt_le_params le_params;
};
struct bt_sock_list {
struct hlist_head head;
rwlock_t lock;
};
int bt_sock_register(int proto, const struct net_proto_family *ops);
int bt_sock_unregister(int proto);
void bt_sock_link(struct bt_sock_list *l, struct sock *s);
void bt_sock_unlink(struct bt_sock_list *l, struct sock *s);
int bt_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
struct msghdr *msg, size_t len, int flags);
int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock,
struct msghdr *msg, size_t len, int flags);
uint bt_sock_poll(struct file *file, struct socket *sock, poll_table *wait);
int bt_sock_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
int bt_sock_wait_state(struct sock *sk, int state, unsigned long timeo);
void bt_accept_enqueue(struct sock *parent, struct sock *sk);
void bt_accept_unlink(struct sock *sk);
struct sock *bt_accept_dequeue(struct sock *parent, struct socket *newsock);
/* Skb helpers */
struct bt_l2cap_control {
__u8 frame_type;
__u8 final;
__u8 sar;
__u8 super;
__u16 reqseq;
__u16 txseq;
__u8 poll;
__u8 fcs;
};
struct bt_skb_cb {
__u8 pkt_type;
__u8 incoming;
__u16 expect;
__u8 retries;
__u8 force_active;
unsigned short channel;
struct bt_l2cap_control control;
};
#define bt_cb(skb) ((struct bt_skb_cb *)((skb)->cb))
static inline struct sk_buff *bt_skb_alloc(unsigned int len, gfp_t how)
{
struct sk_buff *skb;
skb = alloc_skb(len + BT_SKB_RESERVE, how);
if (skb) {
skb_reserve(skb, BT_SKB_RESERVE);
bt_cb(skb)->incoming = 0;
}
return skb;
}
static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
unsigned long len, int nb, int *err)
{
struct sk_buff *skb;
release_sock(sk);
skb = sock_alloc_send_skb(sk, len + BT_SKB_RESERVE, nb, err);
if (skb) {
skb_reserve(skb, BT_SKB_RESERVE);
bt_cb(skb)->incoming = 0;
}
lock_sock(sk);
if (!skb && *err)
return NULL;
*err = sock_error(sk);
if (*err)
goto out;
if (sk->sk_shutdown) {
*err = -ECONNRESET;
goto out;
}
return skb;
out:
kfree_skb(skb);
return NULL;
}
int bt_err(__u16 code);
extern int hci_sock_init(void);
extern void hci_sock_cleanup(void);
extern int bt_sysfs_init(void);
extern void bt_sysfs_cleanup(void);
extern struct dentry *bt_debugfs;
int l2cap_init(void);
void l2cap_exit(void);
int sco_init(void);
void sco_exit(void);
#endif /* __BLUETOOTH_H */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,721 @@
/*
BlueZ - Bluetooth protocol stack for Linux
Copyright (c) 2000-2001, 2010-2012 The Linux Foundation. All rights reserved.
Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org>
Copyright (C) 2010 Google Inc.
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
#ifndef __L2CAP_H
#define __L2CAP_H
/* L2CAP defaults */
#define L2CAP_DEFAULT_MTU 672
#define L2CAP_DEFAULT_MIN_MTU 48
#define L2CAP_DEFAULT_MAX_SDU_SIZE 0xffff
#define L2CAP_DEFAULT_FLUSH_TO 0xffff
#define L2CAP_MAX_FLUSH_TO 0x7ff
#define L2CAP_DEFAULT_TX_WINDOW 63
#define L2CAP_DEFAULT_MAX_TX 3
#define L2CAP_DEFAULT_RETRANS_TO 2000 /* 2 seconds */
#define L2CAP_DEFAULT_MONITOR_TO 12000 /* 12 seconds */
#define L2CAP_DEFAULT_MAX_PDU_SIZE 1482 /* Sized for AMP or BR/EDR */
#define L2CAP_DEFAULT_ACK_TO 200
#define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */
#define L2CAP_MAX_ERTM_QUEUED 5
#define L2CAP_MIN_ERTM_QUEUED 2
#define L2CAP_A2MP_DEFAULT_MTU 670
#define L2CAP_TX_WIN_MAX_ENHANCED 0x3f
#define L2CAP_TX_WIN_MAX_EXTENDED 0x3fff
#define L2CAP_LE_DEFAULT_MTU 23
#define L2CAP_CONN_TIMEOUT (40000) /* 40 seconds */
#define L2CAP_INFO_TIMEOUT (4000) /* 4 seconds */
#define L2CAP_MOVE_TIMEOUT (4*HZ) /* 4 seconds */
#define L2CAP_MOVE_ERTX_TIMEOUT (60*HZ) /* 60 seconds */
/* L2CAP socket address */
struct sockaddr_l2 {
sa_family_t l2_family;
__le16 l2_psm;
bdaddr_t l2_bdaddr;
__le16 l2_cid;
};
/* L2CAP socket options */
#define L2CAP_OPTIONS 0x01
struct l2cap_options {
__u16 omtu;
__u16 imtu;
__u16 flush_to;
__u8 mode;
__u8 fcs;
__u8 max_tx;
__u16 txwin_size;
};
#define L2CAP_CONNINFO 0x02
struct l2cap_conninfo {
__u16 hci_handle;
__u8 dev_class[3];
};
#define L2CAP_LM 0x03
#define L2CAP_LM_MASTER 0x0001
#define L2CAP_LM_AUTH 0x0002
#define L2CAP_LM_ENCRYPT 0x0004
#define L2CAP_LM_TRUSTED 0x0008
#define L2CAP_LM_RELIABLE 0x0010
#define L2CAP_LM_SECURE 0x0020
#define L2CAP_LM_FLUSHABLE 0x0040
/* L2CAP command codes */
#define L2CAP_COMMAND_REJ 0x01
#define L2CAP_CONN_REQ 0x02
#define L2CAP_CONN_RSP 0x03
#define L2CAP_CONF_REQ 0x04
#define L2CAP_CONF_RSP 0x05
#define L2CAP_DISCONN_REQ 0x06
#define L2CAP_DISCONN_RSP 0x07
#define L2CAP_ECHO_REQ 0x08
#define L2CAP_ECHO_RSP 0x09
#define L2CAP_INFO_REQ 0x0a
#define L2CAP_INFO_RSP 0x0b
#define L2CAP_CREATE_CHAN_REQ 0x0c
#define L2CAP_CREATE_CHAN_RSP 0x0d
#define L2CAP_MOVE_CHAN_REQ 0x0e
#define L2CAP_MOVE_CHAN_RSP 0x0f
#define L2CAP_MOVE_CHAN_CFM 0x10
#define L2CAP_MOVE_CHAN_CFM_RSP 0x11
#define L2CAP_CONN_PARAM_UPDATE_REQ 0x12
#define L2CAP_CONN_PARAM_UPDATE_RSP 0x13
/* L2CAP feature mask */
#define L2CAP_FEAT_FLOWCTL 0x00000001
#define L2CAP_FEAT_RETRANS 0x00000002
#define L2CAP_FEAT_ERTM 0x00000008
#define L2CAP_FEAT_STREAMING 0x00000010
#define L2CAP_FEAT_FCS 0x00000020
#define L2CAP_FEAT_FIXED_CHAN 0x00000080
#define L2CAP_FEAT_EXT_WINDOW 0x00000100
#define L2CAP_FEAT_UCD 0x00000200
/* L2CAP checksum option */
#define L2CAP_FCS_NONE 0x00
#define L2CAP_FCS_CRC16 0x01
/* L2CAP fixed channels */
#define L2CAP_FC_L2CAP 0x02
#define L2CAP_FC_A2MP 0x08
/* L2CAP Control Field */
#define L2CAP_CTRL_SAR 0xC000
#define L2CAP_CTRL_REQSEQ 0x3F00
#define L2CAP_CTRL_TXSEQ 0x007E
#define L2CAP_CTRL_FINAL 0x0080
#define L2CAP_CTRL_POLL 0x0010
#define L2CAP_CTRL_SUPERVISE 0x000C
#define L2CAP_CTRL_FRAME_TYPE 0x0001 /* I- or S-Frame */
#define L2CAP_CTRL_TXSEQ_SHIFT 1
#define L2CAP_CTRL_SUPERVISE_SHIFT 2
#define L2CAP_CTRL_POLL_SHIFT 4
#define L2CAP_CTRL_FINAL_SHIFT 7
#define L2CAP_CTRL_REQSEQ_SHIFT 8
#define L2CAP_CTRL_SAR_SHIFT 14
#define L2CAP_EXT_CTRL_SAR 0x00030000
#define L2CAP_EXT_CTRL_REQSEQ 0x0000FFFC
#define L2CAP_EXT_CTRL_TXSEQ 0xFFFC0000
#define L2CAP_EXT_CTRL_FINAL 0x00000002
#define L2CAP_EXT_CTRL_POLL 0x00040000
#define L2CAP_EXT_CTRL_SUPERVISE 0x00030000
#define L2CAP_EXT_CTRL_FRAME_TYPE 0x00000001 /* I- or S-Frame */
#define L2CAP_EXT_CTRL_FINAL_SHIFT 1
#define L2CAP_EXT_CTRL_REQSEQ_SHIFT 2
#define L2CAP_EXT_CTRL_SAR_SHIFT 16
#define L2CAP_EXT_CTRL_SUPERVISE_SHIFT 16
#define L2CAP_EXT_CTRL_POLL_SHIFT 18
#define L2CAP_EXT_CTRL_TXSEQ_SHIFT 18
/* L2CAP Supervisory Frame Types */
#define L2CAP_SFRAME_RR 0x00
#define L2CAP_SFRAME_REJ 0x01
#define L2CAP_SFRAME_RNR 0x02
#define L2CAP_SFRAME_SREJ 0x03
/* L2CAP Segmentation and Reassembly */
#define L2CAP_SAR_UNSEGMENTED 0x00
#define L2CAP_SAR_START 0x01
#define L2CAP_SAR_END 0x02
#define L2CAP_SAR_CONTINUE 0x03
/* L2CAP ERTM / Streaming extra field lengths */
#define L2CAP_SDULEN_SIZE 2
#define L2CAP_FCS_SIZE 2
/* L2CAP structures */
struct l2cap_hdr {
__le16 len;
__le16 cid;
} __packed;
#define L2CAP_HDR_SIZE 4
#define L2CAP_ENHANCED_HDR_SIZE 6
#define L2CAP_EXTENDED_HDR_SIZE 8
struct l2cap_cmd_hdr {
__u8 code;
__u8 ident;
__le16 len;
} __packed;
#define L2CAP_CMD_HDR_SIZE 4
struct l2cap_cmd_rej {
__le16 reason;
} __packed;
struct l2cap_conn_req {
__le16 psm;
__le16 scid;
} __packed;
struct l2cap_conn_rsp {
__le16 dcid;
__le16 scid;
__le16 result;
__le16 status;
} __packed;
/* channel indentifier */
#define L2CAP_CID_SIGNALING 0x0001
#define L2CAP_CID_CONN_LESS 0x0002
#define L2CAP_CID_A2MP 0x0003
#define L2CAP_CID_LE_DATA 0x0004
#define L2CAP_CID_LE_SIGNALING 0x0005
#define L2CAP_CID_SMP 0x0006
#define L2CAP_CID_DYN_START 0x0040
#define L2CAP_CID_DYN_END 0xffff
/* connect result */
#define L2CAP_CR_SUCCESS 0x0000
#define L2CAP_CR_PEND 0x0001
#define L2CAP_CR_BAD_PSM 0x0002
#define L2CAP_CR_SEC_BLOCK 0x0003
#define L2CAP_CR_NO_MEM 0x0004
/* connect status */
#define L2CAP_CS_NO_INFO 0x0000
#define L2CAP_CS_AUTHEN_PEND 0x0001
#define L2CAP_CS_AUTHOR_PEND 0x0002
struct l2cap_conf_req {
__le16 dcid;
__le16 flags;
__u8 data[0];
} __packed;
struct l2cap_conf_rsp {
__le16 scid;
__le16 flags;
__le16 result;
__u8 data[0];
} __packed;
#define L2CAP_CONF_SUCCESS 0x0000
#define L2CAP_CONF_UNACCEPT 0x0001
#define L2CAP_CONF_REJECT 0x0002
#define L2CAP_CONF_UNKNOWN 0x0003
#define L2CAP_CONF_PENDING 0x0004
#define L2CAP_CONF_FLOW_SPEC_REJECT 0x0005
struct l2cap_conf_opt {
__u8 type;
__u8 len;
__u8 val[0];
} __packed;
#define L2CAP_CONF_OPT_SIZE 2
#define L2CAP_CONF_HINT 0x80
#define L2CAP_CONF_MASK 0x7f
#define L2CAP_CONF_MTU 0x01
#define L2CAP_CONF_FLUSH_TO 0x02
#define L2CAP_CONF_QOS 0x03
#define L2CAP_CONF_RFC 0x04
#define L2CAP_CONF_FCS 0x05
#define L2CAP_CONF_EXT_FS 0x06
#define L2CAP_CONF_EXT_WINDOW 0x07
/* QOS Service type */
#define L2CAP_SERVICE_NO_TRAFFIC 0x00
#define L2CAP_SERVICE_BEST_EFFORT 0x01
#define L2CAP_SERVICE_GUARANTEED 0x02
#define L2CAP_CONF_MAX_SIZE 22
struct l2cap_conf_rfc {
__u8 mode;
__u8 txwin_size;
__u8 max_transmit;
__le16 retrans_timeout;
__le16 monitor_timeout;
__le16 max_pdu_size;
} __packed;
struct l2cap_conf_ext_fs {
__u8 id;
__u8 type;
__le16 max_sdu;
__le32 sdu_arr_time;
__le32 acc_latency;
__le32 flush_to;
} __packed;
struct l2cap_conf_prm {
__u8 fcs;
__le32 flush_to;
};
#define L2CAP_MODE_BASIC 0x00
#define L2CAP_MODE_RETRANS 0x01
#define L2CAP_MODE_FLOWCTL 0x02
#define L2CAP_MODE_ERTM 0x03
#define L2CAP_MODE_STREAMING 0x04
struct l2cap_disconn_req {
__le16 dcid;
__le16 scid;
} __packed;
struct l2cap_disconn_rsp {
__le16 dcid;
__le16 scid;
} __packed;
struct l2cap_info_req {
__le16 type;
} __packed;
struct l2cap_info_rsp {
__le16 type;
__le16 result;
__u8 data[0];
} __packed;
struct l2cap_create_chan_req {
__le16 psm;
__le16 scid;
__u8 amp_id;
} __attribute__ ((packed));
struct l2cap_create_chan_rsp {
__le16 dcid;
__le16 scid;
__le16 result;
__le16 status;
} __attribute__ ((packed));
#define L2CAP_CREATE_CHAN_SUCCESS (0x0000)
#define L2CAP_CREATE_CHAN_PENDING (0x0001)
#define L2CAP_CREATE_CHAN_REFUSED_PSM (0x0002)
#define L2CAP_CREATE_CHAN_REFUSED_SECURITY (0x0003)
#define L2CAP_CREATE_CHAN_REFUSED_RESOURCES (0x0004)
#define L2CAP_CREATE_CHAN_REFUSED_CONTROLLER (0x0005)
#define L2CAP_CREATE_CHAN_STATUS_NONE (0x0000)
#define L2CAP_CREATE_CHAN_STATUS_AUTHENTICATION (0x0001)
#define L2CAP_CREATE_CHAN_STATUS_AUTHORIZATION (0x0002)
struct l2cap_move_chan_req {
__le16 icid;
__u8 dest_amp_id;
} __attribute__ ((packed));
struct l2cap_move_chan_rsp {
__le16 icid;
__le16 result;
} __attribute__ ((packed));
#define L2CAP_MOVE_CHAN_SUCCESS (0x0000)
#define L2CAP_MOVE_CHAN_PENDING (0x0001)
#define L2CAP_MOVE_CHAN_REFUSED_CONTROLLER (0x0002)
#define L2CAP_MOVE_CHAN_REFUSED_SAME_ID (0x0003)
#define L2CAP_MOVE_CHAN_REFUSED_CONFIG (0x0004)
#define L2CAP_MOVE_CHAN_REFUSED_COLLISION (0x0005)
#define L2CAP_MOVE_CHAN_REFUSED_NOT_ALLOWED (0x0006)
struct l2cap_move_chan_cfm {
__le16 icid;
__le16 result;
} __attribute__ ((packed));
#define L2CAP_MOVE_CHAN_CONFIRMED (0x0000)
#define L2CAP_MOVE_CHAN_UNCONFIRMED (0x0001)
struct l2cap_move_chan_cfm_rsp {
__le16 icid;
} __attribute__ ((packed));
struct l2cap_amp_signal_work {
struct work_struct work;
struct l2cap_cmd_hdr cmd;
struct l2cap_conn *conn;
struct sk_buff *skb;
u8 *data;
};
struct l2cap_resegment_work {
struct work_struct work;
struct sock *sk;
};
struct l2cap_logical_link_work {
struct work_struct work;
struct hci_chan *chan;
u8 status;
};
/* info type */
#define L2CAP_IT_CL_MTU 0x0001
#define L2CAP_IT_FEAT_MASK 0x0002
#define L2CAP_IT_FIXED_CHAN 0x0003
/* info result */
#define L2CAP_IR_SUCCESS 0x0000
#define L2CAP_IR_NOTSUPP 0x0001
struct l2cap_conn_param_update_req {
__le16 min;
__le16 max;
__le16 latency;
__le16 to_multiplier;
} __packed;
struct l2cap_conn_param_update_rsp {
__le16 result;
} __packed;
/* Connection Parameters result */
#define L2CAP_CONN_PARAM_ACCEPTED 0x0000
#define L2CAP_CONN_PARAM_REJECTED 0x0001
/* ----- L2CAP connections ----- */
struct l2cap_chan_list {
struct sock *head;
rwlock_t lock;
};
struct l2cap_conn {
struct hci_conn *hcon;
bdaddr_t *dst;
bdaddr_t *src;
unsigned int mtu;
__u32 feat_mask;
__u8 fc_mask;
struct amp_mgr *mgr;
__u8 info_state;
__u8 info_ident;
struct timer_list info_timer;
spinlock_t lock;
struct sk_buff *rx_skb;
__u32 rx_len;
__u8 tx_ident;
__u8 disc_reason;
struct l2cap_chan_list chan_list;
};
struct sock_del_list {
struct sock *sk;
struct list_head list;
};
#define L2CAP_INFO_CL_MTU_REQ_SENT 0x01
#define L2CAP_INFO_FEAT_MASK_REQ_SENT 0x04
#define L2CAP_INFO_FEAT_MASK_REQ_DONE 0x08
/* ----- L2CAP channel and socket info ----- */
#define l2cap_pi(sk) ((struct l2cap_pinfo *) sk)
#define TX_QUEUE(sk) (&l2cap_pi(sk)->tx_queue)
#define SREJ_QUEUE(sk) (&l2cap_pi(sk)->srej_queue)
struct l2cap_seq_list {
__u16 head;
__u16 tail;
__u16 size;
__u16 mask;
__u16 *list;
};
struct l2cap_pinfo {
struct bt_sock bt;
__le16 psm;
__u16 dcid;
__u16 scid;
__u16 imtu;
__u16 omtu;
__u16 flush_to;
__u8 mode;
__u8 fixed_channel;
__u8 num_conf_req;
__u8 num_conf_rsp;
__u8 incoming;
__u8 fcs;
__u8 sec_level;
__u8 role_switch;
__u8 force_reliable;
__u8 flushable;
__u8 force_active;
__u8 conf_req[64];
__u8 conf_len;
__u8 conf_ident;
__u16 conf_state;
__u8 conn_state;
__u8 tx_state;
__u8 rx_state;
__u8 reconf_state;
__u8 amp_id;
__u8 amp_move_id;
__u8 amp_move_state;
__u8 amp_move_role;
__u8 amp_move_cmd_ident;
__u16 amp_move_reqseq;
__u16 amp_move_event;
__u16 next_tx_seq;
__u16 expected_ack_seq;
__u16 expected_tx_seq;
__u16 buffer_seq;
__u16 srej_save_reqseq;
__u16 last_acked_seq;
__u32 frames_sent;
__u16 unacked_frames;
__u8 retry_count;
__u16 srej_queue_next;
__u16 sdu_len;
struct sk_buff *sdu;
struct sk_buff *sdu_last_frag;
atomic_t ertm_queued;
__u8 ident;
__u16 tx_win;
__u16 tx_win_max;
__u16 ack_win;
__u8 max_tx;
__u8 amp_pref;
__u16 remote_tx_win;
__u8 remote_max_tx;
__u8 extended_control;
__u16 retrans_timeout;
__u16 monitor_timeout;
__u16 remote_mps;
__u16 mps;
__le16 sport;
struct delayed_work retrans_work;
struct delayed_work monitor_work;
struct delayed_work ack_work;
struct work_struct tx_work;
struct sk_buff_head tx_queue;
struct sk_buff_head srej_queue;
struct l2cap_seq_list srej_list;
struct l2cap_seq_list retrans_list;
struct hci_conn *ampcon;
struct hci_chan *ampchan;
struct l2cap_conn *conn;
struct l2cap_conf_prm local_conf;
struct l2cap_conf_prm remote_conf;
struct l2cap_conf_ext_fs local_fs;
struct l2cap_conf_ext_fs remote_fs;
struct sock *next_c;
struct sock *prev_c;
};
#define L2CAP_CONF_REQ_SENT 0x0001
#define L2CAP_CONF_INPUT_DONE 0x0002
#define L2CAP_CONF_OUTPUT_DONE 0x0004
#define L2CAP_CONF_MTU_DONE 0x0008
#define L2CAP_CONF_MODE_DONE 0x0010
#define L2CAP_CONF_CONNECT_PEND 0x0020
#define L2CAP_CONF_NO_FCS_RECV 0x0040
#define L2CAP_CONF_STATE2_DEVICE 0x0080
#define L2CAP_CONF_EXT_WIN_RECV 0x0100
#define L2CAP_CONF_LOCKSTEP 0x0200
#define L2CAP_CONF_LOCKSTEP_PEND 0x0400
#define L2CAP_CONF_PEND_SENT 0x0800
#define L2CAP_CONF_EFS_RECV 0x1000
#define L2CAP_CONF_MAX_CONF_REQ 2
#define L2CAP_CONF_MAX_CONF_RSP 2
#define L2CAP_RECONF_NONE 0x00
#define L2CAP_RECONF_INT 0x01
#define L2CAP_RECONF_ACC 0x02
#define L2CAP_CONN_SREJ_ACT 0x01
#define L2CAP_CONN_REJ_ACT 0x02
#define L2CAP_CONN_REMOTE_BUSY 0x04
#define L2CAP_CONN_LOCAL_BUSY 0x08
#define L2CAP_CONN_SEND_FBIT 0x10
#define L2CAP_CONN_SENT_RNR 0x20
#define L2CAP_SEQ_LIST_CLEAR 0xFFFF
#define L2CAP_SEQ_LIST_TAIL 0x8000
#define L2CAP_ERTM_TX_STATE_XMIT 0x01
#define L2CAP_ERTM_TX_STATE_WAIT_F 0x02
#define L2CAP_ERTM_RX_STATE_RECV 0x01
#define L2CAP_ERTM_RX_STATE_SREJ_SENT 0x02
#define L2CAP_ERTM_RX_STATE_AMP_MOVE 0x03
#define L2CAP_ERTM_RX_STATE_WAIT_P_FLAG 0x04
#define L2CAP_ERTM_RX_STATE_WAIT_P_FLAG_RECONFIGURE 0x05
#define L2CAP_ERTM_RX_STATE_WAIT_F_FLAG 0x06
#define L2CAP_ERTM_TXSEQ_EXPECTED 0x00
#define L2CAP_ERTM_TXSEQ_EXPECTED_SREJ 0x01
#define L2CAP_ERTM_TXSEQ_UNEXPECTED 0x02
#define L2CAP_ERTM_TXSEQ_UNEXPECTED_SREJ 0x03
#define L2CAP_ERTM_TXSEQ_DUPLICATE 0x04
#define L2CAP_ERTM_TXSEQ_DUPLICATE_SREJ 0x05
#define L2CAP_ERTM_TXSEQ_INVALID 0x06
#define L2CAP_ERTM_TXSEQ_INVALID_IGNORE 0x07
#define L2CAP_ERTM_EVENT_DATA_REQUEST 0x01
#define L2CAP_ERTM_EVENT_LOCAL_BUSY_DETECTED 0x02
#define L2CAP_ERTM_EVENT_LOCAL_BUSY_CLEAR 0x03
#define L2CAP_ERTM_EVENT_RECV_REQSEQ_AND_FBIT 0x04
#define L2CAP_ERTM_EVENT_RECV_FBIT 0x05
#define L2CAP_ERTM_EVENT_RETRANS_TIMER_EXPIRES 0x06
#define L2CAP_ERTM_EVENT_MONITOR_TIMER_EXPIRES 0x07
#define L2CAP_ERTM_EVENT_EXPLICIT_POLL 0x08
#define L2CAP_ERTM_EVENT_RECV_IFRAME 0x09
#define L2CAP_ERTM_EVENT_RECV_RR 0x0a
#define L2CAP_ERTM_EVENT_RECV_REJ 0x0b
#define L2CAP_ERTM_EVENT_RECV_RNR 0x0c
#define L2CAP_ERTM_EVENT_RECV_SREJ 0x0d
#define L2CAP_ERTM_EVENT_RECV_FRAME 0x0e
#define L2CAP_AMP_MOVE_NONE 0
#define L2CAP_AMP_MOVE_INITIATOR 1
#define L2CAP_AMP_MOVE_RESPONDER 2
#define L2CAP_AMP_STATE_STABLE 0
#define L2CAP_AMP_STATE_WAIT_CREATE 1
#define L2CAP_AMP_STATE_WAIT_CREATE_RSP 2
#define L2CAP_AMP_STATE_WAIT_MOVE 3
#define L2CAP_AMP_STATE_WAIT_MOVE_RSP 4
#define L2CAP_AMP_STATE_WAIT_MOVE_RSP_SUCCESS 5
#define L2CAP_AMP_STATE_WAIT_MOVE_CONFIRM 6
#define L2CAP_AMP_STATE_WAIT_MOVE_CONFIRM_RSP 7
#define L2CAP_AMP_STATE_WAIT_LOGICAL_COMPLETE 8
#define L2CAP_AMP_STATE_WAIT_LOGICAL_CONFIRM 9
#define L2CAP_AMP_STATE_WAIT_LOCAL_BUSY 10
#define L2CAP_AMP_STATE_WAIT_PREPARE 11
#define L2CAP_AMP_STATE_RESEGMENT 12
#define L2CAP_ATT_ERROR 0x01
#define L2CAP_ATT_MTU_REQ 0x02
#define L2CAP_ATT_MTU_RSP 0x03
#define L2CAP_ATT_RESPONSE_BIT 0x01
#define L2CAP_ATT_INDICATE 0x1D
#define L2CAP_ATT_CONFIRM 0x1E
#define L2CAP_ATT_NOT_SUPPORTED 0x06
#define __delta_seq(x, y, pi) ((x) >= (y) ? (x) - (y) : \
(pi)->tx_win_max + 1 - (y) + (x))
#define __next_seq(x, pi) ((x + 1) & ((pi)->tx_win_max))
extern bool disable_ertm;
extern const struct proto_ops l2cap_sock_ops;
extern struct bt_sock_list l2cap_sk_list;
int l2cap_init_sockets(void);
void l2cap_cleanup_sockets(void);
u8 l2cap_get_ident(struct l2cap_conn *conn);
void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, void *data);
int l2cap_build_conf_req(struct sock *sk, void *data);
int __l2cap_wait_ack(struct sock *sk);
struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len);
struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len);
struct sk_buff *l2cap_create_iframe_pdu(struct sock *sk, struct msghdr *msg,
size_t len, u16 sdulen, int reseg);
int l2cap_segment_sdu(struct sock *sk, struct sk_buff_head* seg_queue,
struct msghdr *msg, size_t len, int reseg);
int l2cap_resegment_queue(struct sock *sk, struct sk_buff_head *queue);
void l2cap_do_send(struct sock *sk, struct sk_buff *skb);
void l2cap_streaming_send(struct sock *sk);
int l2cap_ertm_send(struct sock *sk);
int l2cap_strm_tx(struct sock *sk, struct sk_buff_head *skbs);
int l2cap_ertm_tx(struct sock *sk, struct bt_l2cap_control *control,
struct sk_buff_head *skbs, u8 event);
int l2cap_sock_le_params_valid(struct bt_le_params *le_params);
void l2cap_sock_set_timer(struct sock *sk, long timeout);
void l2cap_sock_clear_timer(struct sock *sk);
void __l2cap_sock_close(struct sock *sk, int reason);
void l2cap_sock_kill(struct sock *sk);
void l2cap_sock_init(struct sock *sk, struct sock *parent);
struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
int proto, gfp_t prio);
struct sock *l2cap_find_sock_by_fixed_cid_and_dir(__le16 cid, bdaddr_t *src,
bdaddr_t *dst, int server);
void l2cap_send_disconn_req(struct l2cap_conn *conn, struct sock *sk, int err);
void l2cap_chan_del(struct sock *sk, int err);
int l2cap_do_connect(struct sock *sk);
int l2cap_data_channel(struct sock *sk, struct sk_buff *skb);
void l2cap_amp_move_init(struct sock *sk);
void l2cap_ertm_destruct(struct sock *sk);
void l2cap_ertm_shutdown(struct sock *sk);
void l2cap_ertm_recv_done(struct sock *sk);
void l2cap_fixed_channel_config(struct sock *sk, struct l2cap_options *opt);
void l2cap_recv_deferred_frame(struct sock *sk, struct sk_buff *skb);
void l2cap_amp_physical_complete(int result, u8 remote_id, u8 local_id,
struct sock *sk);
void l2cap_amp_logical_complete(int result, struct hci_conn *ampcon,
struct hci_chan *ampchan, struct sock *sk);
void l2cap_amp_logical_destroyed(struct hci_conn *ampcon);
#endif /* __L2CAP_H */

View File

@@ -0,0 +1,421 @@
/*
BlueZ - Bluetooth protocol stack for Linux
Copyright (C) 2010 Nokia Corporation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
#define MGMT_INDEX_NONE 0xFFFF
struct mgmt_hdr {
__le16 opcode;
__le16 index;
__le16 len;
} __packed;
#define MGMT_OP_READ_VERSION 0x0001
struct mgmt_rp_read_version {
__u8 version;
__le16 revision;
} __packed;
#define MGMT_OP_READ_INDEX_LIST 0x0003
struct mgmt_rp_read_index_list {
__le16 num_controllers;
__le16 index[0];
} __packed;
/* Reserve one extra byte for names in management messages so that they
* are always guaranteed to be nul-terminated */
#define MGMT_MAX_NAME_LENGTH (HCI_MAX_NAME_LENGTH + 1)
#define MGMT_OP_READ_INFO 0x0004
struct mgmt_rp_read_info {
__u8 type;
__u8 powered;
__u8 connectable;
__u8 discoverable;
__u8 pairable;
__u8 sec_mode;
bdaddr_t bdaddr;
__u8 dev_class[3];
__u8 features[8];
__u16 manufacturer;
__u8 hci_ver;
__u16 hci_rev;
__u8 name[MGMT_MAX_NAME_LENGTH];
__u8 le_white_list_size;
} __packed;
struct mgmt_mode {
__u8 val;
} __packed;
#define MGMT_OP_SET_POWERED 0x0005
#define MGMT_OP_SET_DISCOVERABLE 0x0006
#define MGMT_OP_SET_CONNECTABLE 0x0007
#define MGMT_OP_SET_PAIRABLE 0x0008
#define MGMT_OP_ADD_UUID 0x0009
struct mgmt_cp_add_uuid {
__u8 uuid[16];
__u8 svc_hint;
} __packed;
#define MGMT_OP_REMOVE_UUID 0x000A
struct mgmt_cp_remove_uuid {
__u8 uuid[16];
} __packed;
#define MGMT_OP_SET_DEV_CLASS 0x000B
struct mgmt_cp_set_dev_class {
__u8 major;
__u8 minor;
} __packed;
#define MGMT_MAJOR_CLASS_MASK 0x1F
#define MGMT_MAJOR_CLASS_LIMITED 0x20
#define MGMT_OP_SET_SERVICE_CACHE 0x000C
struct mgmt_cp_set_service_cache {
__u8 enable;
} __packed;
struct mgmt_key_info {
bdaddr_t bdaddr;
u8 addr_type;
u8 key_type;
u8 val[16];
u8 pin_len;
u8 auth;
u8 dlen;
u8 data[10];
} __packed;
#define MGMT_OP_LOAD_KEYS 0x000D
struct mgmt_cp_load_keys {
__u8 debug_keys;
__le16 key_count;
struct mgmt_key_info keys[0];
} __packed;
#define MGMT_OP_REMOVE_KEY 0x000E
struct mgmt_cp_remove_key {
bdaddr_t bdaddr;
__u8 disconnect;
} __packed;
#define MGMT_OP_DISCONNECT 0x000F
struct mgmt_cp_disconnect {
bdaddr_t bdaddr;
} __packed;
struct mgmt_rp_disconnect {
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_GET_CONNECTIONS 0x0010
struct mgmt_rp_get_connections {
__le16 conn_count;
bdaddr_t conn[0];
} __packed;
#define MGMT_OP_PIN_CODE_REPLY 0x0011
struct mgmt_cp_pin_code_reply {
bdaddr_t bdaddr;
__u8 pin_len;
__u8 pin_code[16];
} __packed;
struct mgmt_rp_pin_code_reply {
bdaddr_t bdaddr;
uint8_t status;
} __packed;
#define MGMT_OP_PIN_CODE_NEG_REPLY 0x0012
struct mgmt_cp_pin_code_neg_reply {
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_SET_IO_CAPABILITY 0x0013
struct mgmt_cp_set_io_capability {
__u8 io_capability;
} __packed;
#define MGMT_OP_PAIR_DEVICE 0x0014
struct mgmt_cp_pair_device {
bdaddr_t bdaddr;
__u8 io_cap;
} __packed;
struct mgmt_rp_pair_device {
bdaddr_t bdaddr;
__u8 status;
} __packed;
#define MGMT_OP_USER_CONFIRM_REPLY 0x0015
struct mgmt_cp_user_confirm_reply {
bdaddr_t bdaddr;
} __packed;
struct mgmt_rp_user_confirm_reply {
bdaddr_t bdaddr;
__u8 status;
} __packed;
#define MGMT_OP_USER_CONFIRM_NEG_REPLY 0x0016
#define MGMT_OP_SET_LOCAL_NAME 0x0017
struct mgmt_cp_set_local_name {
__u8 name[MGMT_MAX_NAME_LENGTH];
} __packed;
#define MGMT_OP_READ_LOCAL_OOB_DATA 0x0018
struct mgmt_rp_read_local_oob_data {
__u8 hash[16];
__u8 randomizer[16];
} __packed;
#define MGMT_OP_ADD_REMOTE_OOB_DATA 0x0019
struct mgmt_cp_add_remote_oob_data {
bdaddr_t bdaddr;
__u8 hash[16];
__u8 randomizer[16];
} __packed;
#define MGMT_OP_REMOVE_REMOTE_OOB_DATA 0x001A
struct mgmt_cp_remove_remote_oob_data {
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_START_DISCOVERY 0x001B
#define MGMT_OP_STOP_DISCOVERY 0x001C
#define MGMT_OP_USER_PASSKEY_REPLY 0x001D
struct mgmt_cp_user_passkey_reply {
bdaddr_t bdaddr;
__le32 passkey;
} __packed;
#define MGMT_OP_RESOLVE_NAME 0x001E
struct mgmt_cp_resolve_name {
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_SET_LIMIT_DISCOVERABLE 0x001F
#define MGMT_OP_SET_CONNECTION_PARAMS 0x0020
struct mgmt_cp_set_connection_params {
bdaddr_t bdaddr;
__le16 interval_min;
__le16 interval_max;
__le16 slave_latency;
__le16 timeout_multiplier;
} __packed;
#define MGMT_OP_ENCRYPT_LINK 0x0021
struct mgmt_cp_encrypt_link {
bdaddr_t bdaddr;
__u8 enable;
} __packed;
#define MGMT_OP_SET_RSSI_REPORTER 0x0022
struct mgmt_cp_set_rssi_reporter {
bdaddr_t bdaddr;
__s8 rssi_threshold;
__le16 interval;
__u8 updateOnThreshExceed;
} __packed;
#define MGMT_OP_UNSET_RSSI_REPORTER 0x0023
struct mgmt_cp_unset_rssi_reporter {
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_CANCEL_RESOLVE_NAME 0x0024
struct mgmt_cp_cancel_resolve_name {
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_LE_READ_WHITE_LIST_SIZE 0xE000
#define MGMT_OP_LE_CLEAR_WHITE_LIST 0xE001
#define MGMT_OP_LE_ADD_DEV_WHITE_LIST 0xE002
struct mgmt_cp_le_add_dev_white_list {
__u8 addr_type;
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_LE_REMOVE_DEV_WHITE_LIST 0xE003
struct mgmt_cp_le_remove_dev_white_list {
__u8 addr_type;
bdaddr_t bdaddr;
} __packed;
#define MGMT_OP_LE_CREATE_CONN_WHITE_LIST 0xE004
#define MGMT_OP_LE_CANCEL_CREATE_CONN_WHITE_LIST 0xE005
#define MGMT_OP_LE_CANCEL_CREATE_CONN 0xE006
struct mgmt_cp_le_cancel_create_conn {
bdaddr_t bdaddr;
} __packed;
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
__u8 data[0];
} __packed;
#define MGMT_EV_CMD_STATUS 0x0002
struct mgmt_ev_cmd_status {
__u8 status;
__le16 opcode;
} __packed;
#define MGMT_EV_CONTROLLER_ERROR 0x0003
struct mgmt_ev_controller_error {
__u8 error_code;
} __packed;
#define MGMT_EV_INDEX_ADDED 0x0004
#define MGMT_EV_INDEX_REMOVED 0x0005
#define MGMT_EV_POWERED 0x0006
#define MGMT_EV_DISCOVERABLE 0x0007
#define MGMT_EV_CONNECTABLE 0x0008
#define MGMT_EV_PAIRABLE 0x0009
#define MGMT_EV_NEW_KEY 0x000A
struct mgmt_ev_new_key {
__u8 store_hint;
struct mgmt_key_info key;
} __packed;
#define MGMT_EV_CONNECTED 0x000B
struct mgmt_ev_connected {
bdaddr_t bdaddr;
__u8 le;
} __packed;
#define MGMT_EV_DISCONNECTED 0x000C
struct mgmt_ev_disconnected {
bdaddr_t bdaddr;
__u8 reason;
} __packed;
#define MGMT_EV_CONNECT_FAILED 0x000D
struct mgmt_ev_connect_failed {
bdaddr_t bdaddr;
__u8 status;
} __packed;
#define MGMT_EV_PIN_CODE_REQUEST 0x000E
struct mgmt_ev_pin_code_request {
bdaddr_t bdaddr;
__u8 secure;
} __packed;
#define MGMT_EV_USER_CONFIRM_REQUEST 0x000F
struct mgmt_ev_user_confirm_request {
bdaddr_t bdaddr;
__u8 auto_confirm;
__u8 event;
__le32 value;
} __packed;
#define MGMT_EV_AUTH_FAILED 0x0010
struct mgmt_ev_auth_failed {
bdaddr_t bdaddr;
__u8 status;
} __packed;
#define MGMT_EV_LOCAL_NAME_CHANGED 0x0011
struct mgmt_ev_local_name_changed {
__u8 name[MGMT_MAX_NAME_LENGTH];
} __packed;
#define MGMT_EV_DEVICE_FOUND 0x0012
struct mgmt_ev_device_found {
bdaddr_t bdaddr;
__u8 dev_class[3];
__s8 rssi;
__u8 le;
__u8 type;
__u8 eir[HCI_MAX_EIR_LENGTH];
} __packed;
#define MGMT_EV_REMOTE_NAME 0x0013
struct mgmt_ev_remote_name {
bdaddr_t bdaddr;
__u8 status;
__u8 name[MGMT_MAX_NAME_LENGTH];
} __packed;
#define MGMT_EV_DISCOVERING 0x0014
#define MGMT_EV_USER_PASSKEY_REQUEST 0x0015
struct mgmt_ev_user_passkey_request {
bdaddr_t bdaddr;
} __packed;
#define MGMT_EV_ENCRYPT_CHANGE 0x0016
struct mgmt_ev_encrypt_change {
bdaddr_t bdaddr;
__u8 status;
} __packed;
#define MGMT_EV_REMOTE_CLASS 0x0017
struct mgmt_ev_remote_class {
bdaddr_t bdaddr;
__u8 dev_class[3];
} __packed;
#define MGMT_EV_REMOTE_VERSION 0x0018
struct mgmt_ev_remote_version {
bdaddr_t bdaddr;
__u8 lmp_ver;
__u16 manufacturer;
__u16 lmp_subver;
} __packed;
#define MGMT_EV_REMOTE_FEATURES 0x0019
struct mgmt_ev_remote_features {
bdaddr_t bdaddr;
uint8_t features[8];
} __packed;
#define MGMT_EV_RSSI_UPDATE 0x0020
struct mgmt_ev_rssi_update {
bdaddr_t bdaddr;
__s8 rssi;
} __packed;
#define MGMT_EV_LE_CONN_PARAMS 0xF000
struct mgmt_ev_le_conn_params {
bdaddr_t bdaddr;
__u16 interval;
__u16 latency;
__u16 timeout;
} __packed;

View File

@@ -0,0 +1,368 @@
/*
RFCOMM implementation for Linux Bluetooth stack (BlueZ)
Copyright (C) 2002 Maxim Krasnyansky <maxk@qualcomm.com>
Copyright (C) 2002 Marcel Holtmann <marcel@holtmann.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
#ifndef __RFCOMM_H
#define __RFCOMM_H
#define RFCOMM_PSM 3
#define RFCOMM_CONN_TIMEOUT (HZ * 30)
#define RFCOMM_DISC_TIMEOUT (HZ * 20)
#define RFCOMM_AUTH_TIMEOUT (HZ * 25)
#define RFCOMM_IDLE_TIMEOUT (HZ * 2)
#define RFCOMM_DEFAULT_MTU 127
#define RFCOMM_DEFAULT_CREDITS 7
#define RFCOMM_MAX_L2CAP_MTU 1013
#define RFCOMM_MAX_CREDITS 40
#define RFCOMM_SKB_HEAD_RESERVE 8
#define RFCOMM_SKB_TAIL_RESERVE 2
#define RFCOMM_SKB_RESERVE (RFCOMM_SKB_HEAD_RESERVE + RFCOMM_SKB_TAIL_RESERVE)
#define RFCOMM_SABM 0x2f
#define RFCOMM_DISC 0x43
#define RFCOMM_UA 0x63
#define RFCOMM_DM 0x0f
#define RFCOMM_UIH 0xef
#define RFCOMM_TEST 0x08
#define RFCOMM_FCON 0x28
#define RFCOMM_FCOFF 0x18
#define RFCOMM_MSC 0x38
#define RFCOMM_RPN 0x24
#define RFCOMM_RLS 0x14
#define RFCOMM_PN 0x20
#define RFCOMM_NSC 0x04
#define RFCOMM_V24_FC 0x02
#define RFCOMM_V24_RTC 0x04
#define RFCOMM_V24_RTR 0x08
#define RFCOMM_V24_IC 0x40
#define RFCOMM_V24_DV 0x80
#define RFCOMM_RPN_BR_2400 0x0
#define RFCOMM_RPN_BR_4800 0x1
#define RFCOMM_RPN_BR_7200 0x2
#define RFCOMM_RPN_BR_9600 0x3
#define RFCOMM_RPN_BR_19200 0x4
#define RFCOMM_RPN_BR_38400 0x5
#define RFCOMM_RPN_BR_57600 0x6
#define RFCOMM_RPN_BR_115200 0x7
#define RFCOMM_RPN_BR_230400 0x8
#define RFCOMM_RPN_DATA_5 0x0
#define RFCOMM_RPN_DATA_6 0x1
#define RFCOMM_RPN_DATA_7 0x2
#define RFCOMM_RPN_DATA_8 0x3
#define RFCOMM_RPN_STOP_1 0
#define RFCOMM_RPN_STOP_15 1
#define RFCOMM_RPN_PARITY_NONE 0x0
#define RFCOMM_RPN_PARITY_ODD 0x1
#define RFCOMM_RPN_PARITY_EVEN 0x3
#define RFCOMM_RPN_PARITY_MARK 0x5
#define RFCOMM_RPN_PARITY_SPACE 0x7
#define RFCOMM_RPN_FLOW_NONE 0x00
#define RFCOMM_RPN_XON_CHAR 0x11
#define RFCOMM_RPN_XOFF_CHAR 0x13
#define RFCOMM_RPN_PM_BITRATE 0x0001
#define RFCOMM_RPN_PM_DATA 0x0002
#define RFCOMM_RPN_PM_STOP 0x0004
#define RFCOMM_RPN_PM_PARITY 0x0008
#define RFCOMM_RPN_PM_PARITY_TYPE 0x0010
#define RFCOMM_RPN_PM_XON 0x0020
#define RFCOMM_RPN_PM_XOFF 0x0040
#define RFCOMM_RPN_PM_FLOW 0x3F00
#define RFCOMM_RPN_PM_ALL 0x3F7F
struct rfcomm_hdr {
u8 addr;
u8 ctrl;
u8 len; /* Actual size can be 2 bytes */
} __packed;
struct rfcomm_cmd {
u8 addr;
u8 ctrl;
u8 len;
u8 fcs;
} __packed;
struct rfcomm_mcc {
u8 type;
u8 len;
} __packed;
struct rfcomm_pn {
u8 dlci;
u8 flow_ctrl;
u8 priority;
u8 ack_timer;
__le16 mtu;
u8 max_retrans;
u8 credits;
} __packed;
struct rfcomm_rpn {
u8 dlci;
u8 bit_rate;
u8 line_settings;
u8 flow_ctrl;
u8 xon_char;
u8 xoff_char;
__le16 param_mask;
} __packed;
struct rfcomm_rls {
u8 dlci;
u8 status;
} __packed;
struct rfcomm_msc {
u8 dlci;
u8 v24_sig;
} __packed;
/* ---- Core structures, flags etc ---- */
struct rfcomm_session {
struct list_head list;
struct socket *sock;
struct timer_list timer;
unsigned long state;
unsigned long flags;
atomic_t refcnt;
int initiator;
/* Default DLC parameters */
int cfc;
uint mtu;
struct list_head dlcs;
};
struct rfcomm_dlc {
struct list_head list;
struct rfcomm_session *session;
struct sk_buff_head tx_queue;
struct timer_list timer;
spinlock_t lock;
unsigned long state;
unsigned long flags;
atomic_t refcnt;
u8 dlci;
u8 addr;
u8 priority;
u8 v24_sig;
u8 remote_v24_sig;
u8 mscex;
u8 out;
u8 sec_level;
u8 role_switch;
u32 defer_setup;
uint mtu;
uint cfc;
uint rx_credits;
uint tx_credits;
void *owner;
void (*data_ready)(struct rfcomm_dlc *d, struct sk_buff *skb);
void (*state_change)(struct rfcomm_dlc *d, int err);
void (*modem_status)(struct rfcomm_dlc *d, u8 v24_sig);
};
/* DLC and session flags */
#define RFCOMM_RX_THROTTLED 0
#define RFCOMM_TX_THROTTLED 1
#define RFCOMM_TIMED_OUT 2
#define RFCOMM_MSC_PENDING 3
#define RFCOMM_SEC_PENDING 4
#define RFCOMM_AUTH_PENDING 5
#define RFCOMM_AUTH_ACCEPT 6
#define RFCOMM_AUTH_REJECT 7
#define RFCOMM_DEFER_SETUP 8
/* Scheduling flags and events */
#define RFCOMM_SCHED_WAKEUP 31
/* MSC exchange flags */
#define RFCOMM_MSCEX_TX 1
#define RFCOMM_MSCEX_RX 2
#define RFCOMM_MSCEX_OK (RFCOMM_MSCEX_TX + RFCOMM_MSCEX_RX)
/* CFC states */
#define RFCOMM_CFC_UNKNOWN -1
#define RFCOMM_CFC_DISABLED 0
#define RFCOMM_CFC_ENABLED RFCOMM_MAX_CREDITS
/* ---- RFCOMM SEND RPN ---- */
int rfcomm_send_rpn(struct rfcomm_session *s, int cr, u8 dlci,
u8 bit_rate, u8 data_bits, u8 stop_bits,
u8 parity, u8 flow_ctrl_settings,
u8 xon_char, u8 xoff_char, u16 param_mask);
/* ---- RFCOMM DLCs (channels) ---- */
struct rfcomm_dlc *rfcomm_dlc_alloc(gfp_t prio);
void rfcomm_dlc_free(struct rfcomm_dlc *d);
int rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel);
int rfcomm_dlc_close(struct rfcomm_dlc *d, int reason);
int rfcomm_dlc_send(struct rfcomm_dlc *d, struct sk_buff *skb);
int rfcomm_dlc_set_modem_status(struct rfcomm_dlc *d, u8 v24_sig);
int rfcomm_dlc_get_modem_status(struct rfcomm_dlc *d, u8 *v24_sig);
void rfcomm_dlc_accept(struct rfcomm_dlc *d);
#define rfcomm_dlc_lock(d) spin_lock(&d->lock)
#define rfcomm_dlc_unlock(d) spin_unlock(&d->lock)
static inline void rfcomm_dlc_hold(struct rfcomm_dlc *d)
{
atomic_inc(&d->refcnt);
}
static inline void rfcomm_dlc_put(struct rfcomm_dlc *d)
{
if (atomic_dec_and_test(&d->refcnt))
rfcomm_dlc_free(d);
}
extern void __rfcomm_dlc_throttle(struct rfcomm_dlc *d);
extern void __rfcomm_dlc_unthrottle(struct rfcomm_dlc *d);
static inline void rfcomm_dlc_throttle(struct rfcomm_dlc *d)
{
if (!test_and_set_bit(RFCOMM_RX_THROTTLED, &d->flags))
__rfcomm_dlc_throttle(d);
}
static inline void rfcomm_dlc_unthrottle(struct rfcomm_dlc *d)
{
if (test_and_clear_bit(RFCOMM_RX_THROTTLED, &d->flags))
__rfcomm_dlc_unthrottle(d);
}
/* ---- RFCOMM sessions ---- */
void rfcomm_session_getaddr(struct rfcomm_session *s, bdaddr_t *src, bdaddr_t *dst);
static inline void rfcomm_session_hold(struct rfcomm_session *s)
{
atomic_inc(&s->refcnt);
}
/* ---- RFCOMM sockets ---- */
struct sockaddr_rc {
sa_family_t rc_family;
bdaddr_t rc_bdaddr;
u8 rc_channel;
};
#define RFCOMM_CONNINFO 0x02
struct rfcomm_conninfo {
__u16 hci_handle;
__u8 dev_class[3];
};
#define RFCOMM_LM 0x03
#define RFCOMM_LM_MASTER 0x0001
#define RFCOMM_LM_AUTH 0x0002
#define RFCOMM_LM_ENCRYPT 0x0004
#define RFCOMM_LM_TRUSTED 0x0008
#define RFCOMM_LM_RELIABLE 0x0010
#define RFCOMM_LM_SECURE 0x0020
#define rfcomm_pi(sk) ((struct rfcomm_pinfo *) sk)
struct rfcomm_pinfo {
struct bt_sock bt;
struct rfcomm_dlc *dlc;
u8 channel;
u8 sec_level;
u8 role_switch;
};
int rfcomm_init_sockets(void);
void rfcomm_cleanup_sockets(void);
int rfcomm_connect_ind(struct rfcomm_session *s, u8 channel, struct rfcomm_dlc **d);
/* ---- RFCOMM TTY ---- */
#define RFCOMM_MAX_DEV 256
#define RFCOMMCREATEDEV _IOW('R', 200, int)
#define RFCOMMRELEASEDEV _IOW('R', 201, int)
#define RFCOMMGETDEVLIST _IOR('R', 210, int)
#define RFCOMMGETDEVINFO _IOR('R', 211, int)
#define RFCOMMSTEALDLC _IOW('R', 220, int)
#define RFCOMM_REUSE_DLC 0
#define RFCOMM_RELEASE_ONHUP 1
#define RFCOMM_HANGUP_NOW 2
#define RFCOMM_TTY_ATTACHED 3
#define RFCOMM_TTY_RELEASED 4
struct rfcomm_dev_req {
s16 dev_id;
u32 flags;
bdaddr_t src;
bdaddr_t dst;
u8 channel;
};
struct rfcomm_dev_info {
s16 id;
u32 flags;
u16 state;
bdaddr_t src;
bdaddr_t dst;
u8 channel;
};
struct rfcomm_dev_list_req {
u16 dev_num;
struct rfcomm_dev_info dev_info[0];
};
int rfcomm_dev_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
#ifdef CONFIG_BT_RFCOMM_TTY
int rfcomm_init_ttys(void);
void rfcomm_cleanup_ttys(void);
#else
static inline int rfcomm_init_ttys(void)
{
return 0;
}
static inline void rfcomm_cleanup_ttys(void)
{
}
#endif
#endif /* __RFCOMM_H */

View File

@@ -0,0 +1,83 @@
/*
BlueZ - Bluetooth protocol stack for Linux
Copyright (C) 2000-2001 Qualcomm Incorporated
Copyright (c) 2011, The Linux Foundation. All rights reserved.
Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
#ifndef __SCO_H
#define __SCO_H
/* SCO defaults */
#define SCO_DEFAULT_MTU 500
#define SCO_DEFAULT_FLUSH_TO 0xFFFF
#define SCO_CONN_TIMEOUT (HZ * 40)
#define SCO_DISCONN_TIMEOUT (HZ * 20)
#define SCO_CONN_IDLE_TIMEOUT (HZ * 60)
/* SCO socket address */
struct sockaddr_sco {
sa_family_t sco_family;
bdaddr_t sco_bdaddr;
__u16 sco_pkt_type;
__s8 is_wbs;
};
/* SCO socket options */
#define SCO_OPTIONS 0x01
struct sco_options {
__u16 mtu;
};
#define SCO_CONNINFO 0x02
struct sco_conninfo {
__u16 hci_handle;
__u8 dev_class[3];
};
/* ---- SCO connections ---- */
struct sco_conn {
struct hci_conn *hcon;
bdaddr_t *dst;
bdaddr_t *src;
spinlock_t lock;
struct sock *sk;
unsigned int mtu;
};
#define sco_conn_lock(c) spin_lock(&c->lock);
#define sco_conn_unlock(c) spin_unlock(&c->lock);
/* ----- SCO socket info ----- */
#define sco_pi(sk) ((struct sco_pinfo *) sk)
struct sco_pinfo {
struct bt_sock bt;
__u16 pkt_type;
struct sco_conn *conn;
};
#endif /* __SCO_H */

View File

@@ -0,0 +1,131 @@
/*
BlueZ - Bluetooth protocol stack for Linux
Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation;
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
SOFTWARE IS DISCLAIMED.
*/
#ifndef __SMP_H
#define __SMP_H
struct smp_command_hdr {
__u8 code;
} __packed;
#define SMP_CMD_PAIRING_REQ 0x01
#define SMP_CMD_PAIRING_RSP 0x02
struct smp_cmd_pairing {
__u8 io_capability;
__u8 oob_flag;
__u8 auth_req;
__u8 max_key_size;
__u8 init_key_dist;
__u8 resp_key_dist;
} __packed;
#define SMP_IO_DISPLAY_ONLY 0x00
#define SMP_IO_DISPLAY_YESNO 0x01
#define SMP_IO_KEYBOARD_ONLY 0x02
#define SMP_IO_NO_INPUT_OUTPUT 0x03
#define SMP_IO_KEYBOARD_DISPLAY 0x04
#define SMP_OOB_NOT_PRESENT 0x00
#define SMP_OOB_PRESENT 0x01
#define SMP_DIST_ENC_KEY 0x01
#define SMP_DIST_ID_KEY 0x02
#define SMP_DIST_SIGN 0x04
#define SMP_AUTH_NONE 0x00
#define SMP_AUTH_BONDING 0x01
#define SMP_AUTH_MITM 0x04
#define SMP_JUST_WORKS 0x00
#define SMP_JUST_CFM 0x01
#define SMP_REQ_PASSKEY 0x02
#define SMP_CFM_PASSKEY 0x03
#define SMP_REQ_OOB 0x04
#define SMP_OVERLAP 0xFF
#define SMP_CMD_PAIRING_CONFIRM 0x03
struct smp_cmd_pairing_confirm {
__u8 confirm_val[16];
} __packed;
#define SMP_CMD_PAIRING_RANDOM 0x04
struct smp_cmd_pairing_random {
__u8 rand_val[16];
} __packed;
#define SMP_CMD_PAIRING_FAIL 0x05
struct smp_cmd_pairing_fail {
__u8 reason;
} __packed;
#define SMP_CMD_ENCRYPT_INFO 0x06
struct smp_cmd_encrypt_info {
__u8 ltk[16];
} __packed;
#define SMP_CMD_MASTER_IDENT 0x07
struct smp_cmd_master_ident {
__u16 ediv;
__u8 rand[8];
} __packed;
#define SMP_CMD_IDENT_INFO 0x08
struct smp_cmd_ident_info {
__u8 irk[16];
} __packed;
#define SMP_CMD_IDENT_ADDR_INFO 0x09
struct smp_cmd_ident_addr_info {
__u8 addr_type;
bdaddr_t bdaddr;
} __packed;
#define SMP_CMD_SIGN_INFO 0x0a
struct smp_cmd_sign_info {
__u8 csrk[16];
} __packed;
#define SMP_CMD_SECURITY_REQ 0x0b
struct smp_cmd_security_req {
__u8 auth_req;
} __packed;
#define SMP_PASSKEY_ENTRY_FAILED 0x01
#define SMP_OOB_NOT_AVAIL 0x02
#define SMP_AUTH_REQUIREMENTS 0x03
#define SMP_CONFIRM_FAILED 0x04
#define SMP_PAIRING_NOTSUPP 0x05
#define SMP_ENC_KEY_SIZE 0x06
#define SMP_CMD_NOTSUPP 0x07
#define SMP_UNSPECIFIED 0x08
#define SMP_REPEATED_ATTEMPTS 0x09
#define SMP_MIN_ENC_KEY_SIZE 7
#define SMP_MAX_ENC_KEY_SIZE 16
/* SMP Commands */
int smp_conn_security(struct l2cap_conn *conn, __u8 sec_level);
int smp_sig_channel(struct l2cap_conn *conn, struct sk_buff *skb);
int smp_link_encrypt_cmplt(struct l2cap_conn *conn, __u8 status, __u8 encrypt);
void smp_timeout(unsigned long l2cap_conn);
#endif /* __SMP_H */