Home | History | Annotate | Line # | Download | only in netbt
sco_socket.c revision 1.11.38.1
      1  1.11.38.1       tls /*	$NetBSD: sco_socket.c,v 1.11.38.1 2014/08/20 00:04:35 tls Exp $	*/
      2        1.1   gdamore 
      3        1.1   gdamore /*-
      4        1.1   gdamore  * Copyright (c) 2006 Itronix Inc.
      5        1.1   gdamore  * All rights reserved.
      6        1.1   gdamore  *
      7        1.1   gdamore  * Redistribution and use in source and binary forms, with or without
      8        1.1   gdamore  * modification, are permitted provided that the following conditions
      9        1.1   gdamore  * are met:
     10        1.1   gdamore  * 1. Redistributions of source code must retain the above copyright
     11        1.1   gdamore  *    notice, this list of conditions and the following disclaimer.
     12        1.1   gdamore  * 2. Redistributions in binary form must reproduce the above copyright
     13        1.1   gdamore  *    notice, this list of conditions and the following disclaimer in the
     14        1.1   gdamore  *    documentation and/or other materials provided with the distribution.
     15        1.1   gdamore  * 3. The name of Itronix Inc. may not be used to endorse
     16        1.1   gdamore  *    or promote products derived from this software without specific
     17        1.1   gdamore  *    prior written permission.
     18        1.1   gdamore  *
     19        1.1   gdamore  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
     20        1.1   gdamore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1   gdamore  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1   gdamore  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
     23        1.1   gdamore  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24        1.1   gdamore  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     25        1.1   gdamore  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
     26        1.1   gdamore  * ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1   gdamore  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1   gdamore  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1   gdamore  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1   gdamore  */
     31        1.1   gdamore 
     32        1.1   gdamore #include <sys/cdefs.h>
     33  1.11.38.1       tls __KERNEL_RCSID(0, "$NetBSD: sco_socket.c,v 1.11.38.1 2014/08/20 00:04:35 tls Exp $");
     34        1.8    plunky 
     35        1.8    plunky /* load symbolic names */
     36        1.8    plunky #ifdef BLUETOOTH_DEBUG
     37        1.8    plunky #define PRUREQUESTS
     38        1.8    plunky #define PRCOREQUESTS
     39        1.8    plunky #endif
     40        1.1   gdamore 
     41        1.1   gdamore #include <sys/param.h>
     42        1.1   gdamore #include <sys/domain.h>
     43        1.1   gdamore #include <sys/kernel.h>
     44        1.1   gdamore #include <sys/mbuf.h>
     45        1.1   gdamore #include <sys/proc.h>
     46        1.1   gdamore #include <sys/protosw.h>
     47        1.1   gdamore #include <sys/socket.h>
     48        1.1   gdamore #include <sys/socketvar.h>
     49        1.1   gdamore #include <sys/systm.h>
     50        1.1   gdamore 
     51        1.1   gdamore #include <netbt/bluetooth.h>
     52        1.1   gdamore #include <netbt/hci.h>
     53        1.1   gdamore #include <netbt/sco.h>
     54        1.1   gdamore 
     55        1.1   gdamore /*******************************************************************************
     56        1.1   gdamore  *
     57        1.1   gdamore  * SCO SOCK_SEQPACKET sockets - low latency audio data
     58        1.1   gdamore  */
     59        1.1   gdamore 
     60        1.1   gdamore static void sco_connecting(void *);
     61        1.1   gdamore static void sco_connected(void *);
     62        1.1   gdamore static void sco_disconnected(void *, int);
     63        1.1   gdamore static void *sco_newconn(void *, struct sockaddr_bt *, struct sockaddr_bt *);
     64        1.1   gdamore static void sco_complete(void *, int);
     65        1.9    plunky static void sco_linkmode(void *, int);
     66        1.1   gdamore static void sco_input(void *, struct mbuf *);
     67        1.1   gdamore 
     68        1.1   gdamore static const struct btproto sco_proto = {
     69        1.1   gdamore 	sco_connecting,
     70        1.1   gdamore 	sco_connected,
     71        1.1   gdamore 	sco_disconnected,
     72        1.1   gdamore 	sco_newconn,
     73        1.1   gdamore 	sco_complete,
     74        1.9    plunky 	sco_linkmode,
     75        1.1   gdamore 	sco_input,
     76        1.1   gdamore };
     77        1.1   gdamore 
     78        1.1   gdamore int sco_sendspace = 4096;
     79        1.1   gdamore int sco_recvspace = 4096;
     80        1.1   gdamore 
     81  1.11.38.1       tls static int
     82  1.11.38.1       tls sco_attach(struct socket *so, int proto)
     83  1.11.38.1       tls {
     84  1.11.38.1       tls 	int error;
     85  1.11.38.1       tls 
     86  1.11.38.1       tls 	KASSERT(so->so_pcb == NULL);
     87  1.11.38.1       tls 
     88  1.11.38.1       tls 	if (so->so_lock == NULL) {
     89  1.11.38.1       tls 		mutex_obj_hold(bt_lock);
     90  1.11.38.1       tls 		so->so_lock = bt_lock;
     91  1.11.38.1       tls 		solock(so);
     92  1.11.38.1       tls 	}
     93  1.11.38.1       tls 	KASSERT(solocked(so));
     94  1.11.38.1       tls 
     95  1.11.38.1       tls 	error = soreserve(so, sco_sendspace, sco_recvspace);
     96  1.11.38.1       tls 	if (error) {
     97  1.11.38.1       tls 		return error;
     98  1.11.38.1       tls 	}
     99  1.11.38.1       tls 	return sco_attach_pcb((struct sco_pcb **)&so->so_pcb, &sco_proto, so);
    100  1.11.38.1       tls }
    101  1.11.38.1       tls 
    102  1.11.38.1       tls static void
    103  1.11.38.1       tls sco_detach(struct socket *so)
    104  1.11.38.1       tls {
    105  1.11.38.1       tls 	KASSERT(so->so_pcb != NULL);
    106  1.11.38.1       tls 	sco_detach_pcb((struct sco_pcb **)&so->so_pcb);
    107  1.11.38.1       tls 	KASSERT(so->so_pcb == NULL);
    108  1.11.38.1       tls }
    109  1.11.38.1       tls 
    110  1.11.38.1       tls static int
    111  1.11.38.1       tls sco_accept(struct socket *so, struct mbuf *nam)
    112  1.11.38.1       tls {
    113  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    114  1.11.38.1       tls 	struct sockaddr_bt *sa;
    115  1.11.38.1       tls 
    116  1.11.38.1       tls 	KASSERT(solocked(so));
    117  1.11.38.1       tls 	KASSERT(nam != NULL);
    118  1.11.38.1       tls 
    119  1.11.38.1       tls 	if (pcb == NULL)
    120  1.11.38.1       tls 		return EINVAL;
    121  1.11.38.1       tls 
    122  1.11.38.1       tls 	sa = mtod(nam, struct sockaddr_bt *);
    123  1.11.38.1       tls 	nam->m_len = sizeof(struct sockaddr_bt);
    124  1.11.38.1       tls 	return sco_peeraddr_pcb(pcb, sa);
    125  1.11.38.1       tls }
    126  1.11.38.1       tls 
    127  1.11.38.1       tls static int
    128  1.11.38.1       tls sco_bind(struct socket *so, struct mbuf *nam, struct lwp *l)
    129  1.11.38.1       tls {
    130  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    131  1.11.38.1       tls 	struct sockaddr_bt *sa;
    132  1.11.38.1       tls 
    133  1.11.38.1       tls 	KASSERT(solocked(so));
    134  1.11.38.1       tls 	KASSERT(nam != NULL);
    135  1.11.38.1       tls 
    136  1.11.38.1       tls 	if (pcb == NULL)
    137  1.11.38.1       tls 		return EINVAL;
    138  1.11.38.1       tls 
    139  1.11.38.1       tls 	sa = mtod(nam, struct sockaddr_bt *);
    140  1.11.38.1       tls 	if (sa->bt_len != sizeof(struct sockaddr_bt))
    141  1.11.38.1       tls 		return EINVAL;
    142  1.11.38.1       tls 
    143  1.11.38.1       tls 	if (sa->bt_family != AF_BLUETOOTH)
    144  1.11.38.1       tls 		return EAFNOSUPPORT;
    145  1.11.38.1       tls 
    146  1.11.38.1       tls 	return sco_bind_pcb(pcb, sa);
    147  1.11.38.1       tls }
    148  1.11.38.1       tls 
    149  1.11.38.1       tls static int
    150  1.11.38.1       tls sco_listen(struct socket *so, struct lwp *l)
    151  1.11.38.1       tls {
    152  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    153  1.11.38.1       tls 
    154  1.11.38.1       tls 	KASSERT(solocked(so));
    155  1.11.38.1       tls 
    156  1.11.38.1       tls 	if (pcb == NULL)
    157  1.11.38.1       tls 		return EINVAL;
    158  1.11.38.1       tls 
    159  1.11.38.1       tls 	return sco_listen_pcb(pcb);
    160  1.11.38.1       tls }
    161  1.11.38.1       tls 
    162  1.11.38.1       tls static int
    163  1.11.38.1       tls sco_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
    164  1.11.38.1       tls {
    165  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    166  1.11.38.1       tls 	struct sockaddr_bt *sa;
    167  1.11.38.1       tls 
    168  1.11.38.1       tls 	KASSERT(solocked(so));
    169  1.11.38.1       tls 	KASSERT(nam != NULL);
    170  1.11.38.1       tls 
    171  1.11.38.1       tls 	if (pcb == NULL)
    172  1.11.38.1       tls 		return EINVAL;
    173  1.11.38.1       tls 
    174  1.11.38.1       tls 	sa = mtod(nam, struct sockaddr_bt *);
    175  1.11.38.1       tls 	if (sa->bt_len != sizeof(struct sockaddr_bt))
    176  1.11.38.1       tls 		return EINVAL;
    177  1.11.38.1       tls 
    178  1.11.38.1       tls 	if (sa->bt_family != AF_BLUETOOTH)
    179  1.11.38.1       tls 		return EAFNOSUPPORT;
    180  1.11.38.1       tls 
    181  1.11.38.1       tls 	soisconnecting(so);
    182  1.11.38.1       tls 	return sco_connect_pcb(pcb, sa);
    183  1.11.38.1       tls }
    184  1.11.38.1       tls 
    185  1.11.38.1       tls static int
    186  1.11.38.1       tls sco_connect2(struct socket *so, struct socket *so2)
    187  1.11.38.1       tls {
    188  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    189  1.11.38.1       tls 
    190  1.11.38.1       tls 	KASSERT(solocked(so));
    191  1.11.38.1       tls 
    192  1.11.38.1       tls 	if (pcb == NULL)
    193  1.11.38.1       tls 		return EINVAL;
    194  1.11.38.1       tls 
    195  1.11.38.1       tls 	return EOPNOTSUPP;
    196  1.11.38.1       tls }
    197  1.11.38.1       tls 
    198  1.11.38.1       tls static int
    199  1.11.38.1       tls sco_disconnect(struct socket *so)
    200  1.11.38.1       tls {
    201  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    202  1.11.38.1       tls 
    203  1.11.38.1       tls 	KASSERT(solocked(so));
    204  1.11.38.1       tls 
    205  1.11.38.1       tls 	if (pcb == NULL)
    206  1.11.38.1       tls 		return EINVAL;
    207  1.11.38.1       tls 
    208  1.11.38.1       tls 	soisdisconnecting(so);
    209  1.11.38.1       tls 	return sco_disconnect_pcb(pcb, so->so_linger);
    210  1.11.38.1       tls }
    211  1.11.38.1       tls 
    212  1.11.38.1       tls static int
    213  1.11.38.1       tls sco_shutdown(struct socket *so)
    214  1.11.38.1       tls {
    215  1.11.38.1       tls 	KASSERT(solocked(so));
    216  1.11.38.1       tls 
    217  1.11.38.1       tls 	socantsendmore(so);
    218  1.11.38.1       tls 	return 0;
    219  1.11.38.1       tls }
    220  1.11.38.1       tls 
    221  1.11.38.1       tls static int
    222  1.11.38.1       tls sco_abort(struct socket *so)
    223  1.11.38.1       tls {
    224  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    225  1.11.38.1       tls 
    226  1.11.38.1       tls 	KASSERT(solocked(so));
    227  1.11.38.1       tls 
    228  1.11.38.1       tls 	if (pcb == NULL)
    229  1.11.38.1       tls 		return EINVAL;
    230  1.11.38.1       tls 
    231  1.11.38.1       tls 	sco_disconnect_pcb(pcb, 0);
    232  1.11.38.1       tls 	soisdisconnected(so);
    233  1.11.38.1       tls 	sco_detach(so);
    234  1.11.38.1       tls 	return 0;
    235  1.11.38.1       tls }
    236  1.11.38.1       tls 
    237  1.11.38.1       tls static int
    238  1.11.38.1       tls sco_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
    239  1.11.38.1       tls {
    240  1.11.38.1       tls 	return EOPNOTSUPP;
    241  1.11.38.1       tls }
    242  1.11.38.1       tls 
    243  1.11.38.1       tls static int
    244  1.11.38.1       tls sco_stat(struct socket *so, struct stat *ub)
    245  1.11.38.1       tls {
    246  1.11.38.1       tls 	KASSERT(solocked(so));
    247  1.11.38.1       tls 
    248  1.11.38.1       tls 	return 0;
    249  1.11.38.1       tls }
    250  1.11.38.1       tls 
    251  1.11.38.1       tls static int
    252  1.11.38.1       tls sco_peeraddr(struct socket *so, struct mbuf *nam)
    253  1.11.38.1       tls {
    254  1.11.38.1       tls 	struct sco_pcb *pcb = (struct sco_pcb *)so->so_pcb;
    255  1.11.38.1       tls 	struct sockaddr_bt *sa;
    256  1.11.38.1       tls 
    257  1.11.38.1       tls 	KASSERT(solocked(so));
    258  1.11.38.1       tls 	KASSERT(pcb != NULL);
    259  1.11.38.1       tls 	KASSERT(nam != NULL);
    260  1.11.38.1       tls 
    261  1.11.38.1       tls 	sa = mtod(nam, struct sockaddr_bt *);
    262  1.11.38.1       tls 	nam->m_len = sizeof(struct sockaddr_bt);
    263  1.11.38.1       tls 	return sco_peeraddr_pcb(pcb, sa);
    264  1.11.38.1       tls }
    265  1.11.38.1       tls 
    266  1.11.38.1       tls static int
    267  1.11.38.1       tls sco_sockaddr(struct socket *so, struct mbuf *nam)
    268  1.11.38.1       tls {
    269  1.11.38.1       tls 	struct sco_pcb *pcb = (struct sco_pcb *)so->so_pcb;
    270  1.11.38.1       tls 	struct sockaddr_bt *sa;
    271  1.11.38.1       tls 
    272  1.11.38.1       tls 	KASSERT(solocked(so));
    273  1.11.38.1       tls 	KASSERT(pcb != NULL);
    274  1.11.38.1       tls 	KASSERT(nam != NULL);
    275  1.11.38.1       tls 
    276  1.11.38.1       tls 	sa = mtod(nam, struct sockaddr_bt *);
    277  1.11.38.1       tls 	nam->m_len = sizeof(struct sockaddr_bt);
    278  1.11.38.1       tls 	return sco_sockaddr_pcb(pcb, sa);
    279  1.11.38.1       tls }
    280  1.11.38.1       tls 
    281  1.11.38.1       tls static int
    282  1.11.38.1       tls sco_rcvd(struct socket *so, int flags, struct lwp *l)
    283  1.11.38.1       tls {
    284  1.11.38.1       tls 	KASSERT(solocked(so));
    285  1.11.38.1       tls 
    286  1.11.38.1       tls 	return EOPNOTSUPP;
    287  1.11.38.1       tls }
    288  1.11.38.1       tls 
    289  1.11.38.1       tls static int
    290  1.11.38.1       tls sco_recvoob(struct socket *so, struct mbuf *m, int flags)
    291  1.11.38.1       tls {
    292  1.11.38.1       tls 	KASSERT(solocked(so));
    293  1.11.38.1       tls 
    294  1.11.38.1       tls 	return EOPNOTSUPP;
    295  1.11.38.1       tls }
    296  1.11.38.1       tls 
    297  1.11.38.1       tls static int
    298  1.11.38.1       tls sco_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
    299  1.11.38.1       tls     struct mbuf *control, struct lwp *l)
    300  1.11.38.1       tls {
    301  1.11.38.1       tls 	struct sco_pcb *pcb = so->so_pcb;
    302  1.11.38.1       tls 	int err = 0;
    303  1.11.38.1       tls 	struct mbuf *m0;
    304  1.11.38.1       tls 
    305  1.11.38.1       tls 	KASSERT(solocked(so));
    306  1.11.38.1       tls 	KASSERT(m != NULL);
    307  1.11.38.1       tls 
    308  1.11.38.1       tls 	if (control) /* no use for that */
    309  1.11.38.1       tls 		m_freem(control);
    310  1.11.38.1       tls 
    311  1.11.38.1       tls 	if (pcb == NULL) {
    312  1.11.38.1       tls 		err = EINVAL;
    313  1.11.38.1       tls 		goto release;
    314  1.11.38.1       tls 	}
    315  1.11.38.1       tls 
    316  1.11.38.1       tls 	if (m->m_pkthdr.len == 0)
    317  1.11.38.1       tls 		goto release;
    318  1.11.38.1       tls 
    319  1.11.38.1       tls 	if (m->m_pkthdr.len > pcb->sp_mtu) {
    320  1.11.38.1       tls 		err = EMSGSIZE;
    321  1.11.38.1       tls 		goto release;
    322  1.11.38.1       tls 	}
    323  1.11.38.1       tls 
    324  1.11.38.1       tls 	m0 = m_copypacket(m, M_DONTWAIT);
    325  1.11.38.1       tls 	if (m0 == NULL) {
    326  1.11.38.1       tls 		err = ENOMEM;
    327  1.11.38.1       tls 		goto release;
    328  1.11.38.1       tls 	}
    329  1.11.38.1       tls 
    330  1.11.38.1       tls 	sbappendrecord(&so->so_snd, m);
    331  1.11.38.1       tls 	return sco_send_pcb(pcb, m0);
    332  1.11.38.1       tls 
    333  1.11.38.1       tls release:
    334  1.11.38.1       tls 	m_freem(m);
    335  1.11.38.1       tls 	return err;
    336  1.11.38.1       tls }
    337  1.11.38.1       tls 
    338  1.11.38.1       tls static int
    339  1.11.38.1       tls sco_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control)
    340  1.11.38.1       tls {
    341  1.11.38.1       tls 	KASSERT(solocked(so));
    342  1.11.38.1       tls 
    343  1.11.38.1       tls 	if (m)
    344  1.11.38.1       tls 		m_freem(m);
    345  1.11.38.1       tls 	if (control)
    346  1.11.38.1       tls 		m_freem(control);
    347  1.11.38.1       tls 
    348  1.11.38.1       tls 	return EOPNOTSUPP;
    349  1.11.38.1       tls }
    350  1.11.38.1       tls 
    351  1.11.38.1       tls static int
    352  1.11.38.1       tls sco_purgeif(struct socket *so, struct ifnet *ifp)
    353  1.11.38.1       tls {
    354  1.11.38.1       tls 
    355  1.11.38.1       tls 	return EOPNOTSUPP;
    356  1.11.38.1       tls }
    357  1.11.38.1       tls 
    358        1.1   gdamore /*
    359        1.1   gdamore  * User Request.
    360        1.1   gdamore  * up is socket
    361  1.11.38.1       tls  * m is optional mbuf chain containing message
    362  1.11.38.1       tls  * nam is optional mbuf chain containing an address
    363        1.1   gdamore  * ctl is optional mbuf chain containing socket options
    364        1.1   gdamore  * l is pointer to process requesting action (if any)
    365        1.1   gdamore  *
    366        1.1   gdamore  * we are responsible for disposing of m and ctl if
    367        1.1   gdamore  * they are mbuf chains
    368        1.1   gdamore  */
    369  1.11.38.1       tls static int
    370        1.1   gdamore sco_usrreq(struct socket *up, int req, struct mbuf *m,
    371        1.5  christos     struct mbuf *nam, struct mbuf *ctl, struct lwp *l)
    372        1.1   gdamore {
    373  1.11.38.1       tls 	struct sco_pcb *pcb = up->so_pcb;
    374        1.1   gdamore 	int err = 0;
    375        1.1   gdamore 
    376        1.1   gdamore 	DPRINTFN(2, "%s\n", prurequests[req]);
    377  1.11.38.1       tls 	KASSERT(req != PRU_ATTACH);
    378  1.11.38.1       tls 	KASSERT(req != PRU_DETACH);
    379  1.11.38.1       tls 	KASSERT(req != PRU_ACCEPT);
    380  1.11.38.1       tls 	KASSERT(req != PRU_BIND);
    381  1.11.38.1       tls 	KASSERT(req != PRU_LISTEN);
    382  1.11.38.1       tls 	KASSERT(req != PRU_CONNECT);
    383  1.11.38.1       tls 	KASSERT(req != PRU_CONNECT2);
    384  1.11.38.1       tls 	KASSERT(req != PRU_DISCONNECT);
    385  1.11.38.1       tls 	KASSERT(req != PRU_SHUTDOWN);
    386  1.11.38.1       tls 	KASSERT(req != PRU_ABORT);
    387  1.11.38.1       tls 	KASSERT(req != PRU_CONTROL);
    388  1.11.38.1       tls 	KASSERT(req != PRU_SENSE);
    389  1.11.38.1       tls 	KASSERT(req != PRU_PEERADDR);
    390  1.11.38.1       tls 	KASSERT(req != PRU_SOCKADDR);
    391  1.11.38.1       tls 	KASSERT(req != PRU_RCVD);
    392  1.11.38.1       tls 	KASSERT(req != PRU_RCVOOB);
    393  1.11.38.1       tls 	KASSERT(req != PRU_SEND);
    394  1.11.38.1       tls 	KASSERT(req != PRU_SENDOOB);
    395  1.11.38.1       tls 	KASSERT(req != PRU_PURGEIF);
    396        1.1   gdamore 
    397        1.1   gdamore 	/* anything after here *requires* a pcb */
    398        1.1   gdamore 	if (pcb == NULL) {
    399        1.1   gdamore 		err = EINVAL;
    400        1.1   gdamore 		goto release;
    401        1.1   gdamore 	}
    402        1.1   gdamore 
    403        1.1   gdamore 	switch(req) {
    404        1.1   gdamore 	case PRU_FASTTIMO:
    405        1.1   gdamore 	case PRU_SLOWTIMO:
    406        1.1   gdamore 	case PRU_PROTORCV:
    407        1.1   gdamore 	case PRU_PROTOSEND:
    408        1.1   gdamore 		err = EOPNOTSUPP;
    409        1.1   gdamore 		break;
    410        1.1   gdamore 
    411        1.1   gdamore 	default:
    412        1.1   gdamore 		UNKNOWN(req);
    413        1.1   gdamore 		err = EOPNOTSUPP;
    414        1.1   gdamore 		break;
    415        1.1   gdamore 	}
    416        1.1   gdamore 
    417        1.1   gdamore release:
    418        1.1   gdamore 	if (m) m_freem(m);
    419        1.1   gdamore 	if (ctl) m_freem(ctl);
    420        1.1   gdamore 	return err;
    421        1.1   gdamore }
    422        1.1   gdamore 
    423        1.1   gdamore /*
    424        1.1   gdamore  * get/set socket options
    425        1.1   gdamore  */
    426        1.1   gdamore int
    427       1.11    plunky sco_ctloutput(int req, struct socket *so, struct sockopt *sopt)
    428        1.1   gdamore {
    429        1.1   gdamore 	struct sco_pcb *pcb = (struct sco_pcb *)so->so_pcb;
    430        1.1   gdamore 	int err = 0;
    431        1.1   gdamore 
    432        1.1   gdamore 	DPRINTFN(2, "req %s\n", prcorequests[req]);
    433        1.1   gdamore 
    434        1.1   gdamore 	if (pcb == NULL)
    435        1.1   gdamore 		return EINVAL;
    436        1.1   gdamore 
    437       1.11    plunky 	if (sopt->sopt_level != BTPROTO_SCO)
    438        1.6    plunky 		return ENOPROTOOPT;
    439        1.1   gdamore 
    440        1.1   gdamore 	switch(req) {
    441        1.1   gdamore 	case PRCO_GETOPT:
    442       1.11    plunky 		err = sco_getopt(pcb, sopt);
    443        1.1   gdamore 		break;
    444        1.1   gdamore 
    445        1.1   gdamore 	case PRCO_SETOPT:
    446       1.11    plunky 		err = sco_setopt(pcb, sopt);
    447        1.1   gdamore 		break;
    448        1.1   gdamore 
    449        1.1   gdamore 	default:
    450        1.6    plunky 		err = ENOPROTOOPT;
    451        1.1   gdamore 		break;
    452        1.1   gdamore 	}
    453        1.1   gdamore 
    454        1.1   gdamore 	return err;
    455        1.1   gdamore }
    456        1.1   gdamore 
    457        1.1   gdamore /*****************************************************************************
    458        1.1   gdamore  *
    459        1.1   gdamore  *	SCO Protocol socket callbacks
    460        1.1   gdamore  *
    461        1.1   gdamore  */
    462        1.1   gdamore static void
    463        1.1   gdamore sco_connecting(void *arg)
    464        1.1   gdamore {
    465        1.1   gdamore 	struct socket *so = arg;
    466        1.1   gdamore 
    467        1.1   gdamore 	DPRINTF("Connecting\n");
    468        1.1   gdamore 	soisconnecting(so);
    469        1.1   gdamore }
    470        1.1   gdamore 
    471        1.1   gdamore static void
    472        1.1   gdamore sco_connected(void *arg)
    473        1.1   gdamore {
    474        1.1   gdamore 	struct socket *so = arg;
    475        1.1   gdamore 
    476        1.1   gdamore 	DPRINTF("Connected\n");
    477        1.1   gdamore 	soisconnected(so);
    478        1.1   gdamore }
    479        1.1   gdamore 
    480        1.1   gdamore static void
    481        1.1   gdamore sco_disconnected(void *arg, int err)
    482        1.1   gdamore {
    483        1.1   gdamore 	struct socket *so = arg;
    484        1.1   gdamore 
    485        1.1   gdamore 	DPRINTF("Disconnected (%d)\n", err);
    486        1.1   gdamore 
    487        1.1   gdamore 	so->so_error = err;
    488        1.1   gdamore 	soisdisconnected(so);
    489        1.1   gdamore }
    490        1.1   gdamore 
    491        1.1   gdamore static void *
    492        1.5  christos sco_newconn(void *arg, struct sockaddr_bt *laddr,
    493        1.5  christos     struct sockaddr_bt *raddr)
    494        1.1   gdamore {
    495        1.2      tron 	struct socket *so = arg;
    496        1.1   gdamore 
    497        1.3    plunky 	DPRINTF("New Connection\n");
    498  1.11.38.1       tls 	so = sonewconn(so, false);
    499        1.2      tron 	if (so == NULL)
    500        1.2      tron 		return NULL;
    501        1.2      tron 
    502        1.2      tron 	soisconnecting(so);
    503        1.2      tron 	return so->so_pcb;
    504        1.1   gdamore }
    505        1.1   gdamore 
    506        1.1   gdamore static void
    507        1.1   gdamore sco_complete(void *arg, int num)
    508        1.1   gdamore {
    509        1.1   gdamore 	struct socket *so = arg;
    510        1.1   gdamore 
    511        1.1   gdamore 	while (num-- > 0)
    512        1.1   gdamore 		sbdroprecord(&so->so_snd);
    513        1.1   gdamore 
    514        1.1   gdamore 	sowwakeup(so);
    515        1.1   gdamore }
    516        1.1   gdamore 
    517        1.1   gdamore static void
    518        1.9    plunky sco_linkmode(void *arg, int mode)
    519        1.9    plunky {
    520        1.9    plunky }
    521        1.9    plunky 
    522        1.9    plunky static void
    523        1.1   gdamore sco_input(void *arg, struct mbuf *m)
    524        1.1   gdamore {
    525        1.1   gdamore 	struct socket *so = arg;
    526        1.1   gdamore 
    527        1.1   gdamore 	/*
    528        1.1   gdamore 	 * since this data is time sensitive, if the buffer
    529        1.1   gdamore 	 * is full we just dump data until the latest one
    530        1.1   gdamore 	 * will fit.
    531        1.1   gdamore 	 */
    532        1.1   gdamore 
    533        1.1   gdamore 	while (m->m_pkthdr.len > sbspace(&so->so_rcv))
    534        1.1   gdamore 		sbdroprecord(&so->so_rcv);
    535        1.1   gdamore 
    536        1.1   gdamore 	DPRINTFN(10, "received %d bytes\n", m->m_pkthdr.len);
    537        1.1   gdamore 
    538        1.1   gdamore 	sbappendrecord(&so->so_rcv, m);
    539        1.1   gdamore 	sorwakeup(so);
    540        1.1   gdamore }
    541  1.11.38.1       tls 
    542  1.11.38.1       tls PR_WRAP_USRREQS(sco)
    543  1.11.38.1       tls 
    544  1.11.38.1       tls #define	sco_attach		sco_attach_wrapper
    545  1.11.38.1       tls #define	sco_detach		sco_detach_wrapper
    546  1.11.38.1       tls #define	sco_accept		sco_accept_wrapper
    547  1.11.38.1       tls #define	sco_bind		sco_bind_wrapper
    548  1.11.38.1       tls #define	sco_listen		sco_listen_wrapper
    549  1.11.38.1       tls #define	sco_connect		sco_connect_wrapper
    550  1.11.38.1       tls #define	sco_connect2		sco_connect2_wrapper
    551  1.11.38.1       tls #define	sco_disconnect		sco_disconnect_wrapper
    552  1.11.38.1       tls #define	sco_shutdown		sco_shutdown_wrapper
    553  1.11.38.1       tls #define	sco_abort		sco_abort_wrapper
    554  1.11.38.1       tls #define	sco_ioctl		sco_ioctl_wrapper
    555  1.11.38.1       tls #define	sco_stat		sco_stat_wrapper
    556  1.11.38.1       tls #define	sco_peeraddr		sco_peeraddr_wrapper
    557  1.11.38.1       tls #define	sco_sockaddr		sco_sockaddr_wrapper
    558  1.11.38.1       tls #define	sco_rcvd		sco_rcvd_wrapper
    559  1.11.38.1       tls #define	sco_recvoob		sco_recvoob_wrapper
    560  1.11.38.1       tls #define	sco_send		sco_send_wrapper
    561  1.11.38.1       tls #define	sco_sendoob		sco_sendoob_wrapper
    562  1.11.38.1       tls #define	sco_purgeif		sco_purgeif_wrapper
    563  1.11.38.1       tls #define	sco_usrreq		sco_usrreq_wrapper
    564  1.11.38.1       tls 
    565  1.11.38.1       tls const struct pr_usrreqs sco_usrreqs = {
    566  1.11.38.1       tls 	.pr_attach	= sco_attach,
    567  1.11.38.1       tls 	.pr_detach	= sco_detach,
    568  1.11.38.1       tls 	.pr_accept	= sco_accept,
    569  1.11.38.1       tls 	.pr_bind	= sco_bind,
    570  1.11.38.1       tls 	.pr_listen	= sco_listen,
    571  1.11.38.1       tls 	.pr_connect	= sco_connect,
    572  1.11.38.1       tls 	.pr_connect2	= sco_connect2,
    573  1.11.38.1       tls 	.pr_disconnect	= sco_disconnect,
    574  1.11.38.1       tls 	.pr_shutdown	= sco_shutdown,
    575  1.11.38.1       tls 	.pr_abort	= sco_abort,
    576  1.11.38.1       tls 	.pr_ioctl	= sco_ioctl,
    577  1.11.38.1       tls 	.pr_stat	= sco_stat,
    578  1.11.38.1       tls 	.pr_peeraddr	= sco_peeraddr,
    579  1.11.38.1       tls 	.pr_sockaddr	= sco_sockaddr,
    580  1.11.38.1       tls 	.pr_rcvd	= sco_rcvd,
    581  1.11.38.1       tls 	.pr_recvoob	= sco_recvoob,
    582  1.11.38.1       tls 	.pr_send	= sco_send,
    583  1.11.38.1       tls 	.pr_sendoob	= sco_sendoob,
    584  1.11.38.1       tls 	.pr_purgeif	= sco_purgeif,
    585  1.11.38.1       tls 	.pr_generic	= sco_usrreq,
    586  1.11.38.1       tls };
    587