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