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