2014-08-05 11:55:31 +04:00
|
|
|
/* $NetBSD: sco_upper.c,v 1.16 2014/08/05 07:55:32 rtr Exp $ */
|
2006-06-19 19:44:33 +04:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2006 Itronix Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Written by Iain Hibbert for Itronix Inc.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of Itronix Inc. may not be used to endorse
|
|
|
|
* or promote products derived from this software without specific
|
|
|
|
* prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2014-08-05 11:55:31 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: sco_upper.c,v 1.16 2014/08/05 07:55:32 rtr Exp $");
|
2006-06-19 19:44:33 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/proc.h>
|
2008-08-06 19:01:23 +04:00
|
|
|
#include <sys/socketvar.h>
|
2006-06-19 19:44:33 +04:00
|
|
|
#include <sys/systm.h>
|
|
|
|
|
|
|
|
#include <netbt/bluetooth.h>
|
|
|
|
#include <netbt/hci.h>
|
|
|
|
#include <netbt/sco.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
*
|
|
|
|
* SCO - Upper Protocol API
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct sco_pcb_list sco_pcb = LIST_HEAD_INITIALIZER(sco_pcb);
|
|
|
|
|
|
|
|
/*
|
2014-05-20 22:25:54 +04:00
|
|
|
* sco_attach_pcb(handle, proto, upper)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Attach a new instance of SCO pcb to handle
|
|
|
|
*/
|
|
|
|
int
|
2014-05-20 22:25:54 +04:00
|
|
|
sco_attach_pcb(struct sco_pcb **handle,
|
2006-06-19 19:44:33 +04:00
|
|
|
const struct btproto *proto, void *upper)
|
|
|
|
{
|
|
|
|
struct sco_pcb *pcb;
|
|
|
|
|
2007-03-31 00:47:02 +04:00
|
|
|
KASSERT(handle != NULL);
|
|
|
|
KASSERT(proto != NULL);
|
|
|
|
KASSERT(upper != NULL);
|
2006-06-19 19:44:33 +04:00
|
|
|
|
|
|
|
pcb = malloc(sizeof(struct sco_pcb), M_BLUETOOTH,
|
|
|
|
M_NOWAIT | M_ZERO);
|
|
|
|
if (pcb == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
pcb->sp_proto = proto;
|
|
|
|
pcb->sp_upper = upper;
|
|
|
|
|
|
|
|
LIST_INSERT_HEAD(&sco_pcb, pcb, sp_next);
|
|
|
|
|
|
|
|
*handle = pcb;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-07-24 19:12:03 +04:00
|
|
|
* sco_bind_pcb(pcb, sockaddr)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Bind SCO pcb to local address
|
|
|
|
*/
|
|
|
|
int
|
2014-07-24 19:12:03 +04:00
|
|
|
sco_bind_pcb(struct sco_pcb *pcb, struct sockaddr_bt *addr)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
|
2010-01-04 22:20:05 +03:00
|
|
|
if (pcb->sp_link != NULL || pcb->sp_flags & SP_LISTENING)
|
|
|
|
return EINVAL;
|
|
|
|
|
2006-06-19 19:44:33 +04:00
|
|
|
bdaddr_copy(&pcb->sp_laddr, &addr->bt_bdaddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
usrreq switches and put into separate functions
xxx_{peer,sock}addr(struct socket *, struct mbuf *).
- KASSERT(solocked(so)) always in new functions even if request
is not implemented
- KASSERT(pcb != NULL) and KASSERT(nam) if the request is
implemented and not for tcp.
* for tcp roll #ifdef KPROF and #ifdef DEBUG code from tcp_usrreq() into
easier to cut & paste functions tcp_debug_capture() and
tcp_debug_trace()
- functions provided by rmind
- remaining use of PRU_{PEER,SOCK}ADDR #define to be removed in a
future commit.
* rename netbt functions to permit consistency of pru function names
(as has been done with other requests already split out).
- l2cap_{peer,sock}addr() -> l2cap_{peer,sock}_addr_pcb()
- rfcomm_{peer,sock}addr() -> rfcomm_{peer,sock}_addr_pcb()
- sco_{peer,sock}addr() -> sco_{peer,sock}_addr_pcb()
* split/refactor do_sys_getsockname(lwp, fd, which, nam) into
two functions do_sys_get{peer,sock}name(fd, nam).
- move PRU_PEERADDR handling into do_sys_getpeername() from
do_sys_getsockname()
- have svr4_stream directly call do_sys_get{sock,peer}name()
respectively instead of providing `which' & fix a DPRINTF string
that incorrectly wrote "getpeername" when it meant "getsockname"
- fix sys_getpeername() and sys_getsockname() to call
do_sys_get{sock,peer}name() without `which' and `lwp' & adjust
comments
- bump kernel version for removal of lwp & which parameters from
do_sys_getsockname()
note: future cleanup to remove struct mbuf * abuse in
xxx_{peer,sock}name()
still to come, not done in this commit since it is easier to do post
split.
patch reviewed by rmind
welcome to 6.99.47
2014-07-09 08:54:03 +04:00
|
|
|
* sco_sockaddr_pcb(pcb, sockaddr)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Copy local address of PCB to sockaddr
|
|
|
|
*/
|
|
|
|
int
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
usrreq switches and put into separate functions
xxx_{peer,sock}addr(struct socket *, struct mbuf *).
- KASSERT(solocked(so)) always in new functions even if request
is not implemented
- KASSERT(pcb != NULL) and KASSERT(nam) if the request is
implemented and not for tcp.
* for tcp roll #ifdef KPROF and #ifdef DEBUG code from tcp_usrreq() into
easier to cut & paste functions tcp_debug_capture() and
tcp_debug_trace()
- functions provided by rmind
- remaining use of PRU_{PEER,SOCK}ADDR #define to be removed in a
future commit.
* rename netbt functions to permit consistency of pru function names
(as has been done with other requests already split out).
- l2cap_{peer,sock}addr() -> l2cap_{peer,sock}_addr_pcb()
- rfcomm_{peer,sock}addr() -> rfcomm_{peer,sock}_addr_pcb()
- sco_{peer,sock}addr() -> sco_{peer,sock}_addr_pcb()
* split/refactor do_sys_getsockname(lwp, fd, which, nam) into
two functions do_sys_get{peer,sock}name(fd, nam).
- move PRU_PEERADDR handling into do_sys_getpeername() from
do_sys_getsockname()
- have svr4_stream directly call do_sys_get{sock,peer}name()
respectively instead of providing `which' & fix a DPRINTF string
that incorrectly wrote "getpeername" when it meant "getsockname"
- fix sys_getpeername() and sys_getsockname() to call
do_sys_get{sock,peer}name() without `which' and `lwp' & adjust
comments
- bump kernel version for removal of lwp & which parameters from
do_sys_getsockname()
note: future cleanup to remove struct mbuf * abuse in
xxx_{peer,sock}name()
still to come, not done in this commit since it is easier to do post
split.
patch reviewed by rmind
welcome to 6.99.47
2014-07-09 08:54:03 +04:00
|
|
|
sco_sockaddr_pcb(struct sco_pcb *pcb, struct sockaddr_bt *addr)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
memset(addr, 0, sizeof(struct sockaddr_bt));
|
|
|
|
addr->bt_len = sizeof(struct sockaddr_bt);
|
|
|
|
addr->bt_family = AF_BLUETOOTH;
|
|
|
|
bdaddr_copy(&addr->bt_bdaddr, &pcb->sp_laddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-07-30 14:04:25 +04:00
|
|
|
* sco_connect_pcb(pcb, sockaddr)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Initiate a SCO connection to the destination address.
|
|
|
|
*/
|
|
|
|
int
|
2014-07-30 14:04:25 +04:00
|
|
|
sco_connect_pcb(struct sco_pcb *pcb, struct sockaddr_bt *dest)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
hci_add_sco_con_cp cp;
|
|
|
|
struct hci_unit *unit;
|
|
|
|
struct hci_link *acl, *sco;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
if (pcb->sp_flags & SP_LISTENING)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
bdaddr_copy(&pcb->sp_raddr, &dest->bt_bdaddr);
|
|
|
|
|
|
|
|
if (bdaddr_any(&pcb->sp_raddr))
|
|
|
|
return EDESTADDRREQ;
|
|
|
|
|
|
|
|
if (bdaddr_any(&pcb->sp_laddr)) {
|
|
|
|
err = hci_route_lookup(&pcb->sp_laddr, &pcb->sp_raddr);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
unit = hci_unit_lookup(&pcb->sp_laddr);
|
|
|
|
if (unit == NULL)
|
|
|
|
return ENETDOWN;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We must have an already open ACL connection before we open the SCO
|
|
|
|
* connection, and since SCO connections dont happen on their own we
|
|
|
|
* will not open one, the application wanting this should have opened
|
|
|
|
* it previously.
|
|
|
|
*/
|
|
|
|
acl = hci_link_lookup_bdaddr(unit, &pcb->sp_raddr, HCI_LINK_ACL);
|
|
|
|
if (acl == NULL || acl->hl_state != HCI_LINK_OPEN)
|
|
|
|
return EHOSTUNREACH;
|
|
|
|
|
2008-03-17 02:28:10 +03:00
|
|
|
sco = hci_link_alloc(unit, &pcb->sp_raddr, HCI_LINK_SCO);
|
2006-06-19 19:44:33 +04:00
|
|
|
if (sco == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
sco->hl_link = hci_acl_open(unit, &pcb->sp_raddr);
|
|
|
|
KASSERT(sco->hl_link == acl);
|
|
|
|
|
|
|
|
cp.con_handle = htole16(acl->hl_handle);
|
|
|
|
cp.pkt_type = htole16(0x00e0); /* HV1, HV2, HV3 */
|
|
|
|
err = hci_send_cmd(unit, HCI_CMD_ADD_SCO_CON, &cp, sizeof(cp));
|
|
|
|
if (err) {
|
|
|
|
hci_link_free(sco, err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
sco->hl_sco = pcb;
|
|
|
|
pcb->sp_link = sco;
|
|
|
|
|
|
|
|
pcb->sp_mtu = unit->hci_max_sco_size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
usrreq switches and put into separate functions
xxx_{peer,sock}addr(struct socket *, struct mbuf *).
- KASSERT(solocked(so)) always in new functions even if request
is not implemented
- KASSERT(pcb != NULL) and KASSERT(nam) if the request is
implemented and not for tcp.
* for tcp roll #ifdef KPROF and #ifdef DEBUG code from tcp_usrreq() into
easier to cut & paste functions tcp_debug_capture() and
tcp_debug_trace()
- functions provided by rmind
- remaining use of PRU_{PEER,SOCK}ADDR #define to be removed in a
future commit.
* rename netbt functions to permit consistency of pru function names
(as has been done with other requests already split out).
- l2cap_{peer,sock}addr() -> l2cap_{peer,sock}_addr_pcb()
- rfcomm_{peer,sock}addr() -> rfcomm_{peer,sock}_addr_pcb()
- sco_{peer,sock}addr() -> sco_{peer,sock}_addr_pcb()
* split/refactor do_sys_getsockname(lwp, fd, which, nam) into
two functions do_sys_get{peer,sock}name(fd, nam).
- move PRU_PEERADDR handling into do_sys_getpeername() from
do_sys_getsockname()
- have svr4_stream directly call do_sys_get{sock,peer}name()
respectively instead of providing `which' & fix a DPRINTF string
that incorrectly wrote "getpeername" when it meant "getsockname"
- fix sys_getpeername() and sys_getsockname() to call
do_sys_get{sock,peer}name() without `which' and `lwp' & adjust
comments
- bump kernel version for removal of lwp & which parameters from
do_sys_getsockname()
note: future cleanup to remove struct mbuf * abuse in
xxx_{peer,sock}name()
still to come, not done in this commit since it is easier to do post
split.
patch reviewed by rmind
welcome to 6.99.47
2014-07-09 08:54:03 +04:00
|
|
|
* sco_peeraddr_pcb(pcb, sockaddr)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Copy remote address of SCO pcb to sockaddr
|
|
|
|
*/
|
|
|
|
int
|
* split PRU_PEERADDR and PRU_SOCKADDR function out of pr_generic()
usrreq switches and put into separate functions
xxx_{peer,sock}addr(struct socket *, struct mbuf *).
- KASSERT(solocked(so)) always in new functions even if request
is not implemented
- KASSERT(pcb != NULL) and KASSERT(nam) if the request is
implemented and not for tcp.
* for tcp roll #ifdef KPROF and #ifdef DEBUG code from tcp_usrreq() into
easier to cut & paste functions tcp_debug_capture() and
tcp_debug_trace()
- functions provided by rmind
- remaining use of PRU_{PEER,SOCK}ADDR #define to be removed in a
future commit.
* rename netbt functions to permit consistency of pru function names
(as has been done with other requests already split out).
- l2cap_{peer,sock}addr() -> l2cap_{peer,sock}_addr_pcb()
- rfcomm_{peer,sock}addr() -> rfcomm_{peer,sock}_addr_pcb()
- sco_{peer,sock}addr() -> sco_{peer,sock}_addr_pcb()
* split/refactor do_sys_getsockname(lwp, fd, which, nam) into
two functions do_sys_get{peer,sock}name(fd, nam).
- move PRU_PEERADDR handling into do_sys_getpeername() from
do_sys_getsockname()
- have svr4_stream directly call do_sys_get{sock,peer}name()
respectively instead of providing `which' & fix a DPRINTF string
that incorrectly wrote "getpeername" when it meant "getsockname"
- fix sys_getpeername() and sys_getsockname() to call
do_sys_get{sock,peer}name() without `which' and `lwp' & adjust
comments
- bump kernel version for removal of lwp & which parameters from
do_sys_getsockname()
note: future cleanup to remove struct mbuf * abuse in
xxx_{peer,sock}name()
still to come, not done in this commit since it is easier to do post
split.
patch reviewed by rmind
welcome to 6.99.47
2014-07-09 08:54:03 +04:00
|
|
|
sco_peeraddr_pcb(struct sco_pcb *pcb, struct sockaddr_bt *addr)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
memset(addr, 0, sizeof(struct sockaddr_bt));
|
|
|
|
addr->bt_len = sizeof(struct sockaddr_bt);
|
|
|
|
addr->bt_family = AF_BLUETOOTH;
|
|
|
|
bdaddr_copy(&addr->bt_bdaddr, &pcb->sp_raddr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out of
pr_generic() usrreq switches and put into separate functions
xxx_disconnect(struct socket *)
xxx_shutdown(struct socket *)
xxx_abort(struct socket *)
- always KASSERT(solocked(so)) even if not implemented
- replace calls to pr_generic() with req =
PRU_{DISCONNECT,SHUTDOWN,ABORT}
with calls to pr_{disconnect,shutdown,abort}() respectively
rename existing internal functions used to implement above functionality
to permit use of the names for xxx_{disconnect,shutdown,abort}().
- {l2cap,sco,rfcomm}_disconnect() ->
{l2cap,sco,rfcomm}_disconnect_pcb()
- {unp,rip,tcp}_disconnect() -> {unp,rip,tcp}_disconnect1()
- unp_shutdown() -> unp_shutdown1()
patch reviewed by rmind
2014-07-31 07:39:35 +04:00
|
|
|
* sco_disconnect_pcb(pcb, linger)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Initiate disconnection of connected SCO pcb
|
|
|
|
*/
|
|
|
|
int
|
split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out of
pr_generic() usrreq switches and put into separate functions
xxx_disconnect(struct socket *)
xxx_shutdown(struct socket *)
xxx_abort(struct socket *)
- always KASSERT(solocked(so)) even if not implemented
- replace calls to pr_generic() with req =
PRU_{DISCONNECT,SHUTDOWN,ABORT}
with calls to pr_{disconnect,shutdown,abort}() respectively
rename existing internal functions used to implement above functionality
to permit use of the names for xxx_{disconnect,shutdown,abort}().
- {l2cap,sco,rfcomm}_disconnect() ->
{l2cap,sco,rfcomm}_disconnect_pcb()
- {unp,rip,tcp}_disconnect() -> {unp,rip,tcp}_disconnect1()
- unp_shutdown() -> unp_shutdown1()
patch reviewed by rmind
2014-07-31 07:39:35 +04:00
|
|
|
sco_disconnect_pcb(struct sco_pcb *pcb, int linger)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
hci_discon_cp cp;
|
|
|
|
struct hci_link *sco;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
sco = pcb->sp_link;
|
|
|
|
if (sco == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
cp.con_handle = htole16(sco->hl_handle);
|
|
|
|
cp.reason = 0x13; /* "Remote User Terminated Connection" */
|
|
|
|
|
|
|
|
err = hci_send_cmd(sco->hl_unit, HCI_CMD_DISCONNECT, &cp, sizeof(cp));
|
|
|
|
if (err || linger == 0) {
|
|
|
|
sco->hl_sco = NULL;
|
|
|
|
pcb->sp_link = NULL;
|
|
|
|
hci_link_free(sco, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-05-20 22:25:54 +04:00
|
|
|
* sco_detach_pcb(handle)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Detach SCO pcb from handle and clear up
|
|
|
|
*/
|
2014-05-19 06:51:24 +04:00
|
|
|
void
|
2014-05-20 22:25:54 +04:00
|
|
|
sco_detach_pcb(struct sco_pcb **handle)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
struct sco_pcb *pcb;
|
|
|
|
|
2007-03-31 00:47:02 +04:00
|
|
|
KASSERT(handle != NULL);
|
2006-06-19 19:44:33 +04:00
|
|
|
pcb = *handle;
|
|
|
|
*handle = NULL;
|
|
|
|
|
|
|
|
if (pcb->sp_link != NULL) {
|
split PRU_DISCONNECT, PRU_SHUTDOWN and PRU_ABORT function out of
pr_generic() usrreq switches and put into separate functions
xxx_disconnect(struct socket *)
xxx_shutdown(struct socket *)
xxx_abort(struct socket *)
- always KASSERT(solocked(so)) even if not implemented
- replace calls to pr_generic() with req =
PRU_{DISCONNECT,SHUTDOWN,ABORT}
with calls to pr_{disconnect,shutdown,abort}() respectively
rename existing internal functions used to implement above functionality
to permit use of the names for xxx_{disconnect,shutdown,abort}().
- {l2cap,sco,rfcomm}_disconnect() ->
{l2cap,sco,rfcomm}_disconnect_pcb()
- {unp,rip,tcp}_disconnect() -> {unp,rip,tcp}_disconnect1()
- unp_shutdown() -> unp_shutdown1()
patch reviewed by rmind
2014-07-31 07:39:35 +04:00
|
|
|
sco_disconnect_pcb(pcb, 0);
|
2006-06-19 19:44:33 +04:00
|
|
|
pcb->sp_link = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LIST_REMOVE(pcb, sp_next);
|
|
|
|
free(pcb, M_BLUETOOTH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-07-24 19:12:03 +04:00
|
|
|
* sco_listen_pcb(pcb)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Mark pcb as a listener.
|
|
|
|
*/
|
|
|
|
int
|
2014-07-24 19:12:03 +04:00
|
|
|
sco_listen_pcb(struct sco_pcb *pcb)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
if (pcb->sp_link != NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
pcb->sp_flags |= SP_LISTENING;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-08-05 11:55:31 +04:00
|
|
|
* sco_send_pcb(pcb, mbuf)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Send data on SCO pcb.
|
|
|
|
*
|
|
|
|
* Gross hackage, we just output the packet directly onto the unit queue.
|
|
|
|
* This will work fine for one channel per unit, but for more channels it
|
|
|
|
* really needs fixing. We set the context so that when the packet is sent,
|
|
|
|
* we can drop a record from the socket buffer.
|
|
|
|
*/
|
|
|
|
int
|
2014-08-05 11:55:31 +04:00
|
|
|
sco_send_pcb(struct sco_pcb *pcb, struct mbuf *m)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
hci_scodata_hdr_t *hdr;
|
|
|
|
int plen;
|
|
|
|
|
|
|
|
if (pcb->sp_link == NULL) {
|
|
|
|
m_freem(m);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
plen = m->m_pkthdr.len;
|
|
|
|
DPRINTFN(10, "%d bytes\n", plen);
|
|
|
|
|
2006-08-27 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* This is a temporary limitation, as USB devices cannot
|
|
|
|
* handle SCO packet sizes that are not an integer number
|
|
|
|
* of Isochronous frames. See ubt(4)
|
|
|
|
*/
|
|
|
|
if (plen != pcb->sp_mtu) {
|
|
|
|
m_freem(m);
|
|
|
|
return EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2006-06-19 19:44:33 +04:00
|
|
|
M_PREPEND(m, sizeof(hci_scodata_hdr_t), M_DONTWAIT);
|
|
|
|
if (m == NULL)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
hdr = mtod(m, hci_scodata_hdr_t *);
|
|
|
|
hdr->type = HCI_SCO_DATA_PKT;
|
|
|
|
hdr->con_handle = htole16(pcb->sp_link->hl_handle);
|
|
|
|
hdr->length = plen;
|
|
|
|
|
|
|
|
pcb->sp_pending++;
|
|
|
|
M_SETCTX(m, pcb->sp_link);
|
|
|
|
hci_output_sco(pcb->sp_link->hl_unit, m);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-08-06 19:01:23 +04:00
|
|
|
* sco_setopt(pcb, sopt)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Set SCO pcb options
|
|
|
|
*/
|
|
|
|
int
|
2008-08-06 19:01:23 +04:00
|
|
|
sco_setopt(struct sco_pcb *pcb, const struct sockopt *sopt)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
|
2008-08-06 19:01:23 +04:00
|
|
|
switch (sopt->sopt_name) {
|
2006-06-19 19:44:33 +04:00
|
|
|
default:
|
2007-03-05 22:11:54 +03:00
|
|
|
err = ENOPROTOOPT;
|
2006-06-19 19:44:33 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-08-06 19:01:23 +04:00
|
|
|
* sco_getopt(pcb, sopt)
|
2006-06-19 19:44:33 +04:00
|
|
|
*
|
|
|
|
* Get SCO pcb options
|
|
|
|
*/
|
|
|
|
int
|
2008-08-06 19:01:23 +04:00
|
|
|
sco_getopt(struct sco_pcb *pcb, struct sockopt *sopt)
|
2006-06-19 19:44:33 +04:00
|
|
|
{
|
|
|
|
|
2008-08-06 19:01:23 +04:00
|
|
|
switch (sopt->sopt_name) {
|
2006-06-19 19:44:33 +04:00
|
|
|
case SO_SCO_MTU:
|
2008-08-06 19:01:23 +04:00
|
|
|
return sockopt_set(sopt, &pcb->sp_mtu, sizeof(uint16_t));
|
2006-06-19 19:44:33 +04:00
|
|
|
|
|
|
|
case SO_SCO_HANDLE:
|
2008-08-06 19:01:23 +04:00
|
|
|
if (pcb->sp_link)
|
|
|
|
return sockopt_set(sopt,
|
|
|
|
&pcb->sp_link->hl_handle, sizeof(uint16_t));
|
|
|
|
|
|
|
|
return ENOTCONN;
|
2006-06-19 19:44:33 +04:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-08-06 19:01:23 +04:00
|
|
|
|
|
|
|
return ENOPROTOOPT;
|
2006-06-19 19:44:33 +04:00
|
|
|
}
|