Home | History | Annotate | Line # | Download | only in netbt
sco_socket.c revision 1.33.6.1
      1  1.33.6.1   msaitoh /*	$NetBSD: sco_socket.c,v 1.33.6.1 2019/01/29 08:09:00 msaitoh 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.33.6.1   msaitoh __KERNEL_RCSID(0, "$NetBSD: sco_socket.c,v 1.33.6.1 2019/01/29 08:09:00 msaitoh 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.14     rmind static int
     82      1.16     rmind sco_attach(struct socket *so, int proto)
     83      1.14     rmind {
     84      1.14     rmind 	int error;
     85      1.14     rmind 
     86      1.14     rmind 	KASSERT(so->so_pcb == NULL);
     87      1.14     rmind 
     88      1.14     rmind 	if (so->so_lock == NULL) {
     89      1.14     rmind 		mutex_obj_hold(bt_lock);
     90      1.14     rmind 		so->so_lock = bt_lock;
     91      1.14     rmind 		solock(so);
     92      1.14     rmind 	}
     93      1.14     rmind 	KASSERT(solocked(so));
     94      1.14     rmind 
     95      1.14     rmind 	error = soreserve(so, sco_sendspace, sco_recvspace);
     96      1.14     rmind 	if (error) {
     97      1.14     rmind 		return error;
     98      1.14     rmind 	}
     99      1.16     rmind 	return sco_attach_pcb((struct sco_pcb **)&so->so_pcb, &sco_proto, so);
    100      1.14     rmind }
    101      1.14     rmind 
    102      1.14     rmind static void
    103      1.16     rmind sco_detach(struct socket *so)
    104      1.14     rmind {
    105      1.15    martin 	KASSERT(so->so_pcb != NULL);
    106      1.16     rmind 	sco_detach_pcb((struct sco_pcb **)&so->so_pcb);
    107      1.14     rmind 	KASSERT(so->so_pcb == NULL);
    108      1.14     rmind }
    109      1.14     rmind 
    110      1.18       rtr static int
    111      1.25       rtr sco_accept(struct socket *so, struct mbuf *nam)
    112      1.25       rtr {
    113      1.25       rtr 	struct sco_pcb *pcb = so->so_pcb;
    114      1.25       rtr 	struct sockaddr_bt *sa;
    115      1.25       rtr 
    116      1.25       rtr 	KASSERT(solocked(so));
    117      1.25       rtr 	KASSERT(nam != NULL);
    118      1.25       rtr 
    119      1.25       rtr 	if (pcb == NULL)
    120      1.25       rtr 		return EINVAL;
    121      1.25       rtr 
    122      1.25       rtr 	sa = mtod(nam, struct sockaddr_bt *);
    123      1.25       rtr 	nam->m_len = sizeof(struct sockaddr_bt);
    124      1.25       rtr 	return sco_peeraddr_pcb(pcb, sa);
    125      1.25       rtr }
    126      1.25       rtr 
    127      1.25       rtr static int
    128      1.30       rtr sco_bind(struct socket *so, struct mbuf *nam, struct lwp *l)
    129      1.27       rtr {
    130      1.27       rtr 	struct sco_pcb *pcb = so->so_pcb;
    131      1.27       rtr 	struct sockaddr_bt *sa;
    132      1.27       rtr 
    133      1.27       rtr 	KASSERT(solocked(so));
    134      1.27       rtr 	KASSERT(nam != NULL);
    135      1.27       rtr 
    136      1.27       rtr 	if (pcb == NULL)
    137      1.27       rtr 		return EINVAL;
    138      1.27       rtr 
    139      1.27       rtr 	sa = mtod(nam, struct sockaddr_bt *);
    140      1.27       rtr 	if (sa->bt_len != sizeof(struct sockaddr_bt))
    141      1.27       rtr 		return EINVAL;
    142      1.27       rtr 
    143      1.27       rtr 	if (sa->bt_family != AF_BLUETOOTH)
    144      1.27       rtr 		return EAFNOSUPPORT;
    145      1.27       rtr 
    146      1.27       rtr 	return sco_bind_pcb(pcb, sa);
    147      1.27       rtr }
    148      1.27       rtr 
    149      1.27       rtr static int
    150      1.30       rtr sco_listen(struct socket *so, struct lwp *l)
    151      1.27       rtr {
    152      1.27       rtr 	struct sco_pcb *pcb = so->so_pcb;
    153      1.27       rtr 
    154      1.27       rtr 	KASSERT(solocked(so));
    155      1.27       rtr 
    156      1.27       rtr 	if (pcb == NULL)
    157      1.27       rtr 		return EINVAL;
    158      1.27       rtr 
    159      1.27       rtr 	return sco_listen_pcb(pcb);
    160      1.27       rtr }
    161      1.27       rtr 
    162      1.27       rtr static int
    163      1.30       rtr sco_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
    164      1.28       rtr {
    165      1.28       rtr 	struct sco_pcb *pcb = so->so_pcb;
    166      1.28       rtr 	struct sockaddr_bt *sa;
    167      1.28       rtr 
    168      1.28       rtr 	KASSERT(solocked(so));
    169      1.28       rtr 	KASSERT(nam != NULL);
    170      1.28       rtr 
    171      1.28       rtr 	if (pcb == NULL)
    172      1.28       rtr 		return EINVAL;
    173      1.28       rtr 
    174      1.28       rtr 	sa = mtod(nam, struct sockaddr_bt *);
    175      1.28       rtr 	if (sa->bt_len != sizeof(struct sockaddr_bt))
    176      1.28       rtr 		return EINVAL;
    177      1.28       rtr 
    178      1.28       rtr 	if (sa->bt_family != AF_BLUETOOTH)
    179      1.28       rtr 		return EAFNOSUPPORT;
    180      1.28       rtr 
    181      1.28       rtr 	soisconnecting(so);
    182      1.28       rtr 	return sco_connect_pcb(pcb, sa);
    183      1.28       rtr }
    184      1.28       rtr 
    185      1.28       rtr static int
    186      1.33       rtr sco_connect2(struct socket *so, struct socket *so2)
    187      1.33       rtr {
    188      1.33       rtr 	struct sco_pcb *pcb = so->so_pcb;
    189      1.33       rtr 
    190      1.33       rtr 	KASSERT(solocked(so));
    191      1.33       rtr 
    192      1.33       rtr 	if (pcb == NULL)
    193      1.33       rtr 		return EINVAL;
    194      1.33       rtr 
    195      1.33       rtr 	return EOPNOTSUPP;
    196      1.33       rtr }
    197      1.33       rtr 
    198      1.33       rtr static int
    199      1.29       rtr sco_disconnect(struct socket *so)
    200      1.29       rtr {
    201      1.29       rtr 	struct sco_pcb *pcb = so->so_pcb;
    202      1.29       rtr 
    203      1.29       rtr 	KASSERT(solocked(so));
    204      1.29       rtr 
    205      1.29       rtr 	if (pcb == NULL)
    206      1.29       rtr 		return EINVAL;
    207      1.29       rtr 
    208      1.29       rtr 	soisdisconnecting(so);
    209      1.29       rtr 	return sco_disconnect_pcb(pcb, so->so_linger);
    210      1.29       rtr }
    211      1.29       rtr 
    212      1.29       rtr static int
    213      1.29       rtr sco_shutdown(struct socket *so)
    214      1.29       rtr {
    215      1.29       rtr 	KASSERT(solocked(so));
    216      1.29       rtr 
    217      1.29       rtr 	socantsendmore(so);
    218      1.29       rtr 	return 0;
    219      1.29       rtr }
    220      1.29       rtr 
    221      1.29       rtr static int
    222      1.29       rtr sco_abort(struct socket *so)
    223      1.29       rtr {
    224      1.29       rtr 	struct sco_pcb *pcb = so->so_pcb;
    225      1.29       rtr 
    226      1.29       rtr 	KASSERT(solocked(so));
    227      1.29       rtr 
    228      1.29       rtr 	if (pcb == NULL)
    229      1.29       rtr 		return EINVAL;
    230      1.29       rtr 
    231      1.29       rtr 	sco_disconnect_pcb(pcb, 0);
    232      1.29       rtr 	soisdisconnected(so);
    233      1.29       rtr 	sco_detach(so);
    234      1.29       rtr 	return 0;
    235      1.29       rtr }
    236      1.29       rtr 
    237      1.29       rtr static int
    238      1.23       rtr sco_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
    239      1.18       rtr {
    240      1.18       rtr 	return EOPNOTSUPP;
    241      1.18       rtr }
    242      1.18       rtr 
    243      1.20       rtr static int
    244      1.20       rtr sco_stat(struct socket *so, struct stat *ub)
    245      1.20       rtr {
    246      1.23       rtr 	KASSERT(solocked(so));
    247      1.23       rtr 
    248      1.22       rtr 	return 0;
    249      1.20       rtr }
    250      1.20       rtr 
    251      1.24       rtr static int
    252      1.24       rtr sco_peeraddr(struct socket *so, struct mbuf *nam)
    253      1.24       rtr {
    254      1.24       rtr 	struct sco_pcb *pcb = (struct sco_pcb *)so->so_pcb;
    255      1.24       rtr 	struct sockaddr_bt *sa;
    256      1.24       rtr 
    257      1.24       rtr 	KASSERT(solocked(so));
    258      1.24       rtr 	KASSERT(pcb != NULL);
    259      1.24       rtr 	KASSERT(nam != NULL);
    260      1.24       rtr 
    261      1.24       rtr 	sa = mtod(nam, struct sockaddr_bt *);
    262      1.24       rtr 	nam->m_len = sizeof(struct sockaddr_bt);
    263      1.24       rtr 	return sco_peeraddr_pcb(pcb, sa);
    264      1.24       rtr }
    265      1.24       rtr 
    266      1.24       rtr static int
    267      1.24       rtr sco_sockaddr(struct socket *so, struct mbuf *nam)
    268      1.24       rtr {
    269      1.24       rtr 	struct sco_pcb *pcb = (struct sco_pcb *)so->so_pcb;
    270      1.24       rtr 	struct sockaddr_bt *sa;
    271      1.24       rtr 
    272      1.24       rtr 	KASSERT(solocked(so));
    273      1.24       rtr 	KASSERT(pcb != NULL);
    274      1.24       rtr 	KASSERT(nam != NULL);
    275      1.24       rtr 
    276      1.24       rtr 	sa = mtod(nam, struct sockaddr_bt *);
    277      1.24       rtr 	nam->m_len = sizeof(struct sockaddr_bt);
    278      1.24       rtr 	return sco_sockaddr_pcb(pcb, sa);
    279      1.24       rtr }
    280      1.24       rtr 
    281      1.26       rtr static int
    282      1.32       rtr sco_rcvd(struct socket *so, int flags, struct lwp *l)
    283      1.32       rtr {
    284      1.32       rtr 	KASSERT(solocked(so));
    285      1.32       rtr 
    286      1.32       rtr 	return EOPNOTSUPP;
    287      1.32       rtr }
    288      1.32       rtr 
    289      1.32       rtr static int
    290      1.26       rtr sco_recvoob(struct socket *so, struct mbuf *m, int flags)
    291      1.26       rtr {
    292      1.26       rtr 	KASSERT(solocked(so));
    293      1.26       rtr 
    294      1.26       rtr 	return EOPNOTSUPP;
    295      1.26       rtr }
    296      1.26       rtr 
    297      1.26       rtr static int
    298      1.31       rtr sco_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
    299      1.31       rtr     struct mbuf *control, struct lwp *l)
    300      1.31       rtr {
    301      1.31       rtr 	struct sco_pcb *pcb = so->so_pcb;
    302      1.31       rtr 	int err = 0;
    303      1.31       rtr 	struct mbuf *m0;
    304      1.31       rtr 
    305      1.31       rtr 	KASSERT(solocked(so));
    306      1.31       rtr 	KASSERT(m != NULL);
    307      1.31       rtr 
    308      1.31       rtr 	if (control) /* no use for that */
    309      1.31       rtr 		m_freem(control);
    310      1.31       rtr 
    311      1.31       rtr 	if (pcb == NULL) {
    312      1.31       rtr 		err = EINVAL;
    313      1.31       rtr 		goto release;
    314      1.31       rtr 	}
    315      1.31       rtr 
    316      1.31       rtr 	if (m->m_pkthdr.len == 0)
    317      1.31       rtr 		goto release;
    318      1.31       rtr 
    319      1.31       rtr 	if (m->m_pkthdr.len > pcb->sp_mtu) {
    320      1.31       rtr 		err = EMSGSIZE;
    321      1.31       rtr 		goto release;
    322      1.31       rtr 	}
    323      1.31       rtr 
    324      1.31       rtr 	m0 = m_copypacket(m, M_DONTWAIT);
    325      1.31       rtr 	if (m0 == NULL) {
    326      1.31       rtr 		err = ENOMEM;
    327      1.31       rtr 		goto release;
    328      1.31       rtr 	}
    329      1.31       rtr 
    330      1.31       rtr 	sbappendrecord(&so->so_snd, m);
    331      1.31       rtr 	return sco_send_pcb(pcb, m0);
    332      1.31       rtr 
    333      1.31       rtr release:
    334      1.31       rtr 	m_freem(m);
    335      1.31       rtr 	return err;
    336      1.31       rtr }
    337      1.31       rtr 
    338      1.31       rtr static int
    339      1.26       rtr sco_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control)
    340      1.26       rtr {
    341      1.26       rtr 	KASSERT(solocked(so));
    342      1.26       rtr 
    343  1.33.6.1   msaitoh 	m_freem(m);
    344  1.33.6.1   msaitoh 	m_freem(control);
    345      1.26       rtr 
    346      1.26       rtr 	return EOPNOTSUPP;
    347      1.26       rtr }
    348      1.26       rtr 
    349      1.33       rtr static int
    350      1.33       rtr sco_purgeif(struct socket *so, struct ifnet *ifp)
    351      1.33       rtr {
    352      1.33       rtr 
    353      1.33       rtr 	return EOPNOTSUPP;
    354      1.33       rtr }
    355      1.33       rtr 
    356       1.1   gdamore /*
    357       1.1   gdamore  * User Request.
    358       1.1   gdamore  * up is socket
    359      1.18       rtr  * m is optional mbuf chain containing message
    360      1.18       rtr  * nam is optional mbuf chain containing an address
    361       1.1   gdamore  * ctl is optional mbuf chain containing socket options
    362       1.1   gdamore  * l is pointer to process requesting action (if any)
    363       1.1   gdamore  *
    364       1.1   gdamore  * we are responsible for disposing of m and ctl if
    365       1.1   gdamore  * they are mbuf chains
    366       1.1   gdamore  */
    367      1.13     rmind static int
    368       1.1   gdamore sco_usrreq(struct socket *up, int req, struct mbuf *m,
    369       1.5  christos     struct mbuf *nam, struct mbuf *ctl, struct lwp *l)
    370       1.1   gdamore {
    371      1.33       rtr 	struct sco_pcb *pcb = up->so_pcb;
    372       1.1   gdamore 	int err = 0;
    373       1.1   gdamore 
    374       1.1   gdamore 	DPRINTFN(2, "%s\n", prurequests[req]);
    375      1.14     rmind 	KASSERT(req != PRU_ATTACH);
    376      1.14     rmind 	KASSERT(req != PRU_DETACH);
    377      1.25       rtr 	KASSERT(req != PRU_ACCEPT);
    378      1.27       rtr 	KASSERT(req != PRU_BIND);
    379      1.27       rtr 	KASSERT(req != PRU_LISTEN);
    380      1.28       rtr 	KASSERT(req != PRU_CONNECT);
    381      1.33       rtr 	KASSERT(req != PRU_CONNECT2);
    382      1.29       rtr 	KASSERT(req != PRU_DISCONNECT);
    383      1.29       rtr 	KASSERT(req != PRU_SHUTDOWN);
    384      1.29       rtr 	KASSERT(req != PRU_ABORT);
    385      1.18       rtr 	KASSERT(req != PRU_CONTROL);
    386      1.20       rtr 	KASSERT(req != PRU_SENSE);
    387      1.24       rtr 	KASSERT(req != PRU_PEERADDR);
    388      1.24       rtr 	KASSERT(req != PRU_SOCKADDR);
    389      1.32       rtr 	KASSERT(req != PRU_RCVD);
    390      1.26       rtr 	KASSERT(req != PRU_RCVOOB);
    391      1.31       rtr 	KASSERT(req != PRU_SEND);
    392      1.26       rtr 	KASSERT(req != PRU_SENDOOB);
    393      1.33       rtr 	KASSERT(req != PRU_PURGEIF);
    394       1.1   gdamore 
    395       1.1   gdamore 	/* anything after here *requires* a pcb */
    396       1.1   gdamore 	if (pcb == NULL) {
    397       1.1   gdamore 		err = EINVAL;
    398       1.1   gdamore 		goto release;
    399       1.1   gdamore 	}
    400       1.1   gdamore 
    401       1.1   gdamore 	switch(req) {
    402       1.1   gdamore 	case PRU_FASTTIMO:
    403       1.1   gdamore 	case PRU_SLOWTIMO:
    404       1.1   gdamore 	case PRU_PROTORCV:
    405       1.1   gdamore 	case PRU_PROTOSEND:
    406       1.1   gdamore 		err = EOPNOTSUPP;
    407       1.1   gdamore 		break;
    408       1.1   gdamore 
    409       1.1   gdamore 	default:
    410       1.1   gdamore 		UNKNOWN(req);
    411       1.1   gdamore 		err = EOPNOTSUPP;
    412       1.1   gdamore 		break;
    413       1.1   gdamore 	}
    414       1.1   gdamore 
    415       1.1   gdamore release:
    416       1.1   gdamore 	if (m) m_freem(m);
    417       1.1   gdamore 	if (ctl) m_freem(ctl);
    418       1.1   gdamore 	return err;
    419       1.1   gdamore }
    420       1.1   gdamore 
    421       1.1   gdamore /*
    422       1.1   gdamore  * get/set socket options
    423       1.1   gdamore  */
    424       1.1   gdamore int
    425      1.11    plunky sco_ctloutput(int req, struct socket *so, struct sockopt *sopt)
    426       1.1   gdamore {
    427       1.1   gdamore 	struct sco_pcb *pcb = (struct sco_pcb *)so->so_pcb;
    428       1.1   gdamore 	int err = 0;
    429       1.1   gdamore 
    430       1.1   gdamore 	DPRINTFN(2, "req %s\n", prcorequests[req]);
    431       1.1   gdamore 
    432       1.1   gdamore 	if (pcb == NULL)
    433       1.1   gdamore 		return EINVAL;
    434       1.1   gdamore 
    435      1.11    plunky 	if (sopt->sopt_level != BTPROTO_SCO)
    436       1.6    plunky 		return ENOPROTOOPT;
    437       1.1   gdamore 
    438       1.1   gdamore 	switch(req) {
    439       1.1   gdamore 	case PRCO_GETOPT:
    440      1.11    plunky 		err = sco_getopt(pcb, sopt);
    441       1.1   gdamore 		break;
    442       1.1   gdamore 
    443       1.1   gdamore 	case PRCO_SETOPT:
    444      1.11    plunky 		err = sco_setopt(pcb, sopt);
    445       1.1   gdamore 		break;
    446       1.1   gdamore 
    447       1.1   gdamore 	default:
    448       1.6    plunky 		err = ENOPROTOOPT;
    449       1.1   gdamore 		break;
    450       1.1   gdamore 	}
    451       1.1   gdamore 
    452       1.1   gdamore 	return err;
    453       1.1   gdamore }
    454       1.1   gdamore 
    455       1.1   gdamore /*****************************************************************************
    456       1.1   gdamore  *
    457       1.1   gdamore  *	SCO Protocol socket callbacks
    458       1.1   gdamore  *
    459       1.1   gdamore  */
    460       1.1   gdamore static void
    461       1.1   gdamore sco_connecting(void *arg)
    462       1.1   gdamore {
    463       1.1   gdamore 	struct socket *so = arg;
    464       1.1   gdamore 
    465       1.1   gdamore 	DPRINTF("Connecting\n");
    466       1.1   gdamore 	soisconnecting(so);
    467       1.1   gdamore }
    468       1.1   gdamore 
    469       1.1   gdamore static void
    470       1.1   gdamore sco_connected(void *arg)
    471       1.1   gdamore {
    472       1.1   gdamore 	struct socket *so = arg;
    473       1.1   gdamore 
    474       1.1   gdamore 	DPRINTF("Connected\n");
    475       1.1   gdamore 	soisconnected(so);
    476       1.1   gdamore }
    477       1.1   gdamore 
    478       1.1   gdamore static void
    479       1.1   gdamore sco_disconnected(void *arg, int err)
    480       1.1   gdamore {
    481       1.1   gdamore 	struct socket *so = arg;
    482       1.1   gdamore 
    483       1.1   gdamore 	DPRINTF("Disconnected (%d)\n", err);
    484       1.1   gdamore 
    485       1.1   gdamore 	so->so_error = err;
    486       1.1   gdamore 	soisdisconnected(so);
    487       1.1   gdamore }
    488       1.1   gdamore 
    489       1.1   gdamore static void *
    490       1.5  christos sco_newconn(void *arg, struct sockaddr_bt *laddr,
    491       1.5  christos     struct sockaddr_bt *raddr)
    492       1.1   gdamore {
    493       1.2      tron 	struct socket *so = arg;
    494       1.1   gdamore 
    495       1.3    plunky 	DPRINTF("New Connection\n");
    496      1.12     rmind 	so = sonewconn(so, false);
    497       1.2      tron 	if (so == NULL)
    498       1.2      tron 		return NULL;
    499       1.2      tron 
    500       1.2      tron 	soisconnecting(so);
    501       1.2      tron 	return so->so_pcb;
    502       1.1   gdamore }
    503       1.1   gdamore 
    504       1.1   gdamore static void
    505       1.1   gdamore sco_complete(void *arg, int num)
    506       1.1   gdamore {
    507       1.1   gdamore 	struct socket *so = arg;
    508       1.1   gdamore 
    509       1.1   gdamore 	while (num-- > 0)
    510       1.1   gdamore 		sbdroprecord(&so->so_snd);
    511       1.1   gdamore 
    512       1.1   gdamore 	sowwakeup(so);
    513       1.1   gdamore }
    514       1.1   gdamore 
    515       1.1   gdamore static void
    516       1.9    plunky sco_linkmode(void *arg, int mode)
    517       1.9    plunky {
    518       1.9    plunky }
    519       1.9    plunky 
    520       1.9    plunky static void
    521       1.1   gdamore sco_input(void *arg, struct mbuf *m)
    522       1.1   gdamore {
    523       1.1   gdamore 	struct socket *so = arg;
    524       1.1   gdamore 
    525       1.1   gdamore 	/*
    526       1.1   gdamore 	 * since this data is time sensitive, if the buffer
    527       1.1   gdamore 	 * is full we just dump data until the latest one
    528       1.1   gdamore 	 * will fit.
    529       1.1   gdamore 	 */
    530       1.1   gdamore 
    531       1.1   gdamore 	while (m->m_pkthdr.len > sbspace(&so->so_rcv))
    532       1.1   gdamore 		sbdroprecord(&so->so_rcv);
    533       1.1   gdamore 
    534       1.1   gdamore 	DPRINTFN(10, "received %d bytes\n", m->m_pkthdr.len);
    535       1.1   gdamore 
    536       1.1   gdamore 	sbappendrecord(&so->so_rcv, m);
    537       1.1   gdamore 	sorwakeup(so);
    538       1.1   gdamore }
    539      1.13     rmind 
    540      1.17     rmind PR_WRAP_USRREQS(sco)
    541      1.13     rmind 
    542      1.17     rmind #define	sco_attach		sco_attach_wrapper
    543      1.17     rmind #define	sco_detach		sco_detach_wrapper
    544      1.25       rtr #define	sco_accept		sco_accept_wrapper
    545      1.27       rtr #define	sco_bind		sco_bind_wrapper
    546      1.27       rtr #define	sco_listen		sco_listen_wrapper
    547      1.28       rtr #define	sco_connect		sco_connect_wrapper
    548      1.33       rtr #define	sco_connect2		sco_connect2_wrapper
    549      1.29       rtr #define	sco_disconnect		sco_disconnect_wrapper
    550      1.29       rtr #define	sco_shutdown		sco_shutdown_wrapper
    551      1.29       rtr #define	sco_abort		sco_abort_wrapper
    552      1.18       rtr #define	sco_ioctl		sco_ioctl_wrapper
    553      1.20       rtr #define	sco_stat		sco_stat_wrapper
    554      1.24       rtr #define	sco_peeraddr		sco_peeraddr_wrapper
    555      1.24       rtr #define	sco_sockaddr		sco_sockaddr_wrapper
    556      1.32       rtr #define	sco_rcvd		sco_rcvd_wrapper
    557      1.26       rtr #define	sco_recvoob		sco_recvoob_wrapper
    558      1.31       rtr #define	sco_send		sco_send_wrapper
    559      1.26       rtr #define	sco_sendoob		sco_sendoob_wrapper
    560      1.33       rtr #define	sco_purgeif		sco_purgeif_wrapper
    561      1.13     rmind #define	sco_usrreq		sco_usrreq_wrapper
    562      1.13     rmind 
    563      1.13     rmind const struct pr_usrreqs sco_usrreqs = {
    564      1.16     rmind 	.pr_attach	= sco_attach,
    565      1.16     rmind 	.pr_detach	= sco_detach,
    566      1.25       rtr 	.pr_accept	= sco_accept,
    567      1.27       rtr 	.pr_bind	= sco_bind,
    568      1.27       rtr 	.pr_listen	= sco_listen,
    569      1.28       rtr 	.pr_connect	= sco_connect,
    570      1.33       rtr 	.pr_connect2	= sco_connect2,
    571      1.29       rtr 	.pr_disconnect	= sco_disconnect,
    572      1.29       rtr 	.pr_shutdown	= sco_shutdown,
    573      1.29       rtr 	.pr_abort	= sco_abort,
    574      1.18       rtr 	.pr_ioctl	= sco_ioctl,
    575      1.20       rtr 	.pr_stat	= sco_stat,
    576      1.24       rtr 	.pr_peeraddr	= sco_peeraddr,
    577      1.24       rtr 	.pr_sockaddr	= sco_sockaddr,
    578      1.32       rtr 	.pr_rcvd	= sco_rcvd,
    579      1.26       rtr 	.pr_recvoob	= sco_recvoob,
    580      1.31       rtr 	.pr_send	= sco_send,
    581      1.26       rtr 	.pr_sendoob	= sco_sendoob,
    582      1.33       rtr 	.pr_purgeif	= sco_purgeif,
    583      1.13     rmind 	.pr_generic	= sco_usrreq,
    584      1.13     rmind };
    585