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