summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/bluetooth/hci/ng_hci_var.h
blob: 43940a93b5994c9dd5e04b746b08c7bfe18aa8bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
 * ng_hci_var.h
 *
 * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: ng_hci_var.h,v 1.14 2002/11/12 22:35:40 max Exp $
 * $FreeBSD$
 */

#ifndef _NETGRAPH_HCI_VAR_H_
#define _NETGRAPH_HCI_VAR_H_ 1

/* MALLOC decalation */
#ifdef NG_SEPARATE_MALLOC
MALLOC_DECLARE(M_NETGRAPH_HCI);
#else
#define M_NETGRAPH_HCI M_NETGRAPH
#endif /* NG_SEPARATE_MALLOC */

/* Debug */
#define	NG_HCI_ALERT	if (unit->debug >= NG_HCI_ALERT_LEVEL) printf
#define	NG_HCI_ERR	if (unit->debug >= NG_HCI_ERR_LEVEL)   printf
#define	NG_HCI_WARN	if (unit->debug >= NG_HCI_WARN_LEVEL)  printf
#define	NG_HCI_INFO	if (unit->debug >= NG_HCI_INFO_LEVEL)  printf

/* Wrapper around m_pullup */
#define NG_HCI_M_PULLUP(m, s) 				\
	do { 						\
		if ((m)->m_len < (s)) 			\
			(m) = m_pullup((m), (s)); 	\
		if ((m) == NULL) 			\
			NG_HCI_ALERT("%s: %s - m_pullup(%d) failed\n", \
				__func__, NG_NODE_NAME(unit->node), (s)); \
	} while (0)

/*
 * Unit hardware buffer descriptor 
 */

typedef struct ng_hci_unit_buff {
	u_int8_t			cmd_free; /* space available (cmds) */

	u_int8_t			sco_size; /* max. size of one packet */
	u_int16_t			sco_pkts; /* size of buffer (packets) */
	u_int16_t			sco_free; /* space available (packets)*/

	u_int16_t			acl_size; /* max. size of one packet */
	u_int16_t			acl_pkts; /* size of buffer (packets) */
	u_int16_t			acl_free; /* space available (packets)*/
} ng_hci_unit_buff_t;

/* 
 * These macro's must be used everywhere in the code. So if extra locking 
 * is required later, it can be added without much troubles.
 */

#define NG_HCI_BUFF_CMD_SET(b, v)	(b).cmd_free = (v)
#define NG_HCI_BUFF_CMD_GET(b, v)	(v) = (b).cmd_free
#define NG_HCI_BUFF_CMD_USE(b, v)	(b).cmd_free -= (v)

#define NG_HCI_BUFF_ACL_USE(b, v)	(b).acl_free -= (v)
#define NG_HCI_BUFF_ACL_FREE(b, v) 			\
	do { 						\
		(b).acl_free += (v);			\
		if ((b).acl_free > (b).acl_pkts) 	\
			(b).acl_free = (b).acl_pkts; 	\
	} while (0)
#define NG_HCI_BUFF_ACL_AVAIL(b, v)	(v) = (b).acl_free
#define NG_HCI_BUFF_ACL_TOTAL(b, v)	(v) = (b).acl_pkts
#define NG_HCI_BUFF_ACL_SIZE(b, v)	(v) = (b).acl_size
#define NG_HCI_BUFF_ACL_SET(b, n, s, f) 		\
	do { 						\
		(b).acl_free = (f); 			\
		(b).acl_size = (s); 			\
		(b).acl_pkts = (n); 			\
	} while (0)

#define NG_HCI_BUFF_SCO_USE(b, v)	(b).sco_free -= (v)
#define NG_HCI_BUFF_SCO_FREE(b, v) 			\
	do { 						\
		(b).sco_free += (v); 			\
		if ((b).sco_free > (b).sco_pkts) 	\
			(b).sco_free = (b).sco_pkts; 	\
	} while (0)
#define NG_HCI_BUFF_SCO_AVAIL(b, v)	(v) = (b).sco_free
#define NG_HCI_BUFF_SCO_TOTAL(b, v)	(v) = (b).sco_pkts
#define NG_HCI_BUFF_SCO_SIZE(b, v)	(v) = (b).sco_size
#define NG_HCI_BUFF_SCO_SET(b, n, s, f) 		\
	do { 						\
		(b).sco_free = (f); 			\
		(b).sco_size = (s); 			\
		(b).sco_pkts = (n); 			\
	} while (0)

/* 
 * Unit (Node private)
 */

struct ng_hci_unit_con;
struct ng_hci_neighbor;

typedef struct ng_hci_unit {
	node_p				node;           /* node ptr */

	ng_hci_node_debug_ep		debug;          /* debug level */
	ng_hci_node_state_ep		state;          /* unit state */

	bdaddr_t			bdaddr;         /* unit address */
	u_int8_t			features[NG_HCI_FEATURES_SIZE];
					                /* LMP features */

	ng_hci_node_link_policy_mask_ep	link_policy_mask; /* link policy mask */
	ng_hci_node_packet_mask_ep	packet_mask;	/* packet mask */

	ng_hci_node_stat_ep		stat;           /* statistic */
#define NG_HCI_STAT_CMD_SENT(s)		(s).cmd_sent ++
#define NG_HCI_STAT_EVNT_RECV(s)	(s).evnt_recv ++
#define NG_HCI_STAT_ACL_SENT(s, n)	(s).acl_sent += (n)
#define NG_HCI_STAT_ACL_RECV(s)		(s).acl_recv ++
#define NG_HCI_STAT_SCO_SENT(s, n)	(s).sco_sent += (n)
#define NG_HCI_STAT_SCO_RECV(s)		(s).sco_recv ++
#define NG_HCI_STAT_BYTES_SENT(s, b)	(s).bytes_sent += (b)
#define NG_HCI_STAT_BYTES_RECV(s, b)	(s).bytes_recv += (b)
#define NG_HCI_STAT_RESET(s)		bzero(&(s), sizeof((s)))

	ng_hci_unit_buff_t		buffer;         /* buffer info */

	struct callout_handle		cmd_timo;       /* command timeout */
	ng_bt_mbufq_t			cmdq;           /* command queue */
#define NG_HCI_CMD_QUEUE_LEN		12		/* max. size of cmd q */

	hook_p				drv;            /* driver hook */
	hook_p				acl;            /* upstream hook */
	hook_p				sco;            /* upstream hook */
	hook_p				raw;            /* upstream hook */

	LIST_HEAD(, ng_hci_unit_con)	con_list;       /* connections */
	LIST_HEAD(, ng_hci_neighbor)	neighbors;      /* unit neighbors */
} ng_hci_unit_t;
typedef ng_hci_unit_t *			ng_hci_unit_p;

/* 
 * Unit connection descriptor
 */

typedef struct ng_hci_unit_con {
	ng_hci_unit_p			unit;            /* pointer back */

	u_int16_t			state;           /* con. state */
	u_int16_t			flags;           /* con. flags */
#define NG_HCI_CON_TIMEOUT_PENDING		(1 << 0)
#define NG_HCI_CON_WATCHDOG_TIMEOUT_PENDING	(1 << 1)
#define NG_HCI_CON_NOTIFY_ACL			(1 << 2)
#define NG_HCI_CON_NOTIFY_SCO			(1 << 3)

	bdaddr_t			bdaddr;          /* remote address */
	u_int16_t			con_handle;      /* con. handle */

	u_int8_t			link_type;       /* ACL or SCO */
	u_int8_t			encryption_mode; /* none, p2p, ... */
	u_int8_t			mode;            /* ACTIVE, HOLD ... */
	u_int8_t			role;            /* MASTER/SLAVE */

	struct callout_handle		con_timo;        /* con. timeout */
	struct callout_handle		watchdog_timo;   /* watch dog */

	int				pending;         /* # of data pkts */
	ng_bt_itemq_t			conq;            /* con. queue */

	LIST_ENTRY(ng_hci_unit_con)	next;            /* next */
} ng_hci_unit_con_t;
typedef ng_hci_unit_con_t *		ng_hci_unit_con_p;

/*
 * Unit's neighbor descriptor. 
 * Neighbor is a remote unit that responded to our inquiry.
 */

typedef struct ng_hci_neighbor {
	struct timeval			updated;	/* entry was updated */

	bdaddr_t			bdaddr;         /* address */
	u_int8_t			features[NG_HCI_FEATURES_SIZE];
					                /* LMP features */

	u_int8_t			page_scan_rep_mode; /* PS rep. mode */
	u_int8_t			page_scan_mode; /* page scan mode */
	u_int16_t			clock_offset;   /* clock offset */

	LIST_ENTRY(ng_hci_neighbor)	next;
} ng_hci_neighbor_t;
typedef ng_hci_neighbor_t *		ng_hci_neighbor_p;
       
#endif /* ndef _NETGRAPH_HCI_VAR_H_ */

OpenPOWER on IntegriCloud