ng_l2cap_var.h revision 114878
1107120Sjulian/* 2107120Sjulian * ng_l2cap_var.h 3107120Sjulian * 4107120Sjulian * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5107120Sjulian * All rights reserved. 6107120Sjulian * 7107120Sjulian * Redistribution and use in source and binary forms, with or without 8107120Sjulian * modification, are permitted provided that the following conditions 9107120Sjulian * are met: 10107120Sjulian * 1. Redistributions of source code must retain the above copyright 11107120Sjulian * notice, this list of conditions and the following disclaimer. 12107120Sjulian * 2. Redistributions in binary form must reproduce the above copyright 13107120Sjulian * notice, this list of conditions and the following disclaimer in the 14107120Sjulian * documentation and/or other materials provided with the distribution. 15107120Sjulian * 16107120Sjulian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17107120Sjulian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18107120Sjulian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19107120Sjulian * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20107120Sjulian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21107120Sjulian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22107120Sjulian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23107120Sjulian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24107120Sjulian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25107120Sjulian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26107120Sjulian * SUCH DAMAGE. 27107120Sjulian * 28114878Sjulian * $Id: ng_l2cap_var.h,v 1.2 2003/04/28 21:44:59 max Exp $ 29107120Sjulian * $FreeBSD: head/sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h 114878 2003-05-10 21:44:42Z julian $ 30107120Sjulian */ 31107120Sjulian 32107120Sjulian#ifndef _NETGRAPH_L2CAP_VAR_H_ 33107120Sjulian#define _NETGRAPH_L2CAP_VAR_H_ 1 34107120Sjulian 35107120Sjulian/* MALLOC decalation */ 36107120Sjulian#ifdef NG_SEPARATE_MALLOC 37107120SjulianMALLOC_DECLARE(M_NETGRAPH_L2CAP); 38107120Sjulian#else 39107120Sjulian#define M_NETGRAPH_L2CAP M_NETGRAPH 40107120Sjulian#endif /* NG_SEPARATE_MALLOC */ 41107120Sjulian 42107120Sjulian/* Debug */ 43107120Sjulian#define NG_L2CAP_ALERT if (l2cap->debug >= NG_L2CAP_ALERT_LEVEL) printf 44107120Sjulian#define NG_L2CAP_ERR if (l2cap->debug >= NG_L2CAP_ERR_LEVEL) printf 45107120Sjulian#define NG_L2CAP_WARN if (l2cap->debug >= NG_L2CAP_WARN_LEVEL) printf 46107120Sjulian#define NG_L2CAP_INFO if (l2cap->debug >= NG_L2CAP_INFO_LEVEL) printf 47107120Sjulian 48107120Sjulian/* Wrapper around m_pullup */ 49107120Sjulian#define NG_L2CAP_M_PULLUP(m, s) \ 50107120Sjulian do { \ 51107120Sjulian if ((m)->m_len < (s)) \ 52107120Sjulian (m) = m_pullup((m), (s)); \ 53107120Sjulian if ((m) == NULL) \ 54107120Sjulian NG_L2CAP_ALERT("%s: %s - m_pullup(%d) failed\n", \ 55107120Sjulian __func__, NG_NODE_NAME(l2cap->node), (s)); \ 56107120Sjulian } while (0) 57107120Sjulian 58107120Sjulian/* 59107120Sjulian * L2CAP signaling command ident's are assigned relative to the connection, 60107120Sjulian * because there is only one signaling channel (cid == 0x01) for every 61107120Sjulian * connection. So up to 254 (0xff - 0x01) L2CAP commands can be pending at the 62107120Sjulian * same time for the same connection. 63107120Sjulian */ 64107120Sjulian 65107120Sjulian#define NG_L2CAP_NULL_IDENT 0x00 /* DO NOT USE THIS IDENT */ 66107120Sjulian#define NG_L2CAP_FIRST_IDENT 0x01 /* dynamically alloc. (start) */ 67107120Sjulian#define NG_L2CAP_LAST_IDENT 0xff /* dynamically alloc. (end) */ 68107120Sjulian 69107120Sjulian/* 70107120Sjulian * L2CAP (Node private) 71107120Sjulian */ 72107120Sjulian 73107120Sjulianstruct ng_l2cap_con; 74107120Sjulianstruct ng_l2cap_chan; 75107120Sjulian 76107120Sjuliantypedef struct ng_l2cap { 77107120Sjulian node_p node; /* node ptr */ 78107120Sjulian 79107120Sjulian ng_l2cap_node_debug_ep debug; /* debug level */ 80107120Sjulian ng_l2cap_node_flags_ep flags; /* L2CAP node flags */ 81114878Sjulian ng_l2cap_node_auto_discon_ep discon_timo; /* auto discon. timeout */ 82107120Sjulian 83107120Sjulian u_int16_t pkt_size; /* max. ACL packet size */ 84107120Sjulian u_int16_t num_pkts; /* out queue size */ 85114878Sjulian bdaddr_t bdaddr; /* unit BDADDR */ 86107120Sjulian 87107120Sjulian hook_p hci; /* HCI downstream hook */ 88107120Sjulian hook_p l2c; /* L2CAP upstream hook */ 89107120Sjulian hook_p ctl; /* control hook */ 90107120Sjulian 91107120Sjulian LIST_HEAD(, ng_l2cap_con) con_list; /* ACL connections */ 92107120Sjulian 93107120Sjulian u_int16_t cid; /* last allocated CID */ 94107120Sjulian LIST_HEAD(, ng_l2cap_chan) chan_list; /* L2CAP channels */ 95107120Sjulian} ng_l2cap_t; 96107120Sjuliantypedef ng_l2cap_t * ng_l2cap_p; 97107120Sjulian 98107120Sjulian/* 99107120Sjulian * L2CAP connection descriptor 100107120Sjulian */ 101107120Sjulian 102107120Sjulianstruct ng_l2cap_cmd; 103107120Sjulian 104107120Sjuliantypedef struct ng_l2cap_con { 105107120Sjulian ng_l2cap_p l2cap; /* pointer to L2CAP */ 106107120Sjulian 107107120Sjulian u_int16_t state; /* ACL connection state */ 108114878Sjulian u_int16_t flags; /* ACL connection flags */ 109107120Sjulian 110114878Sjulian int32_t refcnt; /* reference count */ 111114878Sjulian 112107120Sjulian bdaddr_t remote; /* remote unit address */ 113107120Sjulian u_int16_t con_handle; /* ACL connection handle */ 114107120Sjulian struct callout_handle con_timo; /* connection timeout */ 115107120Sjulian 116107120Sjulian u_int8_t ident; /* last allocated ident */ 117107120Sjulian TAILQ_HEAD(, ng_l2cap_cmd) cmd_list; /* pending L2CAP cmds */ 118107120Sjulian 119107120Sjulian struct mbuf *tx_pkt; /* xmitted L2CAP packet */ 120107120Sjulian int pending; /* num. of pending pkts */ 121107120Sjulian 122107120Sjulian struct mbuf *rx_pkt; /* received L2CAP packet */ 123107120Sjulian int rx_pkt_len; /* packet len. so far */ 124107120Sjulian 125107120Sjulian LIST_ENTRY(ng_l2cap_con) next; /* link */ 126107120Sjulian} ng_l2cap_con_t; 127107120Sjuliantypedef ng_l2cap_con_t * ng_l2cap_con_p; 128107120Sjulian 129107120Sjulian/* 130107120Sjulian * L2CAP channel descriptor 131107120Sjulian */ 132107120Sjulian 133107120Sjuliantypedef struct ng_l2cap_chan { 134107120Sjulian ng_l2cap_con_p con; /* pointer to connection */ 135107120Sjulian 136107120Sjulian u_int16_t state; /* channel state */ 137107120Sjulian 138107120Sjulian u_int8_t cfg_state; /* configuration state */ 139107120Sjulian#define NG_L2CAP_CFG_IN (1 << 0) /* incoming cfg path done */ 140107120Sjulian#define NG_L2CAP_CFG_OUT (1 << 1) /* outgoing cfg path done */ 141107120Sjulian#define NG_L2CAP_CFG_BOTH (NG_L2CAP_CFG_IN|NG_L2CAP_CFG_OUT) 142107120Sjulian 143107120Sjulian u_int8_t ident; /* last L2CAP req. ident */ 144107120Sjulian 145107120Sjulian u_int16_t psm; /* channel PSM */ 146107120Sjulian u_int16_t scid; /* source channel ID */ 147107120Sjulian u_int16_t dcid; /* destination channel ID */ 148107120Sjulian 149107120Sjulian u_int16_t imtu; /* incoming channel MTU */ 150107120Sjulian ng_l2cap_flow_t iflow; /* incoming flow control */ 151107120Sjulian 152107120Sjulian u_int16_t omtu; /* outgoing channel MTU */ 153107120Sjulian ng_l2cap_flow_t oflow; /* outgoing flow control */ 154107120Sjulian 155107120Sjulian u_int16_t flush_timo; /* flush timeout */ 156107120Sjulian u_int16_t link_timo; /* link timeout */ 157107120Sjulian 158107120Sjulian LIST_ENTRY(ng_l2cap_chan) next; /* link */ 159107120Sjulian} ng_l2cap_chan_t; 160107120Sjuliantypedef ng_l2cap_chan_t * ng_l2cap_chan_p; 161107120Sjulian 162107120Sjulian/* 163107120Sjulian * L2CAP command descriptor 164107120Sjulian */ 165107120Sjulian 166107120Sjuliantypedef struct ng_l2cap_cmd { 167107120Sjulian ng_l2cap_con_p con; /* L2CAP connection */ 168107120Sjulian ng_l2cap_chan_p ch; /* L2CAP channel */ 169107120Sjulian 170107120Sjulian u_int16_t flags; /* command flags */ 171107120Sjulian#define NG_L2CAP_CMD_PENDING (1 << 0) /* command is pending */ 172107120Sjulian 173107120Sjulian u_int8_t code; /* L2CAP command opcode */ 174107120Sjulian u_int8_t ident; /* L2CAP command ident */ 175107120Sjulian u_int32_t token; /* L2CA message token */ 176107120Sjulian 177107120Sjulian struct callout_handle timo; /* RTX/ERTX timeout */ 178107120Sjulian 179107120Sjulian struct mbuf *aux; /* optional data */ 180107120Sjulian 181107120Sjulian TAILQ_ENTRY(ng_l2cap_cmd) next; /* link */ 182107120Sjulian} ng_l2cap_cmd_t; 183107120Sjuliantypedef ng_l2cap_cmd_t * ng_l2cap_cmd_p; 184107120Sjulian 185107120Sjulian#endif /* ndef _NETGRAPH_L2CAP_VAR_H_ */ 186107120Sjulian 187