1/* 2 BlueZ - Bluetooth protocol stack for Linux 3 Copyright (C) 2000-2001 Qualcomm Incorporated 4 5 Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com> 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License version 2 as 9 published by the Free Software Foundation; 10 11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 12 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 13 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. 14 IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY 15 CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 16 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 20 ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 21 COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 22 SOFTWARE IS DISCLAIMED. 23*/ 24 25/* 26 * $Id: l2cap.h,v 1.1.1.1 2008/10/15 03:27:31 james26_jang Exp $ 27 */ 28 29#ifndef __L2CAP_H 30#define __L2CAP_H 31 32/* L2CAP defaults */ 33#define L2CAP_DEFAULT_MTU 672 34#define L2CAP_DEFAULT_FLUSH_TO 0xFFFF 35 36#define L2CAP_CONN_TIMEOUT (HZ * 40) 37 38/* L2CAP socket address */ 39struct sockaddr_l2 { 40 sa_family_t l2_family; 41 unsigned short l2_psm; 42 bdaddr_t l2_bdaddr; 43}; 44 45/* Socket options */ 46#define L2CAP_OPTIONS 0x01 47struct l2cap_options { 48 __u16 omtu; 49 __u16 imtu; 50 __u16 flush_to; 51}; 52 53#define L2CAP_CONNINFO 0x02 54struct l2cap_conninfo { 55 __u16 hci_handle; 56}; 57 58#define L2CAP_LM 0x03 59#define L2CAP_LM_MASTER 0x0001 60#define L2CAP_LM_AUTH 0x0002 61#define L2CAP_LM_ENCRYPT 0x0004 62#define L2CAP_LM_TRUSTED 0x0008 63 64#define L2CAP_QOS 0x04 65struct l2cap_qos { 66 __u16 service_type; 67 __u32 token_rate; 68 __u32 token_bucket_size; 69 __u32 peak_bandwidth; 70 __u32 latency; 71 __u32 delay_variation; 72}; 73 74#define L2CAP_SERV_NO_TRAFFIC 0x00 75#define L2CAP_SERV_BEST_EFFORT 0x01 76#define L2CAP_SERV_GUARANTEED 0x02 77 78/* L2CAP command codes */ 79#define L2CAP_COMMAND_REJ 0x01 80#define L2CAP_CONN_REQ 0x02 81#define L2CAP_CONN_RSP 0x03 82#define L2CAP_CONF_REQ 0x04 83#define L2CAP_CONF_RSP 0x05 84#define L2CAP_DISCONN_REQ 0x06 85#define L2CAP_DISCONN_RSP 0x07 86#define L2CAP_ECHO_REQ 0x08 87#define L2CAP_ECHO_RSP 0x09 88#define L2CAP_INFO_REQ 0x0a 89#define L2CAP_INFO_RSP 0x0b 90 91/* L2CAP structures */ 92typedef struct { 93 __u16 len; 94 __u16 cid; 95} __attribute__ ((packed)) l2cap_hdr; 96#define L2CAP_HDR_SIZE 4 97 98typedef struct { 99 __u8 code; 100 __u8 ident; 101 __u16 len; 102} __attribute__ ((packed)) l2cap_cmd_hdr; 103#define L2CAP_CMD_HDR_SIZE 4 104 105typedef struct { 106 __u16 reason; 107} __attribute__ ((packed)) l2cap_cmd_rej; 108#define L2CAP_CMD_REJ_SIZE 2 109 110typedef struct { 111 __u16 psm; 112 __u16 scid; 113} __attribute__ ((packed)) l2cap_conn_req; 114#define L2CAP_CONN_REQ_SIZE 4 115 116typedef struct { 117 __u16 dcid; 118 __u16 scid; 119 __u16 result; 120 __u16 status; 121} __attribute__ ((packed)) l2cap_conn_rsp; 122#define L2CAP_CONN_RSP_SIZE 8 123 124/* connect result */ 125#define L2CAP_CR_SUCCESS 0x0000 126#define L2CAP_CR_PEND 0x0001 127#define L2CAP_CR_BAD_PSM 0x0002 128#define L2CAP_CR_SEC_BLOCK 0x0003 129#define L2CAP_CR_NO_MEM 0x0004 130 131/* connect status */ 132#define L2CAP_CS_NO_INFO 0x0000 133#define L2CAP_CS_AUTHEN_PEND 0x0001 134#define L2CAP_CS_AUTHOR_PEND 0x0002 135 136typedef struct { 137 __u16 dcid; 138 __u16 flags; 139 __u8 data[0]; 140} __attribute__ ((packed)) l2cap_conf_req; 141#define L2CAP_CONF_REQ_SIZE 4 142 143typedef struct { 144 __u16 scid; 145 __u16 flags; 146 __u16 result; 147 __u8 data[0]; 148} __attribute__ ((packed)) l2cap_conf_rsp; 149#define L2CAP_CONF_RSP_SIZE 6 150 151#define L2CAP_CONF_SUCCESS 0x00 152#define L2CAP_CONF_UNACCEPT 0x01 153 154typedef struct { 155 __u8 type; 156 __u8 len; 157 __u8 val[0]; 158} __attribute__ ((packed)) l2cap_conf_opt; 159#define L2CAP_CONF_OPT_SIZE 2 160 161#define L2CAP_CONF_MTU 0x01 162#define L2CAP_CONF_FLUSH_TO 0x02 163#define L2CAP_CONF_QOS 0x03 164 165#define L2CAP_CONF_MAX_SIZE 22 166 167typedef struct { 168 __u16 dcid; 169 __u16 scid; 170} __attribute__ ((packed)) l2cap_disconn_req; 171#define L2CAP_DISCONN_REQ_SIZE 4 172 173typedef struct { 174 __u16 dcid; 175 __u16 scid; 176} __attribute__ ((packed)) l2cap_disconn_rsp; 177#define L2CAP_DISCONN_RSP_SIZE 4 178 179typedef struct { 180 __u16 type; 181 __u8 data[0]; 182} __attribute__ ((packed)) l2cap_info_req; 183#define L2CAP_INFO_REQ_SIZE 2 184 185typedef struct { 186 __u16 type; 187 __u16 result; 188 __u8 data[0]; 189} __attribute__ ((packed)) l2cap_info_rsp; 190#define L2CAP_INFO_RSP_SIZE 4 191 192/* ----- L2CAP connections ----- */ 193struct l2cap_chan_list { 194 struct sock *head; 195 rwlock_t lock; 196 long num; 197}; 198 199struct l2cap_conn { 200 struct hci_conn *hcon; 201 202 bdaddr_t *dst; 203 bdaddr_t *src; 204 205 unsigned int mtu; 206 207 spinlock_t lock; 208 209 struct sk_buff *rx_skb; 210 __u32 rx_len; 211 __u8 rx_ident; 212 __u8 tx_ident; 213 214 struct l2cap_chan_list chan_list; 215}; 216 217/* ----- L2CAP channel and socket info ----- */ 218#define l2cap_pi(sk) ((struct l2cap_pinfo *) &sk->tp_pinfo) 219 220struct l2cap_pinfo { 221 __u16 psm; 222 __u16 dcid; 223 __u16 scid; 224 225 __u16 imtu; 226 __u16 omtu; 227 __u16 flush_to; 228 229 __u32 link_mode; 230 231 __u8 conf_state; 232 __u16 conf_mtu; 233 234 __u8 ident; 235 236 struct l2cap_conn *conn; 237 struct sock *next_c; 238 struct sock *prev_c; 239}; 240 241#define CONF_REQ_SENT 0x01 242#define CONF_INPUT_DONE 0x02 243#define CONF_OUTPUT_DONE 0x04 244 245#endif /* __L2CAP_H */ 246