bthidev.c revision 1.1.8.2 1 1.1.8.2 gdamore /* $NetBSD: bthidev.c,v 1.1.8.2 2006/07/13 17:49:22 gdamore Exp $ */
2 1.1.8.2 gdamore
3 1.1.8.2 gdamore /*-
4 1.1.8.2 gdamore * Copyright (c) 2006 Itronix Inc.
5 1.1.8.2 gdamore * All rights reserved.
6 1.1.8.2 gdamore *
7 1.1.8.2 gdamore * Written by Iain Hibbert for Itronix Inc.
8 1.1.8.2 gdamore *
9 1.1.8.2 gdamore * Redistribution and use in source and binary forms, with or without
10 1.1.8.2 gdamore * modification, are permitted provided that the following conditions
11 1.1.8.2 gdamore * are met:
12 1.1.8.2 gdamore * 1. Redistributions of source code must retain the above copyright
13 1.1.8.2 gdamore * notice, this list of conditions and the following disclaimer.
14 1.1.8.2 gdamore * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.8.2 gdamore * notice, this list of conditions and the following disclaimer in the
16 1.1.8.2 gdamore * documentation and/or other materials provided with the distribution.
17 1.1.8.2 gdamore * 3. The name of Itronix Inc. may not be used to endorse
18 1.1.8.2 gdamore * or promote products derived from this software without specific
19 1.1.8.2 gdamore * prior written permission.
20 1.1.8.2 gdamore *
21 1.1.8.2 gdamore * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
22 1.1.8.2 gdamore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 1.1.8.2 gdamore * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 1.1.8.2 gdamore * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 1.1.8.2 gdamore * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 1.1.8.2 gdamore * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 1.1.8.2 gdamore * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 1.1.8.2 gdamore * ON ANY THEORY OF LIABILITY, WHETHER IN
29 1.1.8.2 gdamore * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 1.1.8.2 gdamore * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 1.1.8.2 gdamore * POSSIBILITY OF SUCH DAMAGE.
32 1.1.8.2 gdamore */
33 1.1.8.2 gdamore
34 1.1.8.2 gdamore #include <sys/cdefs.h>
35 1.1.8.2 gdamore __KERNEL_RCSID(0, "$NetBSD: bthidev.c,v 1.1.8.2 2006/07/13 17:49:22 gdamore Exp $");
36 1.1.8.2 gdamore
37 1.1.8.2 gdamore #include <sys/param.h>
38 1.1.8.2 gdamore #include <sys/conf.h>
39 1.1.8.2 gdamore #include <sys/device.h>
40 1.1.8.2 gdamore #include <sys/fcntl.h>
41 1.1.8.2 gdamore #include <sys/kernel.h>
42 1.1.8.2 gdamore #include <sys/queue.h>
43 1.1.8.2 gdamore #include <sys/malloc.h>
44 1.1.8.2 gdamore #include <sys/mbuf.h>
45 1.1.8.2 gdamore #include <sys/proc.h>
46 1.1.8.2 gdamore #include <sys/systm.h>
47 1.1.8.2 gdamore
48 1.1.8.2 gdamore #include <netbt/bluetooth.h>
49 1.1.8.2 gdamore #include <netbt/l2cap.h>
50 1.1.8.2 gdamore
51 1.1.8.2 gdamore #include <dev/usb/hid.h>
52 1.1.8.2 gdamore #include <dev/bluetooth/btdev.h>
53 1.1.8.2 gdamore #include <dev/bluetooth/bthid.h>
54 1.1.8.2 gdamore #include <dev/bluetooth/bthidev.h>
55 1.1.8.2 gdamore
56 1.1.8.2 gdamore #include "locators.h"
57 1.1.8.2 gdamore
58 1.1.8.2 gdamore /*****************************************************************************
59 1.1.8.2 gdamore *
60 1.1.8.2 gdamore * Bluetooth HID device
61 1.1.8.2 gdamore */
62 1.1.8.2 gdamore
63 1.1.8.2 gdamore MALLOC_DEFINE(M_BTHIDEV, "bthidev", "Bluetooth HID Memory");
64 1.1.8.2 gdamore
65 1.1.8.2 gdamore #define MAX_DESCRIPTOR_LEN 1024 /* sanity check */
66 1.1.8.2 gdamore
67 1.1.8.2 gdamore /* bthidev softc */
68 1.1.8.2 gdamore struct bthidev_softc {
69 1.1.8.2 gdamore struct btdev sc_btdev; /* device+ */
70 1.1.8.2 gdamore uint16_t sc_state;
71 1.1.8.2 gdamore uint16_t sc_flags;
72 1.1.8.2 gdamore
73 1.1.8.2 gdamore bdaddr_t sc_laddr; /* local address */
74 1.1.8.2 gdamore bdaddr_t sc_raddr; /* remote address */
75 1.1.8.2 gdamore
76 1.1.8.2 gdamore void *sc_desc; /* HID descriptor */
77 1.1.8.2 gdamore int sc_dlen; /* descriptor length */
78 1.1.8.2 gdamore
79 1.1.8.2 gdamore uint16_t sc_ctlpsm; /* control PSM */
80 1.1.8.2 gdamore struct l2cap_channel *sc_ctl; /* control channel */
81 1.1.8.2 gdamore struct l2cap_channel *sc_ctl_l; /* control listen */
82 1.1.8.2 gdamore
83 1.1.8.2 gdamore uint16_t sc_intpsm; /* interrupt PSM */
84 1.1.8.2 gdamore struct l2cap_channel *sc_int; /* interrupt channel */
85 1.1.8.2 gdamore struct l2cap_channel *sc_int_l; /* interrupt listen */
86 1.1.8.2 gdamore
87 1.1.8.2 gdamore LIST_HEAD(,bthidev) sc_list; /* child list */
88 1.1.8.2 gdamore
89 1.1.8.2 gdamore struct callout sc_reconnect;
90 1.1.8.2 gdamore int sc_attempts; /* connection attempts */
91 1.1.8.2 gdamore };
92 1.1.8.2 gdamore
93 1.1.8.2 gdamore /* device state */
94 1.1.8.2 gdamore #define BTHID_CLOSED 0
95 1.1.8.2 gdamore #define BTHID_WAIT_CTL 1
96 1.1.8.2 gdamore #define BTHID_WAIT_INT 2
97 1.1.8.2 gdamore #define BTHID_OPEN 3
98 1.1.8.2 gdamore #define BTHID_DETACHING 4
99 1.1.8.2 gdamore
100 1.1.8.2 gdamore #define BTHID_RETRY_INTERVAL 5 /* seconds between connection attempts */
101 1.1.8.2 gdamore
102 1.1.8.2 gdamore /* bthidev internals */
103 1.1.8.2 gdamore static void bthidev_timeout(void *);
104 1.1.8.2 gdamore static int bthidev_listen(struct bthidev_softc *);
105 1.1.8.2 gdamore static int bthidev_connect(struct bthidev_softc *);
106 1.1.8.2 gdamore static int bthidev_output(struct bthidev *, uint8_t *, int);
107 1.1.8.2 gdamore static void bthidev_null(struct bthidev *, uint8_t *, int);
108 1.1.8.2 gdamore
109 1.1.8.2 gdamore /* autoconf(9) glue */
110 1.1.8.2 gdamore static int bthidev_match(struct device *, struct cfdata *, void *);
111 1.1.8.2 gdamore static void bthidev_attach(struct device *, struct device *, void *);
112 1.1.8.2 gdamore static int bthidev_detach(struct device *, int);
113 1.1.8.2 gdamore static int bthidev_print(void *, const char *);
114 1.1.8.2 gdamore
115 1.1.8.2 gdamore CFATTACH_DECL(bthidev, sizeof(struct bthidev_softc),
116 1.1.8.2 gdamore bthidev_match, bthidev_attach, bthidev_detach, NULL);
117 1.1.8.2 gdamore
118 1.1.8.2 gdamore /* bluetooth(9) protocol methods for L2CAP */
119 1.1.8.2 gdamore static void bthidev_connecting(void *);
120 1.1.8.2 gdamore static void bthidev_ctl_connected(void *);
121 1.1.8.2 gdamore static void bthidev_int_connected(void *);
122 1.1.8.2 gdamore static void bthidev_ctl_disconnected(void *, int);
123 1.1.8.2 gdamore static void bthidev_int_disconnected(void *, int);
124 1.1.8.2 gdamore static void *bthidev_ctl_newconn(void *, struct sockaddr_bt *, struct sockaddr_bt *);
125 1.1.8.2 gdamore static void *bthidev_int_newconn(void *, struct sockaddr_bt *, struct sockaddr_bt *);
126 1.1.8.2 gdamore static void bthidev_complete(void *, int);
127 1.1.8.2 gdamore static void bthidev_input(void *, struct mbuf *);
128 1.1.8.2 gdamore
129 1.1.8.2 gdamore static const struct btproto bthidev_ctl_proto = {
130 1.1.8.2 gdamore bthidev_connecting,
131 1.1.8.2 gdamore bthidev_ctl_connected,
132 1.1.8.2 gdamore bthidev_ctl_disconnected,
133 1.1.8.2 gdamore bthidev_ctl_newconn,
134 1.1.8.2 gdamore bthidev_complete,
135 1.1.8.2 gdamore bthidev_input,
136 1.1.8.2 gdamore };
137 1.1.8.2 gdamore
138 1.1.8.2 gdamore static const struct btproto bthidev_int_proto = {
139 1.1.8.2 gdamore bthidev_connecting,
140 1.1.8.2 gdamore bthidev_int_connected,
141 1.1.8.2 gdamore bthidev_int_disconnected,
142 1.1.8.2 gdamore bthidev_int_newconn,
143 1.1.8.2 gdamore bthidev_complete,
144 1.1.8.2 gdamore bthidev_input,
145 1.1.8.2 gdamore };
146 1.1.8.2 gdamore
147 1.1.8.2 gdamore /*****************************************************************************
148 1.1.8.2 gdamore *
149 1.1.8.2 gdamore * bthidev autoconf(9) routines
150 1.1.8.2 gdamore */
151 1.1.8.2 gdamore
152 1.1.8.2 gdamore static int
153 1.1.8.2 gdamore bthidev_match(struct device *self, struct cfdata *cfdata, void *aux)
154 1.1.8.2 gdamore {
155 1.1.8.2 gdamore struct btdev_attach_args *bda = (struct btdev_attach_args *)aux;
156 1.1.8.2 gdamore
157 1.1.8.2 gdamore if (bda->bd_type != BTDEV_HID
158 1.1.8.2 gdamore || L2CAP_PSM_INVALID(bda->bd_hid.hid_ctl)
159 1.1.8.2 gdamore || L2CAP_PSM_INVALID(bda->bd_hid.hid_int)
160 1.1.8.2 gdamore || bda->bd_hid.hid_desc == NULL
161 1.1.8.2 gdamore || bda->bd_hid.hid_dlen == 0
162 1.1.8.2 gdamore || bda->bd_hid.hid_dlen > MAX_DESCRIPTOR_LEN)
163 1.1.8.2 gdamore return 0;
164 1.1.8.2 gdamore
165 1.1.8.2 gdamore return 1;
166 1.1.8.2 gdamore }
167 1.1.8.2 gdamore
168 1.1.8.2 gdamore static void
169 1.1.8.2 gdamore bthidev_attach(struct device *parent, struct device *self, void *aux)
170 1.1.8.2 gdamore {
171 1.1.8.2 gdamore struct bthidev_softc *sc = (struct bthidev_softc *)self;
172 1.1.8.2 gdamore struct btdev_attach_args *bda = (struct btdev_attach_args *)aux;
173 1.1.8.2 gdamore struct bthidev_attach_args bha;
174 1.1.8.2 gdamore struct bthidev *dev;
175 1.1.8.2 gdamore struct hid_data *d;
176 1.1.8.2 gdamore struct hid_item h;
177 1.1.8.2 gdamore int locs[BTHIDBUSCF_NLOCS];
178 1.1.8.2 gdamore int maxid, rep, s;
179 1.1.8.2 gdamore
180 1.1.8.2 gdamore /*
181 1.1.8.2 gdamore * Init softc
182 1.1.8.2 gdamore */
183 1.1.8.2 gdamore LIST_INIT(&sc->sc_list);
184 1.1.8.2 gdamore callout_init(&sc->sc_reconnect);
185 1.1.8.2 gdamore callout_setfunc(&sc->sc_reconnect, bthidev_timeout, sc);
186 1.1.8.2 gdamore sc->sc_state = BTHID_CLOSED;
187 1.1.8.2 gdamore
188 1.1.8.2 gdamore /*
189 1.1.8.2 gdamore * copy in our configuration info
190 1.1.8.2 gdamore */
191 1.1.8.2 gdamore bdaddr_copy(&sc->sc_laddr, &bda->bd_laddr);
192 1.1.8.2 gdamore bdaddr_copy(&sc->sc_raddr, &bda->bd_raddr);
193 1.1.8.2 gdamore
194 1.1.8.2 gdamore sc->sc_ctlpsm = bda->bd_hid.hid_ctl;
195 1.1.8.2 gdamore sc->sc_intpsm = bda->bd_hid.hid_int;
196 1.1.8.2 gdamore
197 1.1.8.2 gdamore sc->sc_flags = bda->bd_hid.hid_flags;
198 1.1.8.2 gdamore if (sc->sc_flags & BTHID_INITIATE)
199 1.1.8.2 gdamore sc->sc_flags |= BTHID_CONNECT;
200 1.1.8.2 gdamore
201 1.1.8.2 gdamore sc->sc_dlen = bda->bd_hid.hid_dlen;
202 1.1.8.2 gdamore sc->sc_desc = malloc(bda->bd_hid.hid_dlen, M_BTHIDEV, M_WAITOK);
203 1.1.8.2 gdamore if (sc->sc_desc == NULL) {
204 1.1.8.2 gdamore aprint_error(" no memory\n");
205 1.1.8.2 gdamore return;
206 1.1.8.2 gdamore }
207 1.1.8.2 gdamore copyin(bda->bd_hid.hid_desc, sc->sc_desc, bda->bd_hid.hid_dlen);
208 1.1.8.2 gdamore
209 1.1.8.2 gdamore /*
210 1.1.8.2 gdamore * Parse the descriptor and attach child devices, one per report.
211 1.1.8.2 gdamore */
212 1.1.8.2 gdamore maxid = -1;
213 1.1.8.2 gdamore h.report_ID = 0;
214 1.1.8.2 gdamore d = hid_start_parse(sc->sc_desc, sc->sc_dlen, hid_none);
215 1.1.8.2 gdamore while (hid_get_item(d, &h)) {
216 1.1.8.2 gdamore if (h.report_ID > maxid)
217 1.1.8.2 gdamore maxid = h.report_ID;
218 1.1.8.2 gdamore }
219 1.1.8.2 gdamore hid_end_parse(d);
220 1.1.8.2 gdamore
221 1.1.8.2 gdamore if (maxid < 0) {
222 1.1.8.2 gdamore aprint_error(" no reports found\n");
223 1.1.8.2 gdamore return;
224 1.1.8.2 gdamore }
225 1.1.8.2 gdamore
226 1.1.8.2 gdamore aprint_normal("\n");
227 1.1.8.2 gdamore
228 1.1.8.2 gdamore for (rep = 0 ; rep <= maxid ; rep++) {
229 1.1.8.2 gdamore if (hid_report_size(sc->sc_desc, sc->sc_dlen, hid_feature, rep) == 0
230 1.1.8.2 gdamore && hid_report_size(sc->sc_desc, sc->sc_dlen, hid_input, rep) == 0
231 1.1.8.2 gdamore && hid_report_size(sc->sc_desc, sc->sc_dlen, hid_output, rep) == 0)
232 1.1.8.2 gdamore continue;
233 1.1.8.2 gdamore
234 1.1.8.2 gdamore bha.ba_desc = sc->sc_desc;
235 1.1.8.2 gdamore bha.ba_dlen = sc->sc_dlen;
236 1.1.8.2 gdamore bha.ba_input = bthidev_null;
237 1.1.8.2 gdamore bha.ba_feature = bthidev_null;
238 1.1.8.2 gdamore bha.ba_output = bthidev_output;
239 1.1.8.2 gdamore bha.ba_id = rep;
240 1.1.8.2 gdamore
241 1.1.8.2 gdamore locs[BTHIDBUSCF_REPORTID] = rep;
242 1.1.8.2 gdamore
243 1.1.8.2 gdamore dev = (struct bthidev *)config_found_sm_loc((struct device *)sc, "bthidbus",
244 1.1.8.2 gdamore locs, &bha, bthidev_print, config_stdsubmatch);
245 1.1.8.2 gdamore if (dev != NULL) {
246 1.1.8.2 gdamore dev->sc_parent = &sc->sc_btdev;
247 1.1.8.2 gdamore dev->sc_id = rep;
248 1.1.8.2 gdamore dev->sc_input = bha.ba_input;
249 1.1.8.2 gdamore dev->sc_feature = bha.ba_feature;
250 1.1.8.2 gdamore LIST_INSERT_HEAD(&sc->sc_list, dev, sc_next);
251 1.1.8.2 gdamore }
252 1.1.8.2 gdamore }
253 1.1.8.2 gdamore
254 1.1.8.2 gdamore /*
255 1.1.8.2 gdamore * start bluetooth connections
256 1.1.8.2 gdamore */
257 1.1.8.2 gdamore s = splsoftnet();
258 1.1.8.2 gdamore if ((sc->sc_flags & BTHID_INITIATE) == 0)
259 1.1.8.2 gdamore bthidev_listen(sc);
260 1.1.8.2 gdamore
261 1.1.8.2 gdamore if (sc->sc_flags & BTHID_CONNECT)
262 1.1.8.2 gdamore bthidev_connect(sc);
263 1.1.8.2 gdamore splx(s);
264 1.1.8.2 gdamore }
265 1.1.8.2 gdamore
266 1.1.8.2 gdamore static int
267 1.1.8.2 gdamore bthidev_detach(struct device *self, int flags)
268 1.1.8.2 gdamore {
269 1.1.8.2 gdamore struct bthidev_softc *sc = (struct bthidev_softc *)self;
270 1.1.8.2 gdamore struct bthidev *dev;
271 1.1.8.2 gdamore int s;
272 1.1.8.2 gdamore
273 1.1.8.2 gdamore s = splsoftnet();
274 1.1.8.2 gdamore sc->sc_flags = 0; /* disable reconnecting */
275 1.1.8.2 gdamore
276 1.1.8.2 gdamore /* release interrupt listen */
277 1.1.8.2 gdamore if (sc->sc_int_l != NULL) {
278 1.1.8.2 gdamore l2cap_detach(&sc->sc_int_l);
279 1.1.8.2 gdamore sc->sc_int_l = NULL;
280 1.1.8.2 gdamore }
281 1.1.8.2 gdamore
282 1.1.8.2 gdamore /* release control listen */
283 1.1.8.2 gdamore if (sc->sc_ctl_l != NULL) {
284 1.1.8.2 gdamore l2cap_detach(&sc->sc_ctl_l);
285 1.1.8.2 gdamore sc->sc_ctl_l = NULL;
286 1.1.8.2 gdamore }
287 1.1.8.2 gdamore
288 1.1.8.2 gdamore /* close interrupt channel */
289 1.1.8.2 gdamore if (sc->sc_int != NULL) {
290 1.1.8.2 gdamore l2cap_disconnect(sc->sc_int, 0);
291 1.1.8.2 gdamore l2cap_detach(&sc->sc_int);
292 1.1.8.2 gdamore sc->sc_int = NULL;
293 1.1.8.2 gdamore }
294 1.1.8.2 gdamore
295 1.1.8.2 gdamore /* close control channel */
296 1.1.8.2 gdamore if (sc->sc_ctl != NULL) {
297 1.1.8.2 gdamore l2cap_disconnect(sc->sc_ctl, 0);
298 1.1.8.2 gdamore l2cap_detach(&sc->sc_ctl);
299 1.1.8.2 gdamore sc->sc_ctl = NULL;
300 1.1.8.2 gdamore }
301 1.1.8.2 gdamore
302 1.1.8.2 gdamore /* remove callout */
303 1.1.8.2 gdamore sc->sc_state = BTHID_DETACHING;
304 1.1.8.2 gdamore callout_stop(&sc->sc_reconnect);
305 1.1.8.2 gdamore if (callout_invoking(&sc->sc_reconnect))
306 1.1.8.2 gdamore tsleep(sc, PWAIT, "bthidetach", 0);
307 1.1.8.2 gdamore
308 1.1.8.2 gdamore splx(s);
309 1.1.8.2 gdamore
310 1.1.8.2 gdamore /* detach children */
311 1.1.8.2 gdamore while ((dev = LIST_FIRST(&sc->sc_list)) != NULL) {
312 1.1.8.2 gdamore LIST_REMOVE(dev, sc_next);
313 1.1.8.2 gdamore config_detach(&dev->sc_dev, flags);
314 1.1.8.2 gdamore }
315 1.1.8.2 gdamore
316 1.1.8.2 gdamore /* release descriptor */
317 1.1.8.2 gdamore if (sc->sc_desc != NULL) {
318 1.1.8.2 gdamore free(sc->sc_desc, M_BTHIDEV);
319 1.1.8.2 gdamore sc->sc_desc = NULL;
320 1.1.8.2 gdamore }
321 1.1.8.2 gdamore return 0;
322 1.1.8.2 gdamore }
323 1.1.8.2 gdamore
324 1.1.8.2 gdamore /*
325 1.1.8.2 gdamore * bthidev config print
326 1.1.8.2 gdamore */
327 1.1.8.2 gdamore static int
328 1.1.8.2 gdamore bthidev_print(void *aux, const char *pnp)
329 1.1.8.2 gdamore {
330 1.1.8.2 gdamore struct bthidev_attach_args *ba = aux;
331 1.1.8.2 gdamore
332 1.1.8.2 gdamore if (pnp != NULL)
333 1.1.8.2 gdamore aprint_normal("%s:", pnp);
334 1.1.8.2 gdamore
335 1.1.8.2 gdamore if (ba->ba_id > 0)
336 1.1.8.2 gdamore aprint_normal(" reportid %d", ba->ba_id);
337 1.1.8.2 gdamore
338 1.1.8.2 gdamore return UNCONF;
339 1.1.8.2 gdamore }
340 1.1.8.2 gdamore
341 1.1.8.2 gdamore
342 1.1.8.2 gdamore /*****************************************************************************
343 1.1.8.2 gdamore *
344 1.1.8.2 gdamore * bluetooth(4) HID attach/detach routines
345 1.1.8.2 gdamore */
346 1.1.8.2 gdamore
347 1.1.8.2 gdamore /*
348 1.1.8.2 gdamore * callouts are scheduled to initiate outgoing connections
349 1.1.8.2 gdamore * after the connection has been lost.
350 1.1.8.2 gdamore */
351 1.1.8.2 gdamore static void
352 1.1.8.2 gdamore bthidev_timeout(void *arg)
353 1.1.8.2 gdamore {
354 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
355 1.1.8.2 gdamore int s, err;
356 1.1.8.2 gdamore
357 1.1.8.2 gdamore s = splsoftnet();
358 1.1.8.2 gdamore callout_ack(&sc->sc_reconnect);
359 1.1.8.2 gdamore
360 1.1.8.2 gdamore switch (sc->sc_state) {
361 1.1.8.2 gdamore case BTHID_CLOSED:
362 1.1.8.2 gdamore sc->sc_flags |= BTHID_CONNECT;
363 1.1.8.2 gdamore err = bthidev_connect(sc);
364 1.1.8.2 gdamore if (err)
365 1.1.8.2 gdamore printf("%s: connect failed (%d)\n",
366 1.1.8.2 gdamore btdev_name(sc), err);
367 1.1.8.2 gdamore break;
368 1.1.8.2 gdamore
369 1.1.8.2 gdamore case BTHID_WAIT_CTL:
370 1.1.8.2 gdamore break;
371 1.1.8.2 gdamore
372 1.1.8.2 gdamore case BTHID_WAIT_INT:
373 1.1.8.2 gdamore break;
374 1.1.8.2 gdamore
375 1.1.8.2 gdamore case BTHID_OPEN:
376 1.1.8.2 gdamore break;
377 1.1.8.2 gdamore
378 1.1.8.2 gdamore case BTHID_DETACHING:
379 1.1.8.2 gdamore wakeup(sc);
380 1.1.8.2 gdamore break;
381 1.1.8.2 gdamore
382 1.1.8.2 gdamore default:
383 1.1.8.2 gdamore break;
384 1.1.8.2 gdamore }
385 1.1.8.2 gdamore splx(s);
386 1.1.8.2 gdamore }
387 1.1.8.2 gdamore
388 1.1.8.2 gdamore /*
389 1.1.8.2 gdamore * listen for our device
390 1.1.8.2 gdamore */
391 1.1.8.2 gdamore static int
392 1.1.8.2 gdamore bthidev_listen(struct bthidev_softc *sc)
393 1.1.8.2 gdamore {
394 1.1.8.2 gdamore struct sockaddr_bt sa;
395 1.1.8.2 gdamore int err;
396 1.1.8.2 gdamore
397 1.1.8.2 gdamore memset(&sa, 0, sizeof(sa));
398 1.1.8.2 gdamore sa.bt_len = sizeof(sa);
399 1.1.8.2 gdamore sa.bt_family = AF_BLUETOOTH;
400 1.1.8.2 gdamore bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr);
401 1.1.8.2 gdamore
402 1.1.8.2 gdamore /*
403 1.1.8.2 gdamore * Listen on control PSM
404 1.1.8.2 gdamore */
405 1.1.8.2 gdamore err = l2cap_attach(&sc->sc_ctl_l, &bthidev_ctl_proto, sc);
406 1.1.8.2 gdamore if (err)
407 1.1.8.2 gdamore return err;
408 1.1.8.2 gdamore
409 1.1.8.2 gdamore sa.bt_psm = sc->sc_ctlpsm;
410 1.1.8.2 gdamore err = l2cap_bind(sc->sc_ctl_l, &sa);
411 1.1.8.2 gdamore if (err)
412 1.1.8.2 gdamore return err;
413 1.1.8.2 gdamore
414 1.1.8.2 gdamore err = l2cap_listen(sc->sc_ctl_l);
415 1.1.8.2 gdamore if (err)
416 1.1.8.2 gdamore return err;
417 1.1.8.2 gdamore
418 1.1.8.2 gdamore /*
419 1.1.8.2 gdamore * Listen on interrupt PSM
420 1.1.8.2 gdamore */
421 1.1.8.2 gdamore err = l2cap_attach(&sc->sc_int_l, &bthidev_int_proto, sc);
422 1.1.8.2 gdamore if (err)
423 1.1.8.2 gdamore return err;
424 1.1.8.2 gdamore
425 1.1.8.2 gdamore sa.bt_psm = sc->sc_intpsm;
426 1.1.8.2 gdamore err = l2cap_bind(sc->sc_int_l, &sa);
427 1.1.8.2 gdamore if (err)
428 1.1.8.2 gdamore return err;
429 1.1.8.2 gdamore
430 1.1.8.2 gdamore err = l2cap_listen(sc->sc_int_l);
431 1.1.8.2 gdamore if (err)
432 1.1.8.2 gdamore return err;
433 1.1.8.2 gdamore
434 1.1.8.2 gdamore sc->sc_state = BTHID_WAIT_CTL;
435 1.1.8.2 gdamore return 0;
436 1.1.8.2 gdamore }
437 1.1.8.2 gdamore
438 1.1.8.2 gdamore /*
439 1.1.8.2 gdamore * start connecting to our device
440 1.1.8.2 gdamore */
441 1.1.8.2 gdamore static int
442 1.1.8.2 gdamore bthidev_connect(struct bthidev_softc *sc)
443 1.1.8.2 gdamore {
444 1.1.8.2 gdamore struct sockaddr_bt sa;
445 1.1.8.2 gdamore int err;
446 1.1.8.2 gdamore
447 1.1.8.2 gdamore if (sc->sc_attempts++ > 0)
448 1.1.8.2 gdamore printf("%s: connect (#%d)\n", btdev_name(sc), sc->sc_attempts);
449 1.1.8.2 gdamore
450 1.1.8.2 gdamore memset(&sa, 0, sizeof(sa));
451 1.1.8.2 gdamore sa.bt_len = sizeof(sa);
452 1.1.8.2 gdamore sa.bt_family = AF_BLUETOOTH;
453 1.1.8.2 gdamore
454 1.1.8.2 gdamore err = l2cap_attach(&sc->sc_ctl, &bthidev_ctl_proto, sc);
455 1.1.8.2 gdamore if (err) {
456 1.1.8.2 gdamore printf("%s: l2cap_attach failed (%d)\n", btdev_name(sc), err);
457 1.1.8.2 gdamore return err;
458 1.1.8.2 gdamore }
459 1.1.8.2 gdamore
460 1.1.8.2 gdamore bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr);
461 1.1.8.2 gdamore err = l2cap_bind(sc->sc_ctl, &sa);
462 1.1.8.2 gdamore if (err) {
463 1.1.8.2 gdamore printf("%s: l2cap_bind failed (%d)\n", btdev_name(sc), err);
464 1.1.8.2 gdamore return err;
465 1.1.8.2 gdamore }
466 1.1.8.2 gdamore
467 1.1.8.2 gdamore sa.bt_psm = sc->sc_ctlpsm;
468 1.1.8.2 gdamore bdaddr_copy(&sa.bt_bdaddr, &sc->sc_raddr);
469 1.1.8.2 gdamore err = l2cap_connect(sc->sc_ctl, &sa);
470 1.1.8.2 gdamore if (err) {
471 1.1.8.2 gdamore printf("%s: l2cap_connect failed (%d)\n", btdev_name(sc), err);
472 1.1.8.2 gdamore return err;
473 1.1.8.2 gdamore }
474 1.1.8.2 gdamore
475 1.1.8.2 gdamore sc->sc_state = BTHID_WAIT_CTL;
476 1.1.8.2 gdamore return 0;
477 1.1.8.2 gdamore }
478 1.1.8.2 gdamore
479 1.1.8.2 gdamore /*****************************************************************************
480 1.1.8.2 gdamore *
481 1.1.8.2 gdamore * bluetooth(9) callback methods for L2CAP
482 1.1.8.2 gdamore *
483 1.1.8.2 gdamore * All these are called from Bluetooth Protocol code, in a soft
484 1.1.8.2 gdamore * interrupt context at IPL_SOFTNET.
485 1.1.8.2 gdamore */
486 1.1.8.2 gdamore
487 1.1.8.2 gdamore static void
488 1.1.8.2 gdamore bthidev_connecting(void *arg)
489 1.1.8.2 gdamore {
490 1.1.8.2 gdamore
491 1.1.8.2 gdamore /* dont care */
492 1.1.8.2 gdamore }
493 1.1.8.2 gdamore
494 1.1.8.2 gdamore static void
495 1.1.8.2 gdamore bthidev_ctl_connected(void *arg)
496 1.1.8.2 gdamore {
497 1.1.8.2 gdamore struct sockaddr_bt sa;
498 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
499 1.1.8.2 gdamore int err;
500 1.1.8.2 gdamore
501 1.1.8.2 gdamore if (sc->sc_state != BTHID_WAIT_CTL)
502 1.1.8.2 gdamore return;
503 1.1.8.2 gdamore
504 1.1.8.2 gdamore KASSERT(sc->sc_ctl != NULL);
505 1.1.8.2 gdamore KASSERT(sc->sc_int == NULL);
506 1.1.8.2 gdamore
507 1.1.8.2 gdamore if (sc->sc_flags & BTHID_CONNECT) {
508 1.1.8.2 gdamore /* initiate connect on interrupt PSM */
509 1.1.8.2 gdamore err = l2cap_attach(&sc->sc_int, &bthidev_int_proto, sc);
510 1.1.8.2 gdamore if (err)
511 1.1.8.2 gdamore goto fail;
512 1.1.8.2 gdamore
513 1.1.8.2 gdamore memset(&sa, 0, sizeof(sa));
514 1.1.8.2 gdamore sa.bt_len = sizeof(sa);
515 1.1.8.2 gdamore sa.bt_family = AF_BLUETOOTH;
516 1.1.8.2 gdamore bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr);
517 1.1.8.2 gdamore
518 1.1.8.2 gdamore err = l2cap_bind(sc->sc_int, &sa);
519 1.1.8.2 gdamore if (err)
520 1.1.8.2 gdamore goto fail;
521 1.1.8.2 gdamore
522 1.1.8.2 gdamore sa.bt_psm = sc->sc_intpsm;
523 1.1.8.2 gdamore bdaddr_copy(&sa.bt_bdaddr, &sc->sc_raddr);
524 1.1.8.2 gdamore err = l2cap_connect(sc->sc_int, &sa);
525 1.1.8.2 gdamore if (err)
526 1.1.8.2 gdamore goto fail;
527 1.1.8.2 gdamore }
528 1.1.8.2 gdamore
529 1.1.8.2 gdamore sc->sc_state = BTHID_WAIT_INT;
530 1.1.8.2 gdamore return;
531 1.1.8.2 gdamore
532 1.1.8.2 gdamore fail:
533 1.1.8.2 gdamore l2cap_detach(&sc->sc_ctl);
534 1.1.8.2 gdamore sc->sc_ctl = NULL;
535 1.1.8.2 gdamore printf("%s: connect failed (%d)\n", btdev_name(sc), err);
536 1.1.8.2 gdamore }
537 1.1.8.2 gdamore
538 1.1.8.2 gdamore static void
539 1.1.8.2 gdamore bthidev_int_connected(void *arg)
540 1.1.8.2 gdamore {
541 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
542 1.1.8.2 gdamore
543 1.1.8.2 gdamore if (sc->sc_state != BTHID_WAIT_INT)
544 1.1.8.2 gdamore return;
545 1.1.8.2 gdamore
546 1.1.8.2 gdamore KASSERT(sc->sc_ctl != NULL);
547 1.1.8.2 gdamore KASSERT(sc->sc_int != NULL);
548 1.1.8.2 gdamore
549 1.1.8.2 gdamore sc->sc_attempts = 0;
550 1.1.8.2 gdamore sc->sc_flags &= ~BTHID_CONNECT;
551 1.1.8.2 gdamore sc->sc_state = BTHID_OPEN;
552 1.1.8.2 gdamore
553 1.1.8.2 gdamore printf("%s: connected\n", btdev_name(sc));
554 1.1.8.2 gdamore }
555 1.1.8.2 gdamore
556 1.1.8.2 gdamore /*
557 1.1.8.2 gdamore * Disconnected
558 1.1.8.2 gdamore *
559 1.1.8.2 gdamore * Depending on our state, this could mean several things, but essentially
560 1.1.8.2 gdamore * we are lost.
561 1.1.8.2 gdamore */
562 1.1.8.2 gdamore static void
563 1.1.8.2 gdamore bthidev_ctl_disconnected(void *arg, int err)
564 1.1.8.2 gdamore {
565 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
566 1.1.8.2 gdamore
567 1.1.8.2 gdamore if (sc->sc_ctl != NULL) {
568 1.1.8.2 gdamore l2cap_detach(&sc->sc_ctl);
569 1.1.8.2 gdamore sc->sc_ctl = NULL;
570 1.1.8.2 gdamore }
571 1.1.8.2 gdamore
572 1.1.8.2 gdamore sc->sc_state = BTHID_CLOSED;
573 1.1.8.2 gdamore
574 1.1.8.2 gdamore if (sc->sc_int == NULL) {
575 1.1.8.2 gdamore printf("%s: disconnected\n", btdev_name(sc));
576 1.1.8.2 gdamore
577 1.1.8.2 gdamore if (sc->sc_flags & BTHID_INITIATE)
578 1.1.8.2 gdamore callout_schedule(&sc->sc_reconnect,
579 1.1.8.2 gdamore BTHID_RETRY_INTERVAL * hz);
580 1.1.8.2 gdamore else
581 1.1.8.2 gdamore sc->sc_state = BTHID_WAIT_CTL;
582 1.1.8.2 gdamore }
583 1.1.8.2 gdamore }
584 1.1.8.2 gdamore
585 1.1.8.2 gdamore static void
586 1.1.8.2 gdamore bthidev_int_disconnected(void *arg, int err)
587 1.1.8.2 gdamore {
588 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
589 1.1.8.2 gdamore
590 1.1.8.2 gdamore if (sc->sc_int != NULL) {
591 1.1.8.2 gdamore l2cap_detach(&sc->sc_int);
592 1.1.8.2 gdamore sc->sc_int = NULL;
593 1.1.8.2 gdamore }
594 1.1.8.2 gdamore
595 1.1.8.2 gdamore sc->sc_state = BTHID_CLOSED;
596 1.1.8.2 gdamore
597 1.1.8.2 gdamore if (sc->sc_ctl == NULL) {
598 1.1.8.2 gdamore printf("%s: disconnected\n", btdev_name(sc));
599 1.1.8.2 gdamore
600 1.1.8.2 gdamore if (sc->sc_flags & BTHID_INITIATE)
601 1.1.8.2 gdamore callout_schedule(&sc->sc_reconnect,
602 1.1.8.2 gdamore BTHID_RETRY_INTERVAL * hz);
603 1.1.8.2 gdamore else
604 1.1.8.2 gdamore sc->sc_state = BTHID_WAIT_CTL;
605 1.1.8.2 gdamore }
606 1.1.8.2 gdamore }
607 1.1.8.2 gdamore
608 1.1.8.2 gdamore /*
609 1.1.8.2 gdamore * New Connections
610 1.1.8.2 gdamore *
611 1.1.8.2 gdamore * We give a new L2CAP handle back if this matches the BDADDR we are
612 1.1.8.2 gdamore * listening for and we are in the right state. bthidev_connected will
613 1.1.8.2 gdamore * be called when the connection is open, so nothing else to do here
614 1.1.8.2 gdamore */
615 1.1.8.2 gdamore static void *
616 1.1.8.2 gdamore bthidev_ctl_newconn(void *arg, struct sockaddr_bt *laddr, struct sockaddr_bt *raddr)
617 1.1.8.2 gdamore {
618 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
619 1.1.8.2 gdamore
620 1.1.8.2 gdamore if (bdaddr_same(&raddr->bt_bdaddr, &sc->sc_raddr) == 0
621 1.1.8.2 gdamore || (sc->sc_flags & BTHID_INITIATE)
622 1.1.8.2 gdamore || sc->sc_state != BTHID_WAIT_CTL
623 1.1.8.2 gdamore || sc->sc_ctl != NULL
624 1.1.8.2 gdamore || sc->sc_int != NULL)
625 1.1.8.2 gdamore return NULL;
626 1.1.8.2 gdamore
627 1.1.8.2 gdamore l2cap_attach(&sc->sc_ctl, &bthidev_ctl_proto, sc);
628 1.1.8.2 gdamore return sc->sc_ctl;
629 1.1.8.2 gdamore }
630 1.1.8.2 gdamore
631 1.1.8.2 gdamore static void *
632 1.1.8.2 gdamore bthidev_int_newconn(void *arg, struct sockaddr_bt *laddr, struct sockaddr_bt *raddr)
633 1.1.8.2 gdamore {
634 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
635 1.1.8.2 gdamore
636 1.1.8.2 gdamore if (bdaddr_same(&raddr->bt_bdaddr, &sc->sc_raddr) == 0
637 1.1.8.2 gdamore || (sc->sc_flags & BTHID_INITIATE)
638 1.1.8.2 gdamore || sc->sc_state != BTHID_WAIT_INT
639 1.1.8.2 gdamore || sc->sc_ctl == NULL
640 1.1.8.2 gdamore || sc->sc_int != NULL)
641 1.1.8.2 gdamore return NULL;
642 1.1.8.2 gdamore
643 1.1.8.2 gdamore l2cap_attach(&sc->sc_int, &bthidev_int_proto, sc);
644 1.1.8.2 gdamore return sc->sc_int;
645 1.1.8.2 gdamore }
646 1.1.8.2 gdamore
647 1.1.8.2 gdamore static void
648 1.1.8.2 gdamore bthidev_complete(void *arg, int count)
649 1.1.8.2 gdamore {
650 1.1.8.2 gdamore
651 1.1.8.2 gdamore /* dont care */
652 1.1.8.2 gdamore }
653 1.1.8.2 gdamore
654 1.1.8.2 gdamore /*
655 1.1.8.2 gdamore * Receive reports from the protocol stack.
656 1.1.8.2 gdamore */
657 1.1.8.2 gdamore static void
658 1.1.8.2 gdamore bthidev_input(void *arg, struct mbuf *m)
659 1.1.8.2 gdamore {
660 1.1.8.2 gdamore struct bthidev_softc *sc = arg;
661 1.1.8.2 gdamore struct bthidev *dev;
662 1.1.8.2 gdamore uint8_t *data;
663 1.1.8.2 gdamore int len;
664 1.1.8.2 gdamore
665 1.1.8.2 gdamore if (sc->sc_state != BTHID_OPEN)
666 1.1.8.2 gdamore goto release;
667 1.1.8.2 gdamore
668 1.1.8.2 gdamore if (m->m_pkthdr.len > m->m_len)
669 1.1.8.2 gdamore printf("%s: truncating HID report\n", btdev_name(sc));
670 1.1.8.2 gdamore
671 1.1.8.2 gdamore len = m->m_len;
672 1.1.8.2 gdamore data = mtod(m, uint8_t *);
673 1.1.8.2 gdamore
674 1.1.8.2 gdamore if (BTHID_TYPE(data[0]) == BTHID_DATA) {
675 1.1.8.2 gdamore /*
676 1.1.8.2 gdamore * data[0] == type / parameter
677 1.1.8.2 gdamore * data[1] == id
678 1.1.8.2 gdamore * data[2..len] == report
679 1.1.8.2 gdamore */
680 1.1.8.2 gdamore if (len < 3)
681 1.1.8.2 gdamore goto release;
682 1.1.8.2 gdamore
683 1.1.8.2 gdamore LIST_FOREACH(dev, &sc->sc_list, sc_next) {
684 1.1.8.2 gdamore if (data[1] == dev->sc_id) {
685 1.1.8.2 gdamore switch (BTHID_DATA_PARAM(data[0])) {
686 1.1.8.2 gdamore case BTHID_DATA_INPUT:
687 1.1.8.2 gdamore (*dev->sc_input)(dev, data + 2, len - 2);
688 1.1.8.2 gdamore break;
689 1.1.8.2 gdamore
690 1.1.8.2 gdamore case BTHID_DATA_FEATURE:
691 1.1.8.2 gdamore (*dev->sc_feature)(dev, data + 2, len - 2);
692 1.1.8.2 gdamore break;
693 1.1.8.2 gdamore
694 1.1.8.2 gdamore default:
695 1.1.8.2 gdamore break;
696 1.1.8.2 gdamore }
697 1.1.8.2 gdamore
698 1.1.8.2 gdamore goto release;
699 1.1.8.2 gdamore }
700 1.1.8.2 gdamore }
701 1.1.8.2 gdamore printf("%s: report id %d, len = %d ignored\n",
702 1.1.8.2 gdamore btdev_name(sc), data[1], len - 2);
703 1.1.8.2 gdamore
704 1.1.8.2 gdamore goto release;
705 1.1.8.2 gdamore }
706 1.1.8.2 gdamore
707 1.1.8.2 gdamore if (BTHID_TYPE(data[0]) == BTHID_CONTROL) {
708 1.1.8.2 gdamore if (len < 1)
709 1.1.8.2 gdamore goto release;
710 1.1.8.2 gdamore
711 1.1.8.2 gdamore if (BTHID_DATA_PARAM(data[0]) == BTHID_CONTROL_UNPLUG) {
712 1.1.8.2 gdamore printf("%s: unplugged\n", btdev_name(sc));
713 1.1.8.2 gdamore
714 1.1.8.2 gdamore /* close interrupt channel */
715 1.1.8.2 gdamore if (sc->sc_int != NULL) {
716 1.1.8.2 gdamore l2cap_disconnect(sc->sc_int, 0);
717 1.1.8.2 gdamore l2cap_detach(&sc->sc_int);
718 1.1.8.2 gdamore sc->sc_int = NULL;
719 1.1.8.2 gdamore }
720 1.1.8.2 gdamore
721 1.1.8.2 gdamore /* close control channel */
722 1.1.8.2 gdamore if (sc->sc_ctl != NULL) {
723 1.1.8.2 gdamore l2cap_disconnect(sc->sc_ctl, 0);
724 1.1.8.2 gdamore l2cap_detach(&sc->sc_ctl);
725 1.1.8.2 gdamore sc->sc_ctl = NULL;
726 1.1.8.2 gdamore }
727 1.1.8.2 gdamore }
728 1.1.8.2 gdamore
729 1.1.8.2 gdamore goto release;
730 1.1.8.2 gdamore }
731 1.1.8.2 gdamore
732 1.1.8.2 gdamore release:
733 1.1.8.2 gdamore m_freem(m);
734 1.1.8.2 gdamore }
735 1.1.8.2 gdamore
736 1.1.8.2 gdamore /*****************************************************************************
737 1.1.8.2 gdamore *
738 1.1.8.2 gdamore * IO routines
739 1.1.8.2 gdamore */
740 1.1.8.2 gdamore
741 1.1.8.2 gdamore static void
742 1.1.8.2 gdamore bthidev_null(struct bthidev *dev, uint8_t *report, int len)
743 1.1.8.2 gdamore {
744 1.1.8.2 gdamore
745 1.1.8.2 gdamore /*
746 1.1.8.2 gdamore * empty routine just in case the device
747 1.1.8.2 gdamore * provided no method to handle this report
748 1.1.8.2 gdamore */
749 1.1.8.2 gdamore }
750 1.1.8.2 gdamore
751 1.1.8.2 gdamore static int
752 1.1.8.2 gdamore bthidev_output(struct bthidev *dev, uint8_t *report, int rlen)
753 1.1.8.2 gdamore {
754 1.1.8.2 gdamore struct bthidev_softc *sc = (struct bthidev_softc *)dev->sc_parent;
755 1.1.8.2 gdamore struct mbuf *m;
756 1.1.8.2 gdamore int s, err;
757 1.1.8.2 gdamore
758 1.1.8.2 gdamore if (sc == NULL || sc->sc_state != BTHID_OPEN)
759 1.1.8.2 gdamore return ENOTCONN;
760 1.1.8.2 gdamore
761 1.1.8.2 gdamore KASSERT(sc->sc_ctl != NULL);
762 1.1.8.2 gdamore KASSERT(sc->sc_int != NULL);
763 1.1.8.2 gdamore
764 1.1.8.2 gdamore if (rlen == 0 || report == NULL)
765 1.1.8.2 gdamore return 0;
766 1.1.8.2 gdamore
767 1.1.8.2 gdamore if (rlen > MHLEN - 2) {
768 1.1.8.2 gdamore printf("%s: output report too long (%d)!\n",
769 1.1.8.2 gdamore btdev_name(sc), rlen);
770 1.1.8.2 gdamore
771 1.1.8.2 gdamore return EMSGSIZE;
772 1.1.8.2 gdamore }
773 1.1.8.2 gdamore
774 1.1.8.2 gdamore m = m_gethdr(M_DONTWAIT, MT_DATA);
775 1.1.8.2 gdamore if (m == NULL)
776 1.1.8.2 gdamore return ENOMEM;
777 1.1.8.2 gdamore
778 1.1.8.2 gdamore /*
779 1.1.8.2 gdamore * data[0] = type / parameter
780 1.1.8.2 gdamore * data[1] = id
781 1.1.8.2 gdamore * data[2..N] = report
782 1.1.8.2 gdamore */
783 1.1.8.2 gdamore mtod(m, uint8_t *)[0] = (uint8_t)((BTHID_DATA << 4) | BTHID_DATA_OUTPUT);
784 1.1.8.2 gdamore mtod(m, uint8_t *)[1] = dev->sc_id;
785 1.1.8.2 gdamore memcpy(mtod(m, uint8_t *) + 2, report, rlen);
786 1.1.8.2 gdamore m->m_pkthdr.len = m->m_len = rlen + 2;
787 1.1.8.2 gdamore
788 1.1.8.2 gdamore s = splsoftnet();
789 1.1.8.2 gdamore err = l2cap_send(sc->sc_int, m);
790 1.1.8.2 gdamore splx(s);
791 1.1.8.2 gdamore
792 1.1.8.2 gdamore return err;
793 1.1.8.2 gdamore }
794