Path: blob/main/sys/netgraph/bluetooth/l2cap/ng_l2cap_var.h
34814 views
/*1* ng_l2cap_var.h2*/34/*-5* SPDX-License-Identifier: BSD-2-Clause6*7* Copyright (c) 2001 Maksim Yevmenkin <[email protected]>8* All rights reserved.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18*19* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND20* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE21* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE22* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE23* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL24* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS25* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT27* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY28* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF29* SUCH DAMAGE.30*31* $Id: ng_l2cap_var.h,v 1.2 2003/04/28 21:44:59 max Exp $32*/3334#ifndef _NETGRAPH_L2CAP_VAR_H_35#define _NETGRAPH_L2CAP_VAR_H_3637/* MALLOC decalation */38#ifdef NG_SEPARATE_MALLOC39MALLOC_DECLARE(M_NETGRAPH_L2CAP);40#else41#define M_NETGRAPH_L2CAP M_NETGRAPH42#endif /* NG_SEPARATE_MALLOC */4344/* Debug */45#define NG_L2CAP_ALERT if (l2cap->debug >= NG_L2CAP_ALERT_LEVEL) printf46#define NG_L2CAP_ERR if (l2cap->debug >= NG_L2CAP_ERR_LEVEL) printf47#define NG_L2CAP_WARN if (l2cap->debug >= NG_L2CAP_WARN_LEVEL) printf48#define NG_L2CAP_INFO if (l2cap->debug >= NG_L2CAP_INFO_LEVEL) printf4950/* Wrapper around m_pullup */51#define NG_L2CAP_M_PULLUP(m, s) \52do { \53if ((m)->m_len < (s)) \54(m) = m_pullup((m), (s)); \55if ((m) == NULL) \56NG_L2CAP_ALERT("%s: %s - m_pullup(%zd) failed\n", \57__func__, NG_NODE_NAME(l2cap->node), (s)); \58} while (0)5960/*61* L2CAP signaling command ident's are assigned relative to the connection,62* because there is only one signaling channel (cid == 0x01) for every63* connection. So up to 254 (0xff - 0x01) L2CAP commands can be pending at the64* same time for the same connection.65*/6667#define NG_L2CAP_NULL_IDENT 0x00 /* DO NOT USE THIS IDENT */68#define NG_L2CAP_FIRST_IDENT 0x01 /* dynamically alloc. (start) */69#define NG_L2CAP_LAST_IDENT 0xff /* dynamically alloc. (end) */7071/*72* L2CAP (Node private)73*/7475struct ng_l2cap_con;76struct ng_l2cap_chan;7778typedef struct ng_l2cap {79node_p node; /* node ptr */8081ng_l2cap_node_debug_ep debug; /* debug level */82ng_l2cap_node_flags_ep flags; /* L2CAP node flags */83ng_l2cap_node_auto_discon_ep discon_timo; /* auto discon. timeout */8485u_int16_t pkt_size; /* max. ACL packet size */86u_int16_t num_pkts; /* out queue size */87bdaddr_t bdaddr; /* unit BDADDR */8889hook_p hci; /* HCI downstream hook */90hook_p l2c; /* L2CAP upstream hook */91hook_p ctl; /* control hook */9293LIST_HEAD(, ng_l2cap_con) con_list; /* ACL connections */9495u_int16_t cid; /* last allocated CID */96u_int16_t lecid; /* last allocated CID for LE */9798LIST_HEAD(, ng_l2cap_chan) chan_list; /* L2CAP channels */99} ng_l2cap_t;100typedef ng_l2cap_t * ng_l2cap_p;101102/*103* L2CAP connection descriptor104*/105106struct ng_l2cap_cmd;107108typedef struct ng_l2cap_con {109ng_l2cap_p l2cap; /* pointer to L2CAP */110111u_int16_t state; /* ACL connection state */112u_int16_t flags; /* ACL connection flags */113114int32_t refcnt; /* reference count */115116bdaddr_t remote; /* remote unit address */117u_int16_t con_handle; /* ACL connection handle */118struct callout con_timo; /* connection timeout */119120u_int8_t ident; /* last allocated ident */121uint8_t linktype;122uint8_t encryption;123124TAILQ_HEAD(, ng_l2cap_cmd) cmd_list; /* pending L2CAP cmds */125126struct mbuf *tx_pkt; /* xmitted L2CAP packet */127int pending; /* num. of pending pkts */128129struct mbuf *rx_pkt; /* received L2CAP packet */130int rx_pkt_len; /* packet len. so far */131132LIST_ENTRY(ng_l2cap_con) next; /* link */133} ng_l2cap_con_t;134typedef ng_l2cap_con_t * ng_l2cap_con_p;135136/*137* L2CAP channel descriptor138*/139140typedef struct ng_l2cap_chan {141ng_l2cap_con_p con; /* pointer to connection */142143u_int16_t state; /* channel state */144145u_int8_t cfg_state; /* configuration state */146#define NG_L2CAP_CFG_IN (1 << 0) /* incoming cfg path done */147#define NG_L2CAP_CFG_OUT (1 << 1) /* outgoing cfg path done */148#define NG_L2CAP_CFG_BOTH (NG_L2CAP_CFG_IN|NG_L2CAP_CFG_OUT)149150u_int8_t ident; /* last L2CAP req. ident */151152u_int16_t psm; /* channel PSM */153u_int16_t scid; /* source channel ID */154u_int16_t dcid; /* destination channel ID */155156uint16_t idtype;157u_int16_t imtu; /* incoming channel MTU */158ng_l2cap_flow_t iflow; /* incoming flow control */159160u_int16_t omtu; /* outgoing channel MTU */161ng_l2cap_flow_t oflow; /* outgoing flow control */162163u_int16_t flush_timo; /* flush timeout */164u_int16_t link_timo; /* link timeout */165166LIST_ENTRY(ng_l2cap_chan) next; /* link */167} ng_l2cap_chan_t;168typedef ng_l2cap_chan_t * ng_l2cap_chan_p;169170/*171* L2CAP command descriptor172*/173174typedef struct ng_l2cap_cmd {175ng_l2cap_con_p con; /* L2CAP connection */176ng_l2cap_chan_p ch; /* L2CAP channel */177178u_int16_t flags; /* command flags */179#define NG_L2CAP_CMD_PENDING (1 << 0) /* command is pending */180181u_int8_t code; /* L2CAP command opcode */182u_int8_t ident; /* L2CAP command ident */183u_int32_t token; /* L2CA message token */184185struct callout timo; /* RTX/ERTX timeout */186187struct mbuf *aux; /* optional data */188189TAILQ_ENTRY(ng_l2cap_cmd) next; /* link */190} ng_l2cap_cmd_t;191typedef ng_l2cap_cmd_t * ng_l2cap_cmd_p;192193#endif /* ndef _NETGRAPH_L2CAP_VAR_H_ */194195196