ng_l2cap_var.h revision 107120
1/* 2 * ng_l2cap_var.h 3 * 4 * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * $Id: ng_l2cap_var.h,v 1.13 2002/09/04 21:38:38 max Exp $ 29 * $FreeBSD: head/sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h 107120 2002-11-20 23:01:59Z julian $ 30 */ 31 32#ifndef _NETGRAPH_L2CAP_VAR_H_ 33#define _NETGRAPH_L2CAP_VAR_H_ 1 34 35/* MALLOC decalation */ 36#ifdef NG_SEPARATE_MALLOC 37MALLOC_DECLARE(M_NETGRAPH_L2CAP); 38#else 39#define M_NETGRAPH_L2CAP M_NETGRAPH 40#endif /* NG_SEPARATE_MALLOC */ 41 42/* Debug */ 43#define NG_L2CAP_ALERT if (l2cap->debug >= NG_L2CAP_ALERT_LEVEL) printf 44#define NG_L2CAP_ERR if (l2cap->debug >= NG_L2CAP_ERR_LEVEL) printf 45#define NG_L2CAP_WARN if (l2cap->debug >= NG_L2CAP_WARN_LEVEL) printf 46#define NG_L2CAP_INFO if (l2cap->debug >= NG_L2CAP_INFO_LEVEL) printf 47 48/* Wrapper around m_pullup */ 49#define NG_L2CAP_M_PULLUP(m, s) \ 50 do { \ 51 if ((m)->m_len < (s)) \ 52 (m) = m_pullup((m), (s)); \ 53 if ((m) == NULL) \ 54 NG_L2CAP_ALERT("%s: %s - m_pullup(%d) failed\n", \ 55 __func__, NG_NODE_NAME(l2cap->node), (s)); \ 56 } while (0) 57 58/* 59 * L2CAP signaling command ident's are assigned relative to the connection, 60 * because there is only one signaling channel (cid == 0x01) for every 61 * connection. So up to 254 (0xff - 0x01) L2CAP commands can be pending at the 62 * same time for the same connection. 63 */ 64 65#define NG_L2CAP_NULL_IDENT 0x00 /* DO NOT USE THIS IDENT */ 66#define NG_L2CAP_FIRST_IDENT 0x01 /* dynamically alloc. (start) */ 67#define NG_L2CAP_LAST_IDENT 0xff /* dynamically alloc. (end) */ 68 69/* 70 * L2CAP (Node private) 71 */ 72 73struct ng_l2cap_con; 74struct ng_l2cap_chan; 75 76typedef struct ng_l2cap { 77 node_p node; /* node ptr */ 78 79 ng_l2cap_node_debug_ep debug; /* debug level */ 80 ng_l2cap_node_flags_ep flags; /* L2CAP node flags */ 81 82 bdaddr_t bdaddr; /* unit BDADDR */ 83 u_int16_t pkt_size; /* max. ACL packet size */ 84 u_int16_t num_pkts; /* out queue size */ 85 86 hook_p hci; /* HCI downstream hook */ 87 hook_p l2c; /* L2CAP upstream hook */ 88 hook_p ctl; /* control hook */ 89 90 LIST_HEAD(, ng_l2cap_con) con_list; /* ACL connections */ 91 92 u_int16_t cid; /* last allocated CID */ 93 LIST_HEAD(, ng_l2cap_chan) chan_list; /* L2CAP channels */ 94} ng_l2cap_t; 95typedef ng_l2cap_t * ng_l2cap_p; 96 97/* 98 * L2CAP connection descriptor 99 */ 100 101struct ng_l2cap_cmd; 102 103typedef struct ng_l2cap_con { 104 ng_l2cap_p l2cap; /* pointer to L2CAP */ 105 106 u_int16_t state; /* ACL connection state */ 107 108 bdaddr_t remote; /* remote unit address */ 109 u_int16_t con_handle; /* ACL connection handle */ 110 struct callout_handle con_timo; /* connection timeout */ 111 112 u_int8_t ident; /* last allocated ident */ 113 TAILQ_HEAD(, ng_l2cap_cmd) cmd_list; /* pending L2CAP cmds */ 114 115 struct mbuf *tx_pkt; /* xmitted L2CAP packet */ 116 int pending; /* num. of pending pkts */ 117 118 struct mbuf *rx_pkt; /* received L2CAP packet */ 119 int rx_pkt_len; /* packet len. so far */ 120 121 LIST_ENTRY(ng_l2cap_con) next; /* link */ 122} ng_l2cap_con_t; 123typedef ng_l2cap_con_t * ng_l2cap_con_p; 124 125/* 126 * L2CAP channel descriptor 127 */ 128 129typedef struct ng_l2cap_chan { 130 ng_l2cap_con_p con; /* pointer to connection */ 131 132 u_int16_t state; /* channel state */ 133 134 u_int8_t cfg_state; /* configuration state */ 135#define NG_L2CAP_CFG_IN (1 << 0) /* incoming cfg path done */ 136#define NG_L2CAP_CFG_OUT (1 << 1) /* outgoing cfg path done */ 137#define NG_L2CAP_CFG_BOTH (NG_L2CAP_CFG_IN|NG_L2CAP_CFG_OUT) 138 139 u_int8_t ident; /* last L2CAP req. ident */ 140 141 u_int16_t psm; /* channel PSM */ 142 u_int16_t scid; /* source channel ID */ 143 u_int16_t dcid; /* destination channel ID */ 144 145 u_int16_t imtu; /* incoming channel MTU */ 146 ng_l2cap_flow_t iflow; /* incoming flow control */ 147 148 u_int16_t omtu; /* outgoing channel MTU */ 149 ng_l2cap_flow_t oflow; /* outgoing flow control */ 150 151 u_int16_t flush_timo; /* flush timeout */ 152 u_int16_t link_timo; /* link timeout */ 153 154 LIST_ENTRY(ng_l2cap_chan) next; /* link */ 155} ng_l2cap_chan_t; 156typedef ng_l2cap_chan_t * ng_l2cap_chan_p; 157 158/* 159 * L2CAP command descriptor 160 */ 161 162typedef struct ng_l2cap_cmd { 163 ng_l2cap_con_p con; /* L2CAP connection */ 164 ng_l2cap_chan_p ch; /* L2CAP channel */ 165 166 u_int16_t flags; /* command flags */ 167#define NG_L2CAP_CMD_PENDING (1 << 0) /* command is pending */ 168 169 u_int8_t code; /* L2CAP command opcode */ 170 u_int8_t ident; /* L2CAP command ident */ 171 u_int32_t token; /* L2CA message token */ 172 173 struct callout_handle timo; /* RTX/ERTX timeout */ 174 175 struct mbuf *aux; /* optional data */ 176 177 TAILQ_ENTRY(ng_l2cap_cmd) next; /* link */ 178} ng_l2cap_cmd_t; 179typedef ng_l2cap_cmd_t * ng_l2cap_cmd_p; 180 181#endif /* ndef _NETGRAPH_L2CAP_VAR_H_ */ 182 183