xref: /dflybsd-src/sys/netgraph7/bluetooth/hci/ng_hci_var.h (revision a62226e46c982d037de05e1bb0894805c0b7a32f)
1b06ebda0SMatthew Dillon /*
2b06ebda0SMatthew Dillon  * ng_hci_var.h
3b06ebda0SMatthew Dillon  */
4b06ebda0SMatthew Dillon 
5b06ebda0SMatthew Dillon /*-
6b06ebda0SMatthew Dillon  * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7b06ebda0SMatthew Dillon  * All rights reserved.
8b06ebda0SMatthew Dillon  *
9b06ebda0SMatthew Dillon  * Redistribution and use in source and binary forms, with or without
10b06ebda0SMatthew Dillon  * modification, are permitted provided that the following conditions
11b06ebda0SMatthew Dillon  * are met:
12b06ebda0SMatthew Dillon  * 1. Redistributions of source code must retain the above copyright
13b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer.
14b06ebda0SMatthew Dillon  * 2. Redistributions in binary form must reproduce the above copyright
15b06ebda0SMatthew Dillon  *    notice, this list of conditions and the following disclaimer in the
16b06ebda0SMatthew Dillon  *    documentation and/or other materials provided with the distribution.
17b06ebda0SMatthew Dillon  *
18b06ebda0SMatthew Dillon  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19b06ebda0SMatthew Dillon  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20b06ebda0SMatthew Dillon  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21b06ebda0SMatthew Dillon  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22b06ebda0SMatthew Dillon  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23b06ebda0SMatthew Dillon  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24b06ebda0SMatthew Dillon  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25b06ebda0SMatthew Dillon  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26b06ebda0SMatthew Dillon  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27b06ebda0SMatthew Dillon  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28b06ebda0SMatthew Dillon  * SUCH DAMAGE.
29b06ebda0SMatthew Dillon  *
30b06ebda0SMatthew Dillon  * $Id: ng_hci_var.h,v 1.3 2003/04/26 22:35:21 max Exp $
31b06ebda0SMatthew Dillon  * $FreeBSD: src/sys/netgraph/bluetooth/hci/ng_hci_var.h,v 1.6 2005/01/07 01:45:43 imp Exp $
32b06ebda0SMatthew Dillon  */
33b06ebda0SMatthew Dillon 
34b06ebda0SMatthew Dillon #ifndef _NETGRAPH_HCI_VAR_H_
35b06ebda0SMatthew Dillon #define _NETGRAPH_HCI_VAR_H_
36b06ebda0SMatthew Dillon 
37b06ebda0SMatthew Dillon /* MALLOC decalation */
38b06ebda0SMatthew Dillon #ifdef NG_SEPARATE_MALLOC
39b06ebda0SMatthew Dillon MALLOC_DECLARE(M_NETGRAPH_HCI);
40b06ebda0SMatthew Dillon #else
41b06ebda0SMatthew Dillon #define M_NETGRAPH_HCI M_NETGRAPH
42b06ebda0SMatthew Dillon #endif /* NG_SEPARATE_MALLOC */
43b06ebda0SMatthew Dillon 
44b06ebda0SMatthew Dillon /* Debug */
45*a62226e4SSascha Wildner #define	NG_HCI_ALERT	if (unit->debug >= NG_HCI_ALERT_LEVEL) kprintf
46*a62226e4SSascha Wildner #define	NG_HCI_ERR	if (unit->debug >= NG_HCI_ERR_LEVEL)   kprintf
47*a62226e4SSascha Wildner #define	NG_HCI_WARN	if (unit->debug >= NG_HCI_WARN_LEVEL)  kprintf
48*a62226e4SSascha Wildner #define	NG_HCI_INFO	if (unit->debug >= NG_HCI_INFO_LEVEL)  kprintf
49b06ebda0SMatthew Dillon 
50b06ebda0SMatthew Dillon /* Wrapper around m_pullup */
51b06ebda0SMatthew Dillon #define NG_HCI_M_PULLUP(m, s) 				\
52b06ebda0SMatthew Dillon 	do { 						\
53b06ebda0SMatthew Dillon 		if ((m)->m_len < (s)) 			\
54b06ebda0SMatthew Dillon 			(m) = m_pullup((m), (s)); 	\
55b06ebda0SMatthew Dillon 		if ((m) == NULL) 			\
56b06ebda0SMatthew Dillon 			NG_HCI_ALERT("%s: %s - m_pullup(%zd) failed\n", \
57b06ebda0SMatthew Dillon 				__func__, NG_NODE_NAME(unit->node), (s)); \
58b06ebda0SMatthew Dillon 	} while (0)
59b06ebda0SMatthew Dillon 
60b06ebda0SMatthew Dillon /*
61b06ebda0SMatthew Dillon  * Unit hardware buffer descriptor
62b06ebda0SMatthew Dillon  */
63b06ebda0SMatthew Dillon 
64b06ebda0SMatthew Dillon typedef struct ng_hci_unit_buff {
65b06ebda0SMatthew Dillon 	u_int8_t			cmd_free; /* space available (cmds) */
66b06ebda0SMatthew Dillon 
67b06ebda0SMatthew Dillon 	u_int8_t			sco_size; /* max. size of one packet */
68b06ebda0SMatthew Dillon 	u_int16_t			sco_pkts; /* size of buffer (packets) */
69b06ebda0SMatthew Dillon 	u_int16_t			sco_free; /* space available (packets)*/
70b06ebda0SMatthew Dillon 
71b06ebda0SMatthew Dillon 	u_int16_t			acl_size; /* max. size of one packet */
72b06ebda0SMatthew Dillon 	u_int16_t			acl_pkts; /* size of buffer (packets) */
73b06ebda0SMatthew Dillon 	u_int16_t			acl_free; /* space available (packets)*/
74b06ebda0SMatthew Dillon } ng_hci_unit_buff_t;
75b06ebda0SMatthew Dillon 
76b06ebda0SMatthew Dillon /*
77b06ebda0SMatthew Dillon  * These macro's must be used everywhere in the code. So if extra locking
78b06ebda0SMatthew Dillon  * is required later, it can be added without much troubles.
79b06ebda0SMatthew Dillon  */
80b06ebda0SMatthew Dillon 
81b06ebda0SMatthew Dillon #define NG_HCI_BUFF_CMD_SET(b, v)	(b).cmd_free = (v)
82b06ebda0SMatthew Dillon #define NG_HCI_BUFF_CMD_GET(b, v)	(v) = (b).cmd_free
83b06ebda0SMatthew Dillon #define NG_HCI_BUFF_CMD_USE(b, v)	(b).cmd_free -= (v)
84b06ebda0SMatthew Dillon 
85b06ebda0SMatthew Dillon #define NG_HCI_BUFF_ACL_USE(b, v)	(b).acl_free -= (v)
86b06ebda0SMatthew Dillon #define NG_HCI_BUFF_ACL_FREE(b, v) 			\
87b06ebda0SMatthew Dillon 	do { 						\
88b06ebda0SMatthew Dillon 		(b).acl_free += (v);			\
89b06ebda0SMatthew Dillon 		if ((b).acl_free > (b).acl_pkts) 	\
90b06ebda0SMatthew Dillon 			(b).acl_free = (b).acl_pkts; 	\
91b06ebda0SMatthew Dillon 	} while (0)
92b06ebda0SMatthew Dillon #define NG_HCI_BUFF_ACL_AVAIL(b, v)	(v) = (b).acl_free
93b06ebda0SMatthew Dillon #define NG_HCI_BUFF_ACL_TOTAL(b, v)	(v) = (b).acl_pkts
94b06ebda0SMatthew Dillon #define NG_HCI_BUFF_ACL_SIZE(b, v)	(v) = (b).acl_size
95b06ebda0SMatthew Dillon #define NG_HCI_BUFF_ACL_SET(b, n, s, f) 		\
96b06ebda0SMatthew Dillon 	do { 						\
97b06ebda0SMatthew Dillon 		(b).acl_free = (f); 			\
98b06ebda0SMatthew Dillon 		(b).acl_size = (s); 			\
99b06ebda0SMatthew Dillon 		(b).acl_pkts = (n); 			\
100b06ebda0SMatthew Dillon 	} while (0)
101b06ebda0SMatthew Dillon 
102b06ebda0SMatthew Dillon #define NG_HCI_BUFF_SCO_USE(b, v)	(b).sco_free -= (v)
103b06ebda0SMatthew Dillon #define NG_HCI_BUFF_SCO_FREE(b, v) 			\
104b06ebda0SMatthew Dillon 	do { 						\
105b06ebda0SMatthew Dillon 		(b).sco_free += (v); 			\
106b06ebda0SMatthew Dillon 		if ((b).sco_free > (b).sco_pkts) 	\
107b06ebda0SMatthew Dillon 			(b).sco_free = (b).sco_pkts; 	\
108b06ebda0SMatthew Dillon 	} while (0)
109b06ebda0SMatthew Dillon #define NG_HCI_BUFF_SCO_AVAIL(b, v)	(v) = (b).sco_free
110b06ebda0SMatthew Dillon #define NG_HCI_BUFF_SCO_TOTAL(b, v)	(v) = (b).sco_pkts
111b06ebda0SMatthew Dillon #define NG_HCI_BUFF_SCO_SIZE(b, v)	(v) = (b).sco_size
112b06ebda0SMatthew Dillon #define NG_HCI_BUFF_SCO_SET(b, n, s, f) 		\
113b06ebda0SMatthew Dillon 	do { 						\
114b06ebda0SMatthew Dillon 		(b).sco_free = (f); 			\
115b06ebda0SMatthew Dillon 		(b).sco_size = (s); 			\
116b06ebda0SMatthew Dillon 		(b).sco_pkts = (n); 			\
117b06ebda0SMatthew Dillon 	} while (0)
118b06ebda0SMatthew Dillon 
119b06ebda0SMatthew Dillon /*
120b06ebda0SMatthew Dillon  * Unit (Node private)
121b06ebda0SMatthew Dillon  */
122b06ebda0SMatthew Dillon 
123b06ebda0SMatthew Dillon struct ng_hci_unit_con;
124b06ebda0SMatthew Dillon struct ng_hci_neighbor;
125b06ebda0SMatthew Dillon 
126b06ebda0SMatthew Dillon typedef struct ng_hci_unit {
127b06ebda0SMatthew Dillon 	node_p				node;           /* node ptr */
128b06ebda0SMatthew Dillon 
129b06ebda0SMatthew Dillon 	ng_hci_node_debug_ep		debug;          /* debug level */
130b06ebda0SMatthew Dillon 	ng_hci_node_state_ep		state;          /* unit state */
131b06ebda0SMatthew Dillon 
132b06ebda0SMatthew Dillon 	bdaddr_t			bdaddr;         /* unit address */
133b06ebda0SMatthew Dillon 	u_int8_t			features[NG_HCI_FEATURES_SIZE];
134b06ebda0SMatthew Dillon 					                /* LMP features */
135b06ebda0SMatthew Dillon 
136b06ebda0SMatthew Dillon 	ng_hci_node_link_policy_mask_ep	link_policy_mask; /* link policy mask */
137b06ebda0SMatthew Dillon 	ng_hci_node_packet_mask_ep	packet_mask;	/* packet mask */
138b06ebda0SMatthew Dillon 	ng_hci_node_role_switch_ep	role_switch;	/* role switch */
139b06ebda0SMatthew Dillon 
140b06ebda0SMatthew Dillon 	ng_hci_node_stat_ep		stat;           /* statistic */
141b06ebda0SMatthew Dillon #define NG_HCI_STAT_CMD_SENT(s)		(s).cmd_sent ++
142b06ebda0SMatthew Dillon #define NG_HCI_STAT_EVNT_RECV(s)	(s).evnt_recv ++
143b06ebda0SMatthew Dillon #define NG_HCI_STAT_ACL_SENT(s, n)	(s).acl_sent += (n)
144b06ebda0SMatthew Dillon #define NG_HCI_STAT_ACL_RECV(s)		(s).acl_recv ++
145b06ebda0SMatthew Dillon #define NG_HCI_STAT_SCO_SENT(s, n)	(s).sco_sent += (n)
146b06ebda0SMatthew Dillon #define NG_HCI_STAT_SCO_RECV(s)		(s).sco_recv ++
147b06ebda0SMatthew Dillon #define NG_HCI_STAT_BYTES_SENT(s, b)	(s).bytes_sent += (b)
148b06ebda0SMatthew Dillon #define NG_HCI_STAT_BYTES_RECV(s, b)	(s).bytes_recv += (b)
149b06ebda0SMatthew Dillon #define NG_HCI_STAT_RESET(s)		bzero(&(s), sizeof((s)))
150b06ebda0SMatthew Dillon 
151b06ebda0SMatthew Dillon 	ng_hci_unit_buff_t		buffer;         /* buffer info */
152b06ebda0SMatthew Dillon 
153b06ebda0SMatthew Dillon 	struct callout			cmd_timo;       /* command timeout */
154b06ebda0SMatthew Dillon 	ng_bt_mbufq_t			cmdq;           /* command queue */
155b06ebda0SMatthew Dillon #define NG_HCI_CMD_QUEUE_LEN		12		/* max. size of cmd q */
156b06ebda0SMatthew Dillon 
157b06ebda0SMatthew Dillon 	hook_p				drv;            /* driver hook */
158b06ebda0SMatthew Dillon 	hook_p				acl;            /* upstream hook */
159b06ebda0SMatthew Dillon 	hook_p				sco;            /* upstream hook */
160b06ebda0SMatthew Dillon 	hook_p				raw;            /* upstream hook */
161b06ebda0SMatthew Dillon 
162b06ebda0SMatthew Dillon 	LIST_HEAD(, ng_hci_unit_con)	con_list;       /* connections */
163b06ebda0SMatthew Dillon 	LIST_HEAD(, ng_hci_neighbor)	neighbors;      /* unit neighbors */
164b06ebda0SMatthew Dillon } ng_hci_unit_t;
165b06ebda0SMatthew Dillon typedef ng_hci_unit_t *			ng_hci_unit_p;
166b06ebda0SMatthew Dillon 
167b06ebda0SMatthew Dillon /*
168b06ebda0SMatthew Dillon  * Unit connection descriptor
169b06ebda0SMatthew Dillon  */
170b06ebda0SMatthew Dillon 
171b06ebda0SMatthew Dillon typedef struct ng_hci_unit_con {
172b06ebda0SMatthew Dillon 	ng_hci_unit_p			unit;            /* pointer back */
173b06ebda0SMatthew Dillon 
174b06ebda0SMatthew Dillon 	u_int16_t			state;           /* con. state */
175b06ebda0SMatthew Dillon 	u_int16_t			flags;           /* con. flags */
176b06ebda0SMatthew Dillon #define NG_HCI_CON_TIMEOUT_PENDING		(1 << 0)
177b06ebda0SMatthew Dillon #define NG_HCI_CON_NOTIFY_ACL			(1 << 1)
178b06ebda0SMatthew Dillon #define NG_HCI_CON_NOTIFY_SCO			(1 << 2)
179b06ebda0SMatthew Dillon 
180b06ebda0SMatthew Dillon 	bdaddr_t			bdaddr;          /* remote address */
181b06ebda0SMatthew Dillon 	u_int16_t			con_handle;      /* con. handle */
182b06ebda0SMatthew Dillon 
183b06ebda0SMatthew Dillon 	u_int8_t			link_type;       /* ACL or SCO */
184b06ebda0SMatthew Dillon 	u_int8_t			encryption_mode; /* none, p2p, ... */
185b06ebda0SMatthew Dillon 	u_int8_t			mode;            /* ACTIVE, HOLD ... */
186b06ebda0SMatthew Dillon 	u_int8_t			role;            /* MASTER/SLAVE */
187b06ebda0SMatthew Dillon 
188b06ebda0SMatthew Dillon 	struct callout			con_timo;        /* con. timeout */
189b06ebda0SMatthew Dillon 
190b06ebda0SMatthew Dillon 	int				pending;         /* # of data pkts */
191b06ebda0SMatthew Dillon 	ng_bt_itemq_t			conq;            /* con. queue */
192b06ebda0SMatthew Dillon 
193b06ebda0SMatthew Dillon 	LIST_ENTRY(ng_hci_unit_con)	next;            /* next */
194b06ebda0SMatthew Dillon } ng_hci_unit_con_t;
195b06ebda0SMatthew Dillon typedef ng_hci_unit_con_t *		ng_hci_unit_con_p;
196b06ebda0SMatthew Dillon 
197b06ebda0SMatthew Dillon /*
198b06ebda0SMatthew Dillon  * Unit's neighbor descriptor.
199b06ebda0SMatthew Dillon  * Neighbor is a remote unit that responded to our inquiry.
200b06ebda0SMatthew Dillon  */
201b06ebda0SMatthew Dillon 
202b06ebda0SMatthew Dillon typedef struct ng_hci_neighbor {
203b06ebda0SMatthew Dillon 	struct timeval			updated;	/* entry was updated */
204b06ebda0SMatthew Dillon 
205b06ebda0SMatthew Dillon 	bdaddr_t			bdaddr;         /* address */
206b06ebda0SMatthew Dillon 	u_int8_t			features[NG_HCI_FEATURES_SIZE];
207b06ebda0SMatthew Dillon 					                /* LMP features */
208b06ebda0SMatthew Dillon 
209b06ebda0SMatthew Dillon 	u_int8_t			page_scan_rep_mode; /* PS rep. mode */
210b06ebda0SMatthew Dillon 	u_int8_t			page_scan_mode; /* page scan mode */
211b06ebda0SMatthew Dillon 	u_int16_t			clock_offset;   /* clock offset */
212b06ebda0SMatthew Dillon 
213b06ebda0SMatthew Dillon 	LIST_ENTRY(ng_hci_neighbor)	next;
214b06ebda0SMatthew Dillon } ng_hci_neighbor_t;
215b06ebda0SMatthew Dillon typedef ng_hci_neighbor_t *		ng_hci_neighbor_p;
216b06ebda0SMatthew Dillon 
217b06ebda0SMatthew Dillon #endif /* ndef _NETGRAPH_HCI_VAR_H_ */
218b06ebda0SMatthew Dillon 
219