1*4bb965d0Splunky /* $NetBSD: l2cap.h,v 1.19 2015/11/28 07:50:37 plunky Exp $ */ 2a5c89047Sgdamore 3a5c89047Sgdamore /*- 4a5c89047Sgdamore * Copyright (c) 2005 Iain Hibbert. 5a5c89047Sgdamore * Copyright (c) 2006 Itronix Inc. 6a5c89047Sgdamore * All rights reserved. 7a5c89047Sgdamore * 8a5c89047Sgdamore * Redistribution and use in source and binary forms, with or without 9a5c89047Sgdamore * modification, are permitted provided that the following conditions 10a5c89047Sgdamore * are met: 11a5c89047Sgdamore * 1. Redistributions of source code must retain the above copyright 12a5c89047Sgdamore * notice, this list of conditions and the following disclaimer. 13a5c89047Sgdamore * 2. Redistributions in binary form must reproduce the above copyright 14a5c89047Sgdamore * notice, this list of conditions and the following disclaimer in the 15a5c89047Sgdamore * documentation and/or other materials provided with the distribution. 16a5c89047Sgdamore * 3. The name of Itronix Inc. may not be used to endorse 17a5c89047Sgdamore * or promote products derived from this software without specific 18a5c89047Sgdamore * prior written permission. 19a5c89047Sgdamore * 20a5c89047Sgdamore * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND 21a5c89047Sgdamore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22a5c89047Sgdamore * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23a5c89047Sgdamore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY 24a5c89047Sgdamore * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25a5c89047Sgdamore * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26a5c89047Sgdamore * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27a5c89047Sgdamore * ON ANY THEORY OF LIABILITY, WHETHER IN 28a5c89047Sgdamore * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29a5c89047Sgdamore * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30a5c89047Sgdamore * POSSIBILITY OF SUCH DAMAGE. 31a5c89047Sgdamore */ 32a5c89047Sgdamore /*- 33a5c89047Sgdamore * Copyright (c) Maksim Yevmenkin <m_evmenkin@yahoo.com> 34a5c89047Sgdamore * All rights reserved. 35a5c89047Sgdamore * 36a5c89047Sgdamore * Redistribution and use in source and binary forms, with or without 37a5c89047Sgdamore * modification, are permitted provided that the following conditions 38a5c89047Sgdamore * are met: 39a5c89047Sgdamore * 1. Redistributions of source code must retain the above copyright 40a5c89047Sgdamore * notice, this list of conditions and the following disclaimer. 41a5c89047Sgdamore * 2. Redistributions in binary form must reproduce the above copyright 42a5c89047Sgdamore * notice, this list of conditions and the following disclaimer in the 43a5c89047Sgdamore * documentation and/or other materials provided with the distribution. 44a5c89047Sgdamore * 45a5c89047Sgdamore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 46a5c89047Sgdamore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 47a5c89047Sgdamore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 48a5c89047Sgdamore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 49a5c89047Sgdamore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 50a5c89047Sgdamore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 51a5c89047Sgdamore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 52a5c89047Sgdamore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 53a5c89047Sgdamore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 54a5c89047Sgdamore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 55a5c89047Sgdamore * SUCH DAMAGE. 56a5c89047Sgdamore * 57*4bb965d0Splunky * $Id: l2cap.h,v 1.19 2015/11/28 07:50:37 plunky Exp $ 58a5c89047Sgdamore * $FreeBSD: src/sys/netgraph/bluetooth/include/l2cap.h,v 1.4 2005/08/31 18:13:23 emax Exp $ 59a5c89047Sgdamore */ 60a5c89047Sgdamore 61a5c89047Sgdamore /* 62a5c89047Sgdamore * This file contains everything that application needs to know about 63a5c89047Sgdamore * Link Layer Control and Adaptation Protocol (L2CAP). All information 64a5c89047Sgdamore * was obtained from Bluetooth Specification Books (v1.1 and up) 65a5c89047Sgdamore * 66a5c89047Sgdamore * This file can be included by both kernel and userland applications. 67a5c89047Sgdamore */ 68a5c89047Sgdamore 69a5c89047Sgdamore #ifndef _NETBT_L2CAP_H_ 70a5c89047Sgdamore #define _NETBT_L2CAP_H_ 71a5c89047Sgdamore 729fcb439aSplunky #include <sys/types.h> 739fcb439aSplunky 74a5c89047Sgdamore /************************************************************************** 75a5c89047Sgdamore ************************************************************************** 76a5c89047Sgdamore ** Common defines and types (L2CAP) 77a5c89047Sgdamore ************************************************************************** 78a5c89047Sgdamore **************************************************************************/ 79a5c89047Sgdamore 80a5c89047Sgdamore /* 81a5c89047Sgdamore * Channel IDs are assigned per machine. So the total number of channels that 82a5c89047Sgdamore * a machine can have open at the same time is 0xffff - 0x0040 = 0xffbf (65471). 83a5c89047Sgdamore * This number does not depend on number of HCI connections. 84a5c89047Sgdamore */ 85a5c89047Sgdamore 86a5c89047Sgdamore #define L2CAP_NULL_CID 0x0000 /* DO NOT USE THIS CID */ 87a5c89047Sgdamore #define L2CAP_SIGNAL_CID 0x0001 /* signaling channel ID */ 88a5c89047Sgdamore #define L2CAP_CLT_CID 0x0002 /* connectionless channel ID */ 89a5c89047Sgdamore /* 0x0003 - 0x003f Reserved */ 90a5c89047Sgdamore #define L2CAP_FIRST_CID 0x0040 /* dynamically alloc. (start) */ 91a5c89047Sgdamore #define L2CAP_LAST_CID 0xffff /* dynamically alloc. (end) */ 92a5c89047Sgdamore 93a5c89047Sgdamore /* L2CAP MTU */ 94a5c89047Sgdamore #define L2CAP_MTU_MINIMUM 48 95a5c89047Sgdamore #define L2CAP_MTU_DEFAULT 672 96a5c89047Sgdamore #define L2CAP_MTU_MAXIMUM 0xffff 97a5c89047Sgdamore 98a5c89047Sgdamore /* L2CAP flush and link timeouts */ 99a5c89047Sgdamore #define L2CAP_FLUSH_TIMO_DEFAULT 0xffff /* always retransmit */ 100a5c89047Sgdamore #define L2CAP_LINK_TIMO_DEFAULT 0xffff 101a5c89047Sgdamore 102a5c89047Sgdamore /* L2CAP Command Reject reasons */ 103a5c89047Sgdamore #define L2CAP_REJ_NOT_UNDERSTOOD 0x0000 104a5c89047Sgdamore #define L2CAP_REJ_MTU_EXCEEDED 0x0001 105a5c89047Sgdamore #define L2CAP_REJ_INVALID_CID 0x0002 106a5c89047Sgdamore /* 0x0003 - 0xffff - reserved for future use */ 107a5c89047Sgdamore 108*4bb965d0Splunky /* Protocol/Service Multiplexer (PSM) values */ 109a5c89047Sgdamore #define L2CAP_PSM_ANY 0x0000 /* Any/Invalid PSM */ 110a5c89047Sgdamore #define L2CAP_PSM_SDP 0x0001 /* Service Discovery Protocol */ 111a5c89047Sgdamore #define L2CAP_PSM_RFCOMM 0x0003 /* RFCOMM protocol */ 112a5c89047Sgdamore #define L2CAP_PSM_TCP 0x0005 /* Telephony Control Protocol */ 113a5c89047Sgdamore #define L2CAP_PSM_TCS 0x0007 /* TCS cordless */ 114a5c89047Sgdamore #define L2CAP_PSM_BNEP 0x000f /* Bluetooth Network */ 115a5c89047Sgdamore /* Encapsulation Protocol*/ 116a5c89047Sgdamore #define L2CAP_PSM_HID_CNTL 0x0011 /* HID Control */ 117a5c89047Sgdamore #define L2CAP_PSM_HID_INTR 0x0013 /* HID Interrupt */ 118a5c89047Sgdamore #define L2CAP_PSM_ESDP 0x0015 /* Extended Service */ 119a5c89047Sgdamore /* Discovery Profile */ 120a5c89047Sgdamore #define L2CAP_PSM_AVCTP 0x0017 /* Audio/Visual Control */ 121a5c89047Sgdamore /* Transport Protocol */ 122a5c89047Sgdamore #define L2CAP_PSM_AVDTP 0x0019 /* Audio/Visual Distribution */ 123a5c89047Sgdamore /* Transport Protocol */ 124*4bb965d0Splunky #define L2CAP_PSM_UDI_C_PLANE 0x001d /* Unrestricted Digital */ 125*4bb965d0Splunky /* Information Profile */ 126*4bb965d0Splunky #define L2CAP_PSM_ATT 0x001f /* Attribute Protocol */ 127*4bb965d0Splunky #define L2CAP_PSM_3DSP 0x0021 /* 3D Synchronization Profile */ 128*4bb965d0Splunky #define L2CAP_PSM_IPSP 0x0023 /* Internet Protocol */ 129*4bb965d0Splunky /* Support Profile */ 130*4bb965d0Splunky /* 0x0025 - 0x1000 - reserved for future use */ 131a5c89047Sgdamore 132a5c89047Sgdamore #define L2CAP_PSM_INVALID(psm) (((psm) & 0x0101) != 0x0001) 133a5c89047Sgdamore 134a5c89047Sgdamore /* L2CAP Connection response command result codes */ 135a5c89047Sgdamore #define L2CAP_SUCCESS 0x0000 136a5c89047Sgdamore #define L2CAP_PENDING 0x0001 137a5c89047Sgdamore #define L2CAP_PSM_NOT_SUPPORTED 0x0002 138a5c89047Sgdamore #define L2CAP_SECURITY_BLOCK 0x0003 139a5c89047Sgdamore #define L2CAP_NO_RESOURCES 0x0004 140a5c89047Sgdamore #define L2CAP_TIMEOUT 0xeeee 141a5c89047Sgdamore #define L2CAP_UNKNOWN 0xffff 142a5c89047Sgdamore /* 0x0005 - 0xffff - reserved for future use */ 143a5c89047Sgdamore 144a5c89047Sgdamore /* L2CAP Connection response status codes */ 145a5c89047Sgdamore #define L2CAP_NO_INFO 0x0000 146a5c89047Sgdamore #define L2CAP_AUTH_PENDING 0x0001 147a5c89047Sgdamore #define L2CAP_AUTZ_PENDING 0x0002 148a5c89047Sgdamore /* 0x0003 - 0xffff - reserved for future use */ 149a5c89047Sgdamore 150a5c89047Sgdamore /* L2CAP Configuration response result codes */ 151a5c89047Sgdamore #define L2CAP_UNACCEPTABLE_PARAMS 0x0001 152a5c89047Sgdamore #define L2CAP_REJECT 0x0002 153a5c89047Sgdamore #define L2CAP_UNKNOWN_OPTION 0x0003 154a5c89047Sgdamore /* 0x0003 - 0xffff - reserved for future use */ 155a5c89047Sgdamore 156a5c89047Sgdamore /* L2CAP Configuration options */ 157a5c89047Sgdamore #define L2CAP_OPT_CFLAG_BIT 0x0001 158a5c89047Sgdamore #define L2CAP_OPT_CFLAG(flags) ((flags) & L2CAP_OPT_CFLAG_BIT) 159a5c89047Sgdamore #define L2CAP_OPT_HINT_BIT 0x80 160a5c89047Sgdamore #define L2CAP_OPT_HINT(type) ((type) & L2CAP_OPT_HINT_BIT) 161a5c89047Sgdamore #define L2CAP_OPT_HINT_MASK 0x7f 162a5c89047Sgdamore #define L2CAP_OPT_MTU 0x01 163a5c89047Sgdamore #define L2CAP_OPT_MTU_SIZE sizeof(uint16_t) 164a5c89047Sgdamore #define L2CAP_OPT_FLUSH_TIMO 0x02 165a5c89047Sgdamore #define L2CAP_OPT_FLUSH_TIMO_SIZE sizeof(uint16_t) 166a5c89047Sgdamore #define L2CAP_OPT_QOS 0x03 167a5c89047Sgdamore #define L2CAP_OPT_QOS_SIZE sizeof(l2cap_qos_t) 168a5c89047Sgdamore #define L2CAP_OPT_RFC 0x04 169a5c89047Sgdamore #define L2CAP_OPT_RFC_SIZE sizeof(l2cap_rfc_t) 170a5c89047Sgdamore /* 0x05 - 0xff - reserved for future use */ 171a5c89047Sgdamore 172a5c89047Sgdamore /* L2CAP Information request type codes */ 173a5c89047Sgdamore #define L2CAP_CONNLESS_MTU 0x0001 174a5c89047Sgdamore #define L2CAP_EXTENDED_FEATURES 0x0002 175b8121e9bSplunky #define L2CAP_FIXED_CHANNELS 0x0003 176b8121e9bSplunky /* 0x0004 - 0xffff - reserved for future use */ 177a5c89047Sgdamore 178a5c89047Sgdamore /* L2CAP Information response codes */ 179a5c89047Sgdamore #define L2CAP_NOT_SUPPORTED 0x0001 180a5c89047Sgdamore /* 0x0002 - 0xffff - reserved for future use */ 181a5c89047Sgdamore 182a5c89047Sgdamore /* L2CAP Quality of Service option */ 183a5c89047Sgdamore typedef struct { 184a5c89047Sgdamore uint8_t flags; /* reserved for future use */ 185a5c89047Sgdamore uint8_t service_type; /* service type */ 186a5c89047Sgdamore uint32_t token_rate; /* bytes per second */ 187a5c89047Sgdamore uint32_t token_bucket_size; /* bytes */ 188a5c89047Sgdamore uint32_t peak_bandwidth; /* bytes per second */ 189a5c89047Sgdamore uint32_t latency; /* microseconds */ 190a5c89047Sgdamore uint32_t delay_variation; /* microseconds */ 1910de5da96Sgmcgarry } __packed l2cap_qos_t; 192a5c89047Sgdamore 193a5c89047Sgdamore /* L2CAP QoS type */ 194a5c89047Sgdamore #define L2CAP_QOS_NO_TRAFFIC 0x00 195a5c89047Sgdamore #define L2CAP_QOS_BEST_EFFORT 0x01 /* (default) */ 196a5c89047Sgdamore #define L2CAP_QOS_GUARANTEED 0x02 197a5c89047Sgdamore /* 0x03 - 0xff - reserved for future use */ 198a5c89047Sgdamore 199a5c89047Sgdamore /* L2CAP Retransmission & Flow Control option */ 200a5c89047Sgdamore typedef struct { 201a5c89047Sgdamore uint8_t mode; /* RFC mode */ 202a5c89047Sgdamore uint8_t window_size; /* bytes */ 203a5c89047Sgdamore uint8_t max_transmit; /* max retransmissions */ 204a5c89047Sgdamore uint16_t retransmit_timo; /* milliseconds */ 205a5c89047Sgdamore uint16_t monitor_timo; /* milliseconds */ 206a5c89047Sgdamore uint16_t max_pdu_size; /* bytes */ 2070de5da96Sgmcgarry } __packed l2cap_rfc_t; 208a5c89047Sgdamore 209a5c89047Sgdamore /* L2CAP RFC mode */ 210a5c89047Sgdamore #define L2CAP_RFC_BASIC 0x00 /* (default) */ 211a5c89047Sgdamore #define L2CAP_RFC_RETRANSMIT 0x01 212a5c89047Sgdamore #define L2CAP_RFC_FLOW 0x02 213a5c89047Sgdamore /* 0x03 - 0xff - reserved for future use */ 214a5c89047Sgdamore 215a5c89047Sgdamore /************************************************************************** 216a5c89047Sgdamore ************************************************************************** 217a5c89047Sgdamore ** Link level defines, headers and types 218a5c89047Sgdamore ************************************************************************** 219a5c89047Sgdamore **************************************************************************/ 220a5c89047Sgdamore 221a5c89047Sgdamore /* L2CAP header */ 222a5c89047Sgdamore typedef struct { 223a5c89047Sgdamore uint16_t length; /* payload size */ 224a5c89047Sgdamore uint16_t dcid; /* destination channel ID */ 2250de5da96Sgmcgarry } __packed l2cap_hdr_t; 226a5c89047Sgdamore 227a5c89047Sgdamore /* L2CAP ConnectionLess Traffic (dcid == L2CAP_CLT_CID) */ 228a5c89047Sgdamore typedef struct { 229*4bb965d0Splunky uint16_t psm; /* Protocol/Service Multiplexer */ 2300de5da96Sgmcgarry } __packed l2cap_clt_hdr_t; 231a5c89047Sgdamore 232a5c89047Sgdamore #define L2CAP_CLT_MTU_MAXIMUM \ 233a5c89047Sgdamore (L2CAP_MTU_MAXIMUM - sizeof(l2cap_clt_hdr_t)) 234a5c89047Sgdamore 235a5c89047Sgdamore /* L2CAP Command header (dcid == L2CAP_SIGNAL_CID) */ 236a5c89047Sgdamore typedef struct { 237a5c89047Sgdamore uint8_t code; /* command OpCode */ 238a5c89047Sgdamore uint8_t ident; /* identifier to match request and response */ 239a5c89047Sgdamore uint16_t length; /* command parameters length */ 2400de5da96Sgmcgarry } __packed l2cap_cmd_hdr_t; 241a5c89047Sgdamore 242a5c89047Sgdamore /* L2CAP Command Reject */ 243a5c89047Sgdamore #define L2CAP_COMMAND_REJ 0x01 244a5c89047Sgdamore typedef struct { 245a5c89047Sgdamore uint16_t reason; /* reason to reject command */ 246a5c89047Sgdamore uint16_t data[2];/* optional data */ 2470de5da96Sgmcgarry } __packed l2cap_cmd_rej_cp; 248a5c89047Sgdamore 249a5c89047Sgdamore /* L2CAP Connection Request */ 250a5c89047Sgdamore #define L2CAP_CONNECT_REQ 0x02 251a5c89047Sgdamore typedef struct { 252*4bb965d0Splunky uint16_t psm; /* Protocol/Service Multiplexer */ 253a5c89047Sgdamore uint16_t scid; /* source channel ID */ 2540de5da96Sgmcgarry } __packed l2cap_con_req_cp; 255a5c89047Sgdamore 256a5c89047Sgdamore /* L2CAP Connection Response */ 257a5c89047Sgdamore #define L2CAP_CONNECT_RSP 0x03 258a5c89047Sgdamore typedef struct { 259a5c89047Sgdamore uint16_t dcid; /* destination channel ID */ 260a5c89047Sgdamore uint16_t scid; /* source channel ID */ 261a5c89047Sgdamore uint16_t result; /* 0x00 - success */ 262a5c89047Sgdamore uint16_t status; /* more info if result != 0x00 */ 2630de5da96Sgmcgarry } __packed l2cap_con_rsp_cp; 264a5c89047Sgdamore 265a5c89047Sgdamore /* L2CAP Configuration Request */ 266a5c89047Sgdamore #define L2CAP_CONFIG_REQ 0x04 267a5c89047Sgdamore typedef struct { 268a5c89047Sgdamore uint16_t dcid; /* destination channel ID */ 269a5c89047Sgdamore uint16_t flags; /* flags */ 270a5c89047Sgdamore /* uint8_t options[] -- options */ 2710de5da96Sgmcgarry } __packed l2cap_cfg_req_cp; 272a5c89047Sgdamore 273a5c89047Sgdamore /* L2CAP Configuration Response */ 274a5c89047Sgdamore #define L2CAP_CONFIG_RSP 0x05 275a5c89047Sgdamore typedef struct { 276a5c89047Sgdamore uint16_t scid; /* source channel ID */ 277a5c89047Sgdamore uint16_t flags; /* flags */ 278a5c89047Sgdamore uint16_t result; /* 0x00 - success */ 279a5c89047Sgdamore /* uint8_t options[] -- options */ 2800de5da96Sgmcgarry } __packed l2cap_cfg_rsp_cp; 281a5c89047Sgdamore 282a5c89047Sgdamore /* L2CAP configuration option */ 283a5c89047Sgdamore typedef struct { 284a5c89047Sgdamore uint8_t type; 285a5c89047Sgdamore uint8_t length; 286a5c89047Sgdamore /* uint8_t value[] -- option value (depends on type) */ 2870de5da96Sgmcgarry } __packed l2cap_cfg_opt_t; 288a5c89047Sgdamore 289a5c89047Sgdamore /* L2CAP configuration option value */ 290a5c89047Sgdamore typedef union { 291a5c89047Sgdamore uint16_t mtu; /* L2CAP_OPT_MTU */ 292a5c89047Sgdamore uint16_t flush_timo; /* L2CAP_OPT_FLUSH_TIMO */ 293a5c89047Sgdamore l2cap_qos_t qos; /* L2CAP_OPT_QOS */ 294a5c89047Sgdamore l2cap_rfc_t rfc; /* L2CAP_OPT_RFC */ 295a5c89047Sgdamore } l2cap_cfg_opt_val_t; 296a5c89047Sgdamore 297a5c89047Sgdamore /* L2CAP Disconnect Request */ 298a5c89047Sgdamore #define L2CAP_DISCONNECT_REQ 0x06 299a5c89047Sgdamore typedef struct { 300a5c89047Sgdamore uint16_t dcid; /* destination channel ID */ 301a5c89047Sgdamore uint16_t scid; /* source channel ID */ 3020de5da96Sgmcgarry } __packed l2cap_discon_req_cp; 303a5c89047Sgdamore 304a5c89047Sgdamore /* L2CAP Disconnect Response */ 305a5c89047Sgdamore #define L2CAP_DISCONNECT_RSP 0x07 306a5c89047Sgdamore typedef l2cap_discon_req_cp l2cap_discon_rsp_cp; 307a5c89047Sgdamore 308a5c89047Sgdamore /* L2CAP Echo Request */ 309a5c89047Sgdamore #define L2CAP_ECHO_REQ 0x08 310a5c89047Sgdamore /* No command parameters, only optional data */ 311a5c89047Sgdamore 312a5c89047Sgdamore /* L2CAP Echo Response */ 313a5c89047Sgdamore #define L2CAP_ECHO_RSP 0x09 314a5c89047Sgdamore #define L2CAP_MAX_ECHO_SIZE \ 315a5c89047Sgdamore (L2CAP_MTU_MAXIMUM - sizeof(l2cap_cmd_hdr_t)) 316a5c89047Sgdamore /* No command parameters, only optional data */ 317a5c89047Sgdamore 318a5c89047Sgdamore /* L2CAP Information Request */ 319a5c89047Sgdamore #define L2CAP_INFO_REQ 0x0a 320a5c89047Sgdamore typedef struct { 321a5c89047Sgdamore uint16_t type; /* requested information type */ 3220de5da96Sgmcgarry } __packed l2cap_info_req_cp; 323a5c89047Sgdamore 324a5c89047Sgdamore /* L2CAP Information Response */ 325a5c89047Sgdamore #define L2CAP_INFO_RSP 0x0b 326a5c89047Sgdamore typedef struct { 327a5c89047Sgdamore uint16_t type; /* requested information type */ 328a5c89047Sgdamore uint16_t result; /* 0x00 - success */ 329a5c89047Sgdamore /* uint8_t info[] -- info data (depends on type) 330a5c89047Sgdamore */ 3310de5da96Sgmcgarry } __packed l2cap_info_rsp_cp; 332a5c89047Sgdamore 333a5c89047Sgdamore 334a5c89047Sgdamore /************************************************************************** 335a5c89047Sgdamore ************************************************************************** 336a5c89047Sgdamore ** L2CAP Socket Definitions 337a5c89047Sgdamore ************************************************************************** 338a5c89047Sgdamore **************************************************************************/ 339a5c89047Sgdamore 340f5db72e7Splunky /* Socket options */ 341f5db72e7Splunky #define SO_L2CAP_IMTU 1 /* incoming MTU */ 342f5db72e7Splunky #define SO_L2CAP_OMTU 2 /* outgoing MTU */ 343f5db72e7Splunky #define SO_L2CAP_IQOS 3 /* incoming QoS */ 344f5db72e7Splunky #define SO_L2CAP_OQOS 4 /* outgoing QoS */ 345f5db72e7Splunky #define SO_L2CAP_FLUSH 5 /* flush timeout */ 346f5db72e7Splunky #define SO_L2CAP_LM 6 /* link mode */ 347f5db72e7Splunky 348f5db72e7Splunky /* L2CAP link mode flags */ 349f5db72e7Splunky #define L2CAP_LM_AUTH (1<<0) /* want authentication */ 350f5db72e7Splunky #define L2CAP_LM_ENCRYPT (1<<1) /* want encryption */ 351f5db72e7Splunky #define L2CAP_LM_SECURE (1<<2) /* want secured link */ 352a5c89047Sgdamore 353a5c89047Sgdamore #ifdef _KERNEL 354a5c89047Sgdamore 355a5c89047Sgdamore LIST_HEAD(l2cap_channel_list, l2cap_channel); 356a5c89047Sgdamore 357a5c89047Sgdamore /* global variables */ 358a5c89047Sgdamore extern struct l2cap_channel_list l2cap_active_list; 359a5c89047Sgdamore extern struct l2cap_channel_list l2cap_listen_list; 360a5c89047Sgdamore extern struct pool l2cap_pdu_pool; 361a5c89047Sgdamore extern struct pool l2cap_req_pool; 362a5c89047Sgdamore extern const l2cap_qos_t l2cap_default_qos; 363a5c89047Sgdamore 364a5c89047Sgdamore /* sysctl variables */ 365a5c89047Sgdamore extern int l2cap_response_timeout; 366a5c89047Sgdamore extern int l2cap_response_extended_timeout; 367a5c89047Sgdamore extern int l2cap_sendspace, l2cap_recvspace; 368a5c89047Sgdamore 369a5c89047Sgdamore /* 370a5c89047Sgdamore * L2CAP Channel 371a5c89047Sgdamore */ 372a5c89047Sgdamore struct l2cap_channel { 373a5c89047Sgdamore struct hci_link *lc_link; /* ACL connection (down) */ 374a5c89047Sgdamore uint16_t lc_state; /* channel state */ 375a5c89047Sgdamore uint16_t lc_flags; /* channel flags */ 376f5db72e7Splunky uint8_t lc_ident; /* cached request id */ 377a5c89047Sgdamore 378a5c89047Sgdamore uint16_t lc_lcid; /* local channel ID */ 379a5c89047Sgdamore struct sockaddr_bt lc_laddr; /* local address */ 380a5c89047Sgdamore 381a5c89047Sgdamore uint16_t lc_rcid; /* remote channel ID */ 382a5c89047Sgdamore struct sockaddr_bt lc_raddr; /* remote address */ 383a5c89047Sgdamore 384f5db72e7Splunky int lc_mode; /* link mode */ 385a5c89047Sgdamore uint16_t lc_imtu; /* incoming mtu */ 386a5c89047Sgdamore uint16_t lc_omtu; /* outgoing mtu */ 387a5c89047Sgdamore uint16_t lc_flush; /* flush timeout */ 388a5c89047Sgdamore l2cap_qos_t lc_iqos; /* incoming QoS flow control */ 389a5c89047Sgdamore l2cap_qos_t lc_oqos; /* outgoing Qos flow control */ 390a5c89047Sgdamore 391a5c89047Sgdamore uint8_t lc_pending; /* num of pending PDUs */ 392a5c89047Sgdamore MBUFQ_HEAD() lc_txq; /* transmit queue */ 393a5c89047Sgdamore 394a5c89047Sgdamore const struct btproto *lc_proto; /* upper layer callbacks */ 395a5c89047Sgdamore void *lc_upper; /* upper layer argument */ 396a5c89047Sgdamore 397a5c89047Sgdamore LIST_ENTRY(l2cap_channel)lc_ncid; /* next channel (ascending CID) */ 398a5c89047Sgdamore }; 399a5c89047Sgdamore 400f42c04d4Splunky /* l2cap_channel state */ 401f42c04d4Splunky #define L2CAP_CLOSED 0 /* closed */ 402f5db72e7Splunky #define L2CAP_WAIT_SEND_CONNECT_REQ 1 /* waiting to send connect request */ 403f5db72e7Splunky #define L2CAP_WAIT_RECV_CONNECT_RSP 2 /* waiting to recv connect response */ 404f5db72e7Splunky #define L2CAP_WAIT_SEND_CONNECT_RSP 3 /* waiting to send connect response */ 405f5db72e7Splunky #define L2CAP_WAIT_CONFIG 4 /* waiting for configuration */ 406f5db72e7Splunky #define L2CAP_OPEN 5 /* user data transfer state */ 407f5db72e7Splunky #define L2CAP_WAIT_DISCONNECT 6 /* have sent disconnect request */ 408a5c89047Sgdamore 409a5c89047Sgdamore /* l2cap_channel flags */ 410a5c89047Sgdamore #define L2CAP_SHUTDOWN (1<<0) /* channel is closing */ 411f42c04d4Splunky #define L2CAP_WAIT_CONFIG_REQ (1<<1) /* waiting for config request */ 412f42c04d4Splunky #define L2CAP_WAIT_CONFIG_RSP (1<<2) /* waiting for config response */ 413a5c89047Sgdamore 414a5c89047Sgdamore /* 415a5c89047Sgdamore * L2CAP Request 416a5c89047Sgdamore */ 417a5c89047Sgdamore struct l2cap_req { 418a5c89047Sgdamore struct hci_link *lr_link; /* ACL connection */ 419a5c89047Sgdamore struct l2cap_channel *lr_chan; /* channel pointer */ 420a5c89047Sgdamore uint8_t lr_code; /* request code */ 421a5c89047Sgdamore uint8_t lr_id; /* request id */ 422644e69cdSplunky callout_t lr_rtx; /* response timer */ 423a5c89047Sgdamore TAILQ_ENTRY(l2cap_req) lr_next; /* next request on link */ 424a5c89047Sgdamore }; 425a5c89047Sgdamore 426a5c89047Sgdamore /* 427a5c89047Sgdamore * L2CAP Protocol Data Unit 428a5c89047Sgdamore */ 429a5c89047Sgdamore struct l2cap_pdu { 430a5c89047Sgdamore struct l2cap_channel *lp_chan; /* PDU owner */ 431a5c89047Sgdamore MBUFQ_HEAD() lp_data; /* PDU data */ 432a5c89047Sgdamore TAILQ_ENTRY(l2cap_pdu) lp_next; /* next PDU on link */ 433a5c89047Sgdamore int lp_pending; /* # of fragments pending */ 434a5c89047Sgdamore }; 435a5c89047Sgdamore 436a5c89047Sgdamore /* 437a5c89047Sgdamore * L2CAP function prototypes 438a5c89047Sgdamore */ 439a5c89047Sgdamore 440a5c89047Sgdamore struct socket; 441fd7356a9Splunky struct sockopt; 442a5c89047Sgdamore struct mbuf; 443a5c89047Sgdamore 444a5c89047Sgdamore /* l2cap_lower.c */ 445a5c89047Sgdamore void l2cap_close(struct l2cap_channel *, int); 446a5c89047Sgdamore void l2cap_recv_frame(struct mbuf *, struct hci_link *); 447a5c89047Sgdamore int l2cap_start(struct l2cap_channel *); 448a5c89047Sgdamore 449a5c89047Sgdamore /* l2cap_misc.c */ 450f5db72e7Splunky int l2cap_setmode(struct l2cap_channel *); 451a5c89047Sgdamore int l2cap_cid_alloc(struct l2cap_channel *); 452a5c89047Sgdamore struct l2cap_channel *l2cap_cid_lookup(uint16_t); 453a5c89047Sgdamore int l2cap_request_alloc(struct l2cap_channel *, uint8_t); 454a5c89047Sgdamore struct l2cap_req *l2cap_request_lookup(struct hci_link *, uint8_t); 455a5c89047Sgdamore void l2cap_request_free(struct l2cap_req *); 456a5c89047Sgdamore void l2cap_rtx(void *); 457fbd53556Spooka void l2cap_init(void); 458a5c89047Sgdamore 459a5c89047Sgdamore /* l2cap_signal.c */ 460a5c89047Sgdamore void l2cap_recv_signal(struct mbuf *, struct hci_link *); 461a5c89047Sgdamore int l2cap_send_connect_req(struct l2cap_channel *); 462a5c89047Sgdamore int l2cap_send_config_req(struct l2cap_channel *); 463a5c89047Sgdamore int l2cap_send_disconnect_req(struct l2cap_channel *); 464f5db72e7Splunky int l2cap_send_connect_rsp(struct hci_link *, uint8_t, uint16_t, uint16_t, uint16_t); 465a5c89047Sgdamore 466a5c89047Sgdamore /* l2cap_socket.c */ 467fd7356a9Splunky int l2cap_ctloutput(int, struct socket *, struct sockopt *); 468a5c89047Sgdamore 469a5c89047Sgdamore /* l2cap_upper.c */ 4708db4ab26Srmind int l2cap_attach_pcb(struct l2cap_channel **, const struct btproto *, void *); 47150c78d5eSrtr int l2cap_bind_pcb(struct l2cap_channel *, struct sockaddr_bt *); 4723bb356e9Srtr int l2cap_sockaddr_pcb(struct l2cap_channel *, struct sockaddr_bt *); 4734d1c14a6Srtr int l2cap_connect_pcb(struct l2cap_channel *, struct sockaddr_bt *); 4743bb356e9Srtr int l2cap_peeraddr_pcb(struct l2cap_channel *, struct sockaddr_bt *); 47508e341e4Srtr int l2cap_disconnect_pcb(struct l2cap_channel *, int); 4768db4ab26Srmind void l2cap_detach_pcb(struct l2cap_channel **); 47750c78d5eSrtr int l2cap_listen_pcb(struct l2cap_channel *); 478c0e2453cSrtr int l2cap_send_pcb(struct l2cap_channel *, struct mbuf *); 479fd7356a9Splunky int l2cap_setopt(struct l2cap_channel *, const struct sockopt *); 480fd7356a9Splunky int l2cap_getopt(struct l2cap_channel *, struct sockopt *); 481a5c89047Sgdamore 482a5c89047Sgdamore #endif /* _KERNEL */ 483a5c89047Sgdamore 484a5c89047Sgdamore #endif /* _NETBT_L2CAP_H_ */ 485