Thu Dec 20 11:17:48 2012 UTC ()
increase some diagnostics


(plunky)
diff -r1.23 -r1.24 src/sys/dev/bluetooth/bthidev.c
diff -r1.4 -r1.5 src/sys/dev/bluetooth/btmagic.c

cvs diff -r1.23 -r1.24 src/sys/dev/bluetooth/bthidev.c (expand / switch to unified diff)

--- src/sys/dev/bluetooth/bthidev.c 2012/12/20 11:13:53 1.23
+++ src/sys/dev/bluetooth/bthidev.c 2012/12/20 11:17:47 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bthidev.c,v 1.23 2012/12/20 11:13:53 plunky Exp $ */ 1/* $NetBSD: bthidev.c,v 1.24 2012/12/20 11:17:47 plunky Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2006 Itronix Inc. 4 * Copyright (c) 2006 Itronix Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Written by Iain Hibbert for Itronix Inc. 7 * Written by Iain Hibbert for Itronix Inc.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 25 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 * ON ANY THEORY OF LIABILITY, WHETHER IN 28 * ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE. 31 * POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: bthidev.c,v 1.23 2012/12/20 11:13:53 plunky Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: bthidev.c,v 1.24 2012/12/20 11:17:47 plunky Exp $");
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/condvar.h> 38#include <sys/condvar.h>
39#include <sys/conf.h> 39#include <sys/conf.h>
40#include <sys/device.h> 40#include <sys/device.h>
41#include <sys/fcntl.h> 41#include <sys/fcntl.h>
42#include <sys/kernel.h> 42#include <sys/kernel.h>
43#include <sys/kthread.h> 43#include <sys/kthread.h>
44#include <sys/queue.h> 44#include <sys/queue.h>
45#include <sys/malloc.h> 45#include <sys/malloc.h>
46#include <sys/mbuf.h> 46#include <sys/mbuf.h>
47#include <sys/mutex.h> 47#include <sys/mutex.h>
48#include <sys/proc.h> 48#include <sys/proc.h>
@@ -183,26 +183,27 @@ bthidev_attach(device_t parent, device_t @@ -183,26 +183,27 @@ bthidev_attach(device_t parent, device_t
183{ 183{
184 struct bthidev_softc *sc = device_private(self); 184 struct bthidev_softc *sc = device_private(self);
185 prop_dictionary_t dict = aux; 185 prop_dictionary_t dict = aux;
186 prop_object_t obj; 186 prop_object_t obj;
187 device_t dev; 187 device_t dev;
188 struct bthidev_attach_args bha; 188 struct bthidev_attach_args bha;
189 struct bthidev *hidev; 189 struct bthidev *hidev;
190 struct hid_data *d; 190 struct hid_data *d;
191 struct hid_item h; 191 struct hid_item h;
192 const void *desc; 192 const void *desc;
193 int locs[BTHIDBUSCF_NLOCS]; 193 int locs[BTHIDBUSCF_NLOCS];
194 int maxid, rep, dlen; 194 int maxid, rep, dlen;
195 int vendor, product; 195 int vendor, product;
 196 int err;
196 197
197 /* 198 /*
198 * Init softc 199 * Init softc
199 */ 200 */
200 sc->sc_dev = self; 201 sc->sc_dev = self;
201 LIST_INIT(&sc->sc_list); 202 LIST_INIT(&sc->sc_list);
202 MBUFQ_INIT(&sc->sc_inq); 203 MBUFQ_INIT(&sc->sc_inq);
203 callout_init(&sc->sc_reconnect, 0); 204 callout_init(&sc->sc_reconnect, 0);
204 callout_setfunc(&sc->sc_reconnect, bthidev_timeout, sc); 205 callout_setfunc(&sc->sc_reconnect, bthidev_timeout, sc);
205 sc->sc_state = BTHID_CLOSED; 206 sc->sc_state = BTHID_CLOSED;
206 sc->sc_flags = BTHID_CONNECTING; 207 sc->sc_flags = BTHID_CONNECTING;
207 sc->sc_ctlpsm = L2CAP_PSM_HID_CNTL; 208 sc->sc_ctlpsm = L2CAP_PSM_HID_CNTL;
208 sc->sc_intpsm = L2CAP_PSM_HID_INTR; 209 sc->sc_intpsm = L2CAP_PSM_HID_INTR;
@@ -327,28 +328,29 @@ bthidev_attach(device_t parent, device_t @@ -327,28 +328,29 @@ bthidev_attach(device_t parent, device_t
327 hidev->sc_id = rep; 328 hidev->sc_id = rep;
328 hidev->sc_input = bha.ba_input; 329 hidev->sc_input = bha.ba_input;
329 hidev->sc_feature = bha.ba_feature; 330 hidev->sc_feature = bha.ba_feature;
330 LIST_INSERT_HEAD(&sc->sc_list, hidev, sc_next); 331 LIST_INSERT_HEAD(&sc->sc_list, hidev, sc_next);
331 } 332 }
332 } 333 }
333 334
334 pmf_device_register(self, NULL, NULL); 335 pmf_device_register(self, NULL, NULL);
335 336
336 /* 337 /*
337 * start bluetooth connections 338 * start bluetooth connections
338 */ 339 */
339 mutex_enter(bt_lock); 340 mutex_enter(bt_lock);
340 if ((sc->sc_flags & BTHID_RECONNECT) == 0) 341 if ((sc->sc_flags & BTHID_RECONNECT) == 0
341 bthidev_listen(sc); 342 && (err = bthidev_listen(sc)) != 0)
 343 aprint_error_dev(self, "failed to listen (%d)\n", err);
342 344
343 if (sc->sc_flags & BTHID_CONNECTING) 345 if (sc->sc_flags & BTHID_CONNECTING)
344 bthidev_connect(sc); 346 bthidev_connect(sc);
345 mutex_exit(bt_lock); 347 mutex_exit(bt_lock);
346} 348}
347 349
348static int 350static int
349bthidev_detach(device_t self, int flags) 351bthidev_detach(device_t self, int flags)
350{ 352{
351 struct bthidev_softc *sc = device_private(self); 353 struct bthidev_softc *sc = device_private(self);
352 struct bthidev *hidev; 354 struct bthidev *hidev;
353 355
354 mutex_enter(bt_lock); 356 mutex_enter(bt_lock);
@@ -551,28 +553,30 @@ bthidev_connect(struct bthidev_softc *sc @@ -551,28 +553,30 @@ bthidev_connect(struct bthidev_softc *sc
551 aprint_verbose_dev(sc->sc_dev, "connect (#%d)\n", sc->sc_attempts); 553 aprint_verbose_dev(sc->sc_dev, "connect (#%d)\n", sc->sc_attempts);
552 554
553 memset(&sa, 0, sizeof(sa)); 555 memset(&sa, 0, sizeof(sa));
554 sa.bt_len = sizeof(sa); 556 sa.bt_len = sizeof(sa);
555 sa.bt_family = AF_BLUETOOTH; 557 sa.bt_family = AF_BLUETOOTH;
556 558
557 err = l2cap_attach(&sc->sc_ctl, &bthidev_ctl_proto, sc); 559 err = l2cap_attach(&sc->sc_ctl, &bthidev_ctl_proto, sc);
558 if (err) { 560 if (err) {
559 aprint_error_dev(sc->sc_dev, "l2cap_attach failed (%d)\n", err); 561 aprint_error_dev(sc->sc_dev, "l2cap_attach failed (%d)\n", err);
560 return err; 562 return err;
561 } 563 }
562 564
563 err = l2cap_setopt(sc->sc_ctl, &sc->sc_mode); 565 err = l2cap_setopt(sc->sc_ctl, &sc->sc_mode);
564 if (err) 566 if (err) {
 567 aprint_error_dev(sc->sc_dev, "l2cap_setopt failed (%d)\n", err);
565 return err; 568 return err;
 569 }
566 570
567 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr); 571 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr);
568 err = l2cap_bind(sc->sc_ctl, &sa); 572 err = l2cap_bind(sc->sc_ctl, &sa);
569 if (err) { 573 if (err) {
570 aprint_error_dev(sc->sc_dev, "l2cap_bind failed (%d)\n", err); 574 aprint_error_dev(sc->sc_dev, "l2cap_bind failed (%d)\n", err);
571 return err; 575 return err;
572 } 576 }
573 577
574 sa.bt_psm = sc->sc_ctlpsm; 578 sa.bt_psm = sc->sc_ctlpsm;
575 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_raddr); 579 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_raddr);
576 err = l2cap_connect(sc->sc_ctl, &sa); 580 err = l2cap_connect(sc->sc_ctl, &sa);
577 if (err) { 581 if (err) {
578 aprint_error_dev(sc->sc_dev, "l2cap_connect failed (%d)\n", err); 582 aprint_error_dev(sc->sc_dev, "l2cap_connect failed (%d)\n", err);
@@ -792,27 +796,27 @@ bthidev_int_connected(void *arg) @@ -792,27 +796,27 @@ bthidev_int_connected(void *arg)
792static void 796static void
793bthidev_ctl_disconnected(void *arg, int err) 797bthidev_ctl_disconnected(void *arg, int err)
794{ 798{
795 struct bthidev_softc *sc = arg; 799 struct bthidev_softc *sc = arg;
796 800
797 if (sc->sc_ctl != NULL) { 801 if (sc->sc_ctl != NULL) {
798 l2cap_detach(&sc->sc_ctl); 802 l2cap_detach(&sc->sc_ctl);
799 sc->sc_ctl = NULL; 803 sc->sc_ctl = NULL;
800 } 804 }
801 805
802 sc->sc_state = BTHID_CLOSED; 806 sc->sc_state = BTHID_CLOSED;
803 807
804 if (sc->sc_int == NULL) { 808 if (sc->sc_int == NULL) {
805 aprint_normal_dev(sc->sc_dev, "disconnected\n"); 809 aprint_normal_dev(sc->sc_dev, "disconnected (%d)\n", err);
806 sc->sc_flags &= ~BTHID_CONNECTING; 810 sc->sc_flags &= ~BTHID_CONNECTING;
807 811
808 if (sc->sc_flags & BTHID_RECONNECT) 812 if (sc->sc_flags & BTHID_RECONNECT)
809 callout_schedule(&sc->sc_reconnect, 813 callout_schedule(&sc->sc_reconnect,
810 BTHID_RETRY_INTERVAL * hz); 814 BTHID_RETRY_INTERVAL * hz);
811 else 815 else
812 sc->sc_state = BTHID_WAIT_CTL; 816 sc->sc_state = BTHID_WAIT_CTL;
813 } else { 817 } else {
814 /* 818 /*
815 * The interrupt channel should have been closed first, 819 * The interrupt channel should have been closed first,
816 * but its potentially unsafe to detach that from here. 820 * but its potentially unsafe to detach that from here.
817 * Give them a second to do the right thing or let the 821 * Give them a second to do the right thing or let the
818 * callout handle it. 822 * callout handle it.
@@ -824,27 +828,27 @@ bthidev_ctl_disconnected(void *arg, int  @@ -824,27 +828,27 @@ bthidev_ctl_disconnected(void *arg, int
824static void 828static void
825bthidev_int_disconnected(void *arg, int err) 829bthidev_int_disconnected(void *arg, int err)
826{ 830{
827 struct bthidev_softc *sc = arg; 831 struct bthidev_softc *sc = arg;
828 832
829 if (sc->sc_int != NULL) { 833 if (sc->sc_int != NULL) {
830 l2cap_detach(&sc->sc_int); 834 l2cap_detach(&sc->sc_int);
831 sc->sc_int = NULL; 835 sc->sc_int = NULL;
832 } 836 }
833 837
834 sc->sc_state = BTHID_CLOSED; 838 sc->sc_state = BTHID_CLOSED;
835 839
836 if (sc->sc_ctl == NULL) { 840 if (sc->sc_ctl == NULL) {
837 aprint_normal_dev(sc->sc_dev, "disconnected\n"); 841 aprint_normal_dev(sc->sc_dev, "disconnected (%d)\n", err);
838 sc->sc_flags &= ~BTHID_CONNECTING; 842 sc->sc_flags &= ~BTHID_CONNECTING;
839 843
840 if (sc->sc_flags & BTHID_RECONNECT) 844 if (sc->sc_flags & BTHID_RECONNECT)
841 callout_schedule(&sc->sc_reconnect, 845 callout_schedule(&sc->sc_reconnect,
842 BTHID_RETRY_INTERVAL * hz); 846 BTHID_RETRY_INTERVAL * hz);
843 else 847 else
844 sc->sc_state = BTHID_WAIT_CTL; 848 sc->sc_state = BTHID_WAIT_CTL;
845 } else { 849 } else {
846 /* 850 /*
847 * The control channel should be closing also, allow 851 * The control channel should be closing also, allow
848 * them a chance to do that before we force it. 852 * them a chance to do that before we force it.
849 */ 853 */
850 callout_schedule(&sc->sc_reconnect, hz); 854 callout_schedule(&sc->sc_reconnect, hz);

cvs diff -r1.4 -r1.5 src/sys/dev/bluetooth/btmagic.c (expand / switch to unified diff)

--- src/sys/dev/bluetooth/btmagic.c 2012/12/20 11:13:53 1.4
+++ src/sys/dev/bluetooth/btmagic.c 2012/12/20 11:17:47 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: btmagic.c,v 1.4 2012/12/20 11:13:53 plunky Exp $ */ 1/* $NetBSD: btmagic.c,v 1.5 2012/12/20 11:17:47 plunky Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Iain Hibbert. 8 * by Iain Hibbert.
9 * 9 *
10 * This code is derived from software contributed to The NetBSD Foundation 10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Lennart Augustsson (lennart@augustsson.net) at 11 * by Lennart Augustsson (lennart@augustsson.net) at
12 * Carlstedt Research & Technology. 12 * Carlstedt Research & Technology.
13 * 13 *
14 * Redistribution and use in source and binary forms, with or without 14 * Redistribution and use in source and binary forms, with or without
@@ -75,27 +75,27 @@ @@ -75,27 +75,27 @@
75 * for such complications. 75 * for such complications.
76 * 76 *
77 * This driver interprets the touch reports only as far as emulating a 77 * This driver interprets the touch reports only as far as emulating a
78 * middle mouse button and providing horizontal and vertical scroll action. 78 * middle mouse button and providing horizontal and vertical scroll action.
79 * Full gesture support would be more complicated and is left as an exercise 79 * Full gesture support would be more complicated and is left as an exercise
80 * for the reader. 80 * for the reader.
81 * 81 *
82 * Credit for decoding the proprietary touch reports goes to Michael Poole 82 * Credit for decoding the proprietary touch reports goes to Michael Poole
83 * who wrote the Linux hid-magicmouse input driver. 83 * who wrote the Linux hid-magicmouse input driver.
84 * 84 *
85 *****************************************************************************/ 85 *****************************************************************************/
86 86
87#include <sys/cdefs.h> 87#include <sys/cdefs.h>
88__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.4 2012/12/20 11:13:53 plunky Exp $"); 88__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.5 2012/12/20 11:17:47 plunky Exp $");
89 89
90#include <sys/param.h> 90#include <sys/param.h>
91#include <sys/conf.h> 91#include <sys/conf.h>
92#include <sys/device.h> 92#include <sys/device.h>
93#include <sys/fcntl.h> 93#include <sys/fcntl.h>
94#include <sys/kernel.h> 94#include <sys/kernel.h>
95#include <sys/malloc.h> 95#include <sys/malloc.h>
96#include <sys/mbuf.h> 96#include <sys/mbuf.h>
97#include <sys/proc.h> 97#include <sys/proc.h>
98#include <sys/socketvar.h> 98#include <sys/socketvar.h>
99#include <sys/systm.h> 99#include <sys/systm.h>
100#include <sys/sysctl.h> 100#include <sys/sysctl.h>
101 101
@@ -262,26 +262,27 @@ btmagic_match(device_t self, cfdata_t cf @@ -262,26 +262,27 @@ btmagic_match(device_t self, cfdata_t cf
262 && p == USB_PRODUCT_APPLE_MAGICMOUSE) 262 && p == USB_PRODUCT_APPLE_MAGICMOUSE)
263 return 2; /* trump bthidev(4) */ 263 return 2; /* trump bthidev(4) */
264 264
265 return 0; 265 return 0;
266} 266}
267 267
268static void 268static void
269btmagic_attach(device_t parent, device_t self, void *aux) 269btmagic_attach(device_t parent, device_t self, void *aux)
270{ 270{
271 struct btmagic_softc *sc = device_private(self); 271 struct btmagic_softc *sc = device_private(self);
272 struct wsmousedev_attach_args wsma; 272 struct wsmousedev_attach_args wsma;
273 const struct sysctlnode *node; 273 const struct sysctlnode *node;
274 prop_object_t obj; 274 prop_object_t obj;
 275 int err;
275 276
276 /* 277 /*
277 * Init softc 278 * Init softc
278 */ 279 */
279 sc->sc_dev = self; 280 sc->sc_dev = self;
280 sc->sc_state = BTMAGIC_CLOSED; 281 sc->sc_state = BTMAGIC_CLOSED;
281 callout_init(&sc->sc_timeout, 0); 282 callout_init(&sc->sc_timeout, 0);
282 callout_setfunc(&sc->sc_timeout, btmagic_timeout, sc); 283 callout_setfunc(&sc->sc_timeout, btmagic_timeout, sc);
283 sockopt_init(&sc->sc_mode, BTPROTO_L2CAP, SO_L2CAP_LM, 0); 284 sockopt_init(&sc->sc_mode, BTPROTO_L2CAP, SO_L2CAP_LM, 0);
284 285
285 /* 286 /*
286 * extract config from proplist 287 * extract config from proplist
287 */ 288 */
@@ -382,27 +383,28 @@ btmagic_attach(device_t parent, device_t @@ -382,27 +383,28 @@ btmagic_attach(device_t parent, device_t
382 wsma.accesscookie = self; 383 wsma.accesscookie = self;
383 sc->sc_wsmouse = config_found(self, &wsma, wsmousedevprint); 384 sc->sc_wsmouse = config_found(self, &wsma, wsmousedevprint);
384 if (sc->sc_wsmouse == NULL) { 385 if (sc->sc_wsmouse == NULL) {
385 aprint_error_dev(self, "failed to attach wsmouse\n"); 386 aprint_error_dev(self, "failed to attach wsmouse\n");
386 return; 387 return;
387 } 388 }
388 389
389 pmf_device_register(self, NULL, NULL); 390 pmf_device_register(self, NULL, NULL);
390 391
391 /* 392 /*
392 * start bluetooth connections 393 * start bluetooth connections
393 */ 394 */
394 mutex_enter(bt_lock); 395 mutex_enter(bt_lock);
395 btmagic_listen(sc); 396 if ((err = btmagic_listen(sc)) != 0)
 397 aprint_error_dev(self, "failed to listen (%d)\n", err);
396 btmagic_connect(sc); 398 btmagic_connect(sc);
397 mutex_exit(bt_lock); 399 mutex_exit(bt_lock);
398} 400}
399 401
400static int 402static int
401btmagic_detach(device_t self, int flags) 403btmagic_detach(device_t self, int flags)
402{ 404{
403 struct btmagic_softc *sc = device_private(self); 405 struct btmagic_softc *sc = device_private(self);
404 int err = 0; 406 int err = 0;
405 407
406 mutex_enter(bt_lock); 408 mutex_enter(bt_lock);
407 409
408 /* release interrupt listen */ 410 /* release interrupt listen */
@@ -523,28 +525,31 @@ btmagic_connect(struct btmagic_softc *sc @@ -523,28 +525,31 @@ btmagic_connect(struct btmagic_softc *sc
523 525
524 memset(&sa, 0, sizeof(sa)); 526 memset(&sa, 0, sizeof(sa));
525 sa.bt_len = sizeof(sa); 527 sa.bt_len = sizeof(sa);
526 sa.bt_family = AF_BLUETOOTH; 528 sa.bt_family = AF_BLUETOOTH;
527 529
528 err = l2cap_attach(&sc->sc_ctl, &btmagic_ctl_proto, sc); 530 err = l2cap_attach(&sc->sc_ctl, &btmagic_ctl_proto, sc);
529 if (err) { 531 if (err) {
530 printf("%s: l2cap_attach failed (%d)\n", 532 printf("%s: l2cap_attach failed (%d)\n",
531 device_xname(sc->sc_dev), err); 533 device_xname(sc->sc_dev), err);
532 return err; 534 return err;
533 } 535 }
534 536
535 err = l2cap_setopt(sc->sc_ctl, &sc->sc_mode); 537 err = l2cap_setopt(sc->sc_ctl, &sc->sc_mode);
536 if (err) 538 if (err) {
 539 printf("%s: l2cap_setopt failed (%d)\n",
 540 device_xname(sc->sc_dev), err);
537 return err; 541 return err;
 542 }
538 543
539 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr); 544 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr);
540 err = l2cap_bind(sc->sc_ctl, &sa); 545 err = l2cap_bind(sc->sc_ctl, &sa);
541 if (err) { 546 if (err) {
542 printf("%s: l2cap_bind failed (%d)\n", 547 printf("%s: l2cap_bind failed (%d)\n",
543 device_xname(sc->sc_dev), err); 548 device_xname(sc->sc_dev), err);
544 return err; 549 return err;
545 } 550 }
546 551
547 sa.bt_psm = L2CAP_PSM_HID_CNTL; 552 sa.bt_psm = L2CAP_PSM_HID_CNTL;
548 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_raddr); 553 bdaddr_copy(&sa.bt_bdaddr, &sc->sc_raddr);
549 err = l2cap_connect(sc->sc_ctl, &sa); 554 err = l2cap_connect(sc->sc_ctl, &sa);
550 if (err) { 555 if (err) {
@@ -875,53 +880,53 @@ btmagic_int_connected(void *arg) @@ -875,53 +880,53 @@ btmagic_int_connected(void *arg)
875 * we are lost. If both channels are closed, schedule another connection. 880 * we are lost. If both channels are closed, schedule another connection.
876 */ 881 */
877static void 882static void
878btmagic_ctl_disconnected(void *arg, int err) 883btmagic_ctl_disconnected(void *arg, int err)
879{ 884{
880 struct btmagic_softc *sc = arg; 885 struct btmagic_softc *sc = arg;
881 886
882 if (sc->sc_ctl != NULL) { 887 if (sc->sc_ctl != NULL) {
883 l2cap_detach(&sc->sc_ctl); 888 l2cap_detach(&sc->sc_ctl);
884 sc->sc_ctl = NULL; 889 sc->sc_ctl = NULL;
885 } 890 }
886 891
887 if (sc->sc_int == NULL) { 892 if (sc->sc_int == NULL) {
888 printf("%s: disconnected\n", device_xname(sc->sc_dev)); 893 printf("%s: disconnected (%d)\n", device_xname(sc->sc_dev), err);
889 CLR(sc->sc_flags, BTMAGIC_CONNECTING); 894 CLR(sc->sc_flags, BTMAGIC_CONNECTING);
890 sc->sc_state = BTMAGIC_WAIT_CTL; 895 sc->sc_state = BTMAGIC_WAIT_CTL;
891 } else { 896 } else {
892 /* 897 /*
893 * The interrupt channel should have been closed first, 898 * The interrupt channel should have been closed first,
894 * but its potentially unsafe to detach that from here. 899 * but its potentially unsafe to detach that from here.
895 * Give them a second to do the right thing or let the 900 * Give them a second to do the right thing or let the
896 * callout handle it. 901 * callout handle it.
897 */ 902 */
898 sc->sc_state = BTMAGIC_CLOSED; 903 sc->sc_state = BTMAGIC_CLOSED;
899 callout_schedule(&sc->sc_timeout, hz); 904 callout_schedule(&sc->sc_timeout, hz);
900 } 905 }
901} 906}
902 907
903static void 908static void
904btmagic_int_disconnected(void *arg, int err) 909btmagic_int_disconnected(void *arg, int err)
905{ 910{
906 struct btmagic_softc *sc = arg; 911 struct btmagic_softc *sc = arg;
907 912
908 if (sc->sc_int != NULL) { 913 if (sc->sc_int != NULL) {
909 l2cap_detach(&sc->sc_int); 914 l2cap_detach(&sc->sc_int);
910 sc->sc_int = NULL; 915 sc->sc_int = NULL;
911 } 916 }
912 917
913 if (sc->sc_ctl == NULL) { 918 if (sc->sc_ctl == NULL) {
914 printf("%s: disconnected\n", device_xname(sc->sc_dev)); 919 printf("%s: disconnected (%d)\n", device_xname(sc->sc_dev), err);
915 CLR(sc->sc_flags, BTMAGIC_CONNECTING); 920 CLR(sc->sc_flags, BTMAGIC_CONNECTING);
916 sc->sc_state = BTMAGIC_WAIT_CTL; 921 sc->sc_state = BTMAGIC_WAIT_CTL;
917 } else { 922 } else {
918 /* 923 /*
919 * The control channel should be closing also, allow 924 * The control channel should be closing also, allow
920 * them a chance to do that before we force it. 925 * them a chance to do that before we force it.
921 */ 926 */
922 sc->sc_state = BTMAGIC_CLOSED; 927 sc->sc_state = BTMAGIC_CLOSED;
923 callout_schedule(&sc->sc_timeout, hz); 928 callout_schedule(&sc->sc_timeout, hz);
924 } 929 }
925} 930}
926 931
927/* 932/*