| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: btsco.c,v 1.25 2011/11/23 23:07:31 jmcneill Exp $ */ | | 1 | /* $NetBSD: btsco.c,v 1.26 2011/12/10 16:16:11 jmcneill 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: btsco.c,v 1.25 2011/11/23 23:07:31 jmcneill Exp $"); | | 35 | __KERNEL_RCSID(0, "$NetBSD: btsco.c,v 1.26 2011/12/10 16:16:11 jmcneill Exp $"); |
36 | | | 36 | |
37 | #include <sys/param.h> | | 37 | #include <sys/param.h> |
38 | #include <sys/audioio.h> | | 38 | #include <sys/audioio.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/queue.h> | | 43 | #include <sys/queue.h> |
44 | #include <sys/kmem.h> | | 44 | #include <sys/kmem.h> |
45 | #include <sys/mbuf.h> | | 45 | #include <sys/mbuf.h> |
46 | #include <sys/proc.h> | | 46 | #include <sys/proc.h> |
47 | #include <sys/socketvar.h> | | 47 | #include <sys/socketvar.h> |
48 | #include <sys/systm.h> | | 48 | #include <sys/systm.h> |
| @@ -566,27 +566,27 @@ static int | | | @@ -566,27 +566,27 @@ static int |
566 | btsco_open(void *hdl, int flags) | | 566 | btsco_open(void *hdl, int flags) |
567 | { | | 567 | { |
568 | struct sockaddr_bt sa; | | 568 | struct sockaddr_bt sa; |
569 | struct btsco_softc *sc = hdl; | | 569 | struct btsco_softc *sc = hdl; |
570 | struct sockopt sopt; | | 570 | struct sockopt sopt; |
571 | int err, timo; | | 571 | int err, timo; |
572 | | | 572 | |
573 | DPRINTF("%s flags 0x%x\n", sc->sc_name, flags); | | 573 | DPRINTF("%s flags 0x%x\n", sc->sc_name, flags); |
574 | /* flags FREAD & FWRITE? */ | | 574 | /* flags FREAD & FWRITE? */ |
575 | | | 575 | |
576 | if (sc->sc_sco != NULL || sc->sc_sco_l != NULL) | | 576 | if (sc->sc_sco != NULL || sc->sc_sco_l != NULL) |
577 | return EIO; | | 577 | return EIO; |
578 | | | 578 | |
579 | mutex_enter(bt_lock); | | 579 | KASSERT(mutex_owned(bt_lock)); |
580 | | | 580 | |
581 | memset(&sa, 0, sizeof(sa)); | | 581 | memset(&sa, 0, sizeof(sa)); |
582 | sa.bt_len = sizeof(sa); | | 582 | sa.bt_len = sizeof(sa); |
583 | sa.bt_family = AF_BLUETOOTH; | | 583 | sa.bt_family = AF_BLUETOOTH; |
584 | bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr); | | 584 | bdaddr_copy(&sa.bt_bdaddr, &sc->sc_laddr); |
585 | | | 585 | |
586 | if (sc->sc_flags & BTSCO_LISTEN) { | | 586 | if (sc->sc_flags & BTSCO_LISTEN) { |
587 | err = sco_attach(&sc->sc_sco_l, &btsco_sco_proto, sc); | | 587 | err = sco_attach(&sc->sc_sco_l, &btsco_sco_proto, sc); |
588 | if (err) | | 588 | if (err) |
589 | goto done; | | 589 | goto done; |
590 | | | 590 | |
591 | err = sco_bind(sc->sc_sco_l, &sa); | | 591 | err = sco_bind(sc->sc_sco_l, &sa); |
592 | if (err) { | | 592 | if (err) { |
| @@ -643,50 +643,48 @@ btsco_open(void *hdl, int flags) | | | @@ -643,50 +643,48 @@ btsco_open(void *hdl, int flags) |
643 | case BTSCO_OPEN: /* hurrah */ | | 643 | case BTSCO_OPEN: /* hurrah */ |
644 | sockopt_init(&sopt, BTPROTO_SCO, SO_SCO_MTU, 0); | | 644 | sockopt_init(&sopt, BTPROTO_SCO, SO_SCO_MTU, 0); |
645 | (void)sco_getopt(sc->sc_sco, &sopt); | | 645 | (void)sco_getopt(sc->sc_sco, &sopt); |
646 | (void)sockopt_get(&sopt, &sc->sc_mtu, sizeof(sc->sc_mtu)); | | 646 | (void)sockopt_get(&sopt, &sc->sc_mtu, sizeof(sc->sc_mtu)); |
647 | sockopt_destroy(&sopt); | | 647 | sockopt_destroy(&sopt); |
648 | break; | | 648 | break; |
649 | | | 649 | |
650 | default: | | 650 | default: |
651 | UNKNOWN(sc->sc_state); | | 651 | UNKNOWN(sc->sc_state); |
652 | break; | | 652 | break; |
653 | } | | 653 | } |
654 | | | 654 | |
655 | done: | | 655 | done: |
656 | mutex_exit(bt_lock); | | | |
657 | | | | |
658 | DPRINTF("done err=%d, sc_state=%d, sc_mtu=%d\n", | | 656 | DPRINTF("done err=%d, sc_state=%d, sc_mtu=%d\n", |
659 | err, sc->sc_state, sc->sc_mtu); | | 657 | err, sc->sc_state, sc->sc_mtu); |
660 | return err; | | 658 | return err; |
661 | } | | 659 | } |
662 | | | 660 | |
663 | static void | | 661 | static void |
664 | btsco_close(void *hdl) | | 662 | btsco_close(void *hdl) |
665 | { | | 663 | { |
666 | struct btsco_softc *sc = hdl; | | 664 | struct btsco_softc *sc = hdl; |
667 | | | 665 | |
668 | DPRINTF("%s\n", sc->sc_name); | | 666 | DPRINTF("%s\n", sc->sc_name); |
669 | | | 667 | |
670 | mutex_enter(bt_lock); | | 668 | KASSERT(mutex_owned(bt_lock)); |
| | | 669 | |
671 | if (sc->sc_sco != NULL) { | | 670 | if (sc->sc_sco != NULL) { |
672 | sco_disconnect(sc->sc_sco, 0); | | 671 | sco_disconnect(sc->sc_sco, 0); |
673 | sco_detach(&sc->sc_sco); | | 672 | sco_detach(&sc->sc_sco); |
674 | } | | 673 | } |
675 | | | 674 | |
676 | if (sc->sc_sco_l != NULL) { | | 675 | if (sc->sc_sco_l != NULL) { |
677 | sco_detach(&sc->sc_sco_l); | | 676 | sco_detach(&sc->sc_sco_l); |
678 | } | | 677 | } |
679 | mutex_exit(bt_lock); | | | |
680 | | | 678 | |
681 | if (sc->sc_rx_mbuf != NULL) { | | 679 | if (sc->sc_rx_mbuf != NULL) { |
682 | m_freem(sc->sc_rx_mbuf); | | 680 | m_freem(sc->sc_rx_mbuf); |
683 | sc->sc_rx_mbuf = NULL; | | 681 | sc->sc_rx_mbuf = NULL; |
684 | } | | 682 | } |
685 | | | 683 | |
686 | sc->sc_rx_want = 0; | | 684 | sc->sc_rx_want = 0; |
687 | sc->sc_rx_block = NULL; | | 685 | sc->sc_rx_block = NULL; |
688 | sc->sc_rx_intr = NULL; | | 686 | sc->sc_rx_intr = NULL; |
689 | sc->sc_rx_intrarg = NULL; | | 687 | sc->sc_rx_intrarg = NULL; |
690 | | | 688 | |
691 | sc->sc_tx_size = 0; | | 689 | sc->sc_tx_size = 0; |
692 | sc->sc_tx_block = NULL; | | 690 | sc->sc_tx_block = NULL; |