Skip to content

Commit bb4c6de

Browse files
emaxemax
emax
authored and
emax
committed
Introduce support for Bluetooth SCO sockets. This is based on older
code that was revisted. MFC after: 3 months
1 parent 926481c commit bb4c6de

File tree

3 files changed

+2132
-1
lines changed

3 files changed

+2132
-1
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
/*
2+
* ng_btsocket_sco.h
3+
*/
4+
5+
/*-
6+
* Copyright (c) 2001-2002 Maksim Yevmenkin <[email protected]>
7+
* All rights reserved.
8+
*
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions
11+
* are met:
12+
* 1. Redistributions of source code must retain the above copyright
13+
* notice, this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in the
16+
* documentation and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28+
* SUCH DAMAGE.
29+
*
30+
* $Id: ng_btsocket_sco.h,v 1.3 2005/10/31 18:08:52 max Exp $
31+
* $FreeBSD$
32+
*/
33+
34+
#ifndef _NETGRAPH_BTSOCKET_SCO_H_
35+
#define _NETGRAPH_BTSOCKET_SCO_H_
36+
37+
/*
38+
* SCO routing entry
39+
*/
40+
41+
struct ng_hook;
42+
struct ng_message;
43+
44+
struct ng_btsocket_sco_rtentry {
45+
bdaddr_t src; /* source BD_ADDR */
46+
u_int16_t pkt_size; /* mtu */
47+
u_int16_t num_pkts; /* buffer size */
48+
int32_t pending; /* pending packets */
49+
struct ng_hook *hook; /* downstream hook */
50+
LIST_ENTRY(ng_btsocket_sco_rtentry) next; /* link to next */
51+
};
52+
typedef struct ng_btsocket_sco_rtentry ng_btsocket_sco_rtentry_t;
53+
typedef struct ng_btsocket_sco_rtentry * ng_btsocket_sco_rtentry_p;
54+
55+
/*****************************************************************************
56+
*****************************************************************************
57+
** SOCK_SEQPACKET SCO sockets **
58+
*****************************************************************************
59+
*****************************************************************************/
60+
61+
#define NG_BTSOCKET_SCO_SENDSPACE 1024
62+
#define NG_BTSOCKET_SCO_RECVSPACE (64 * 1024)
63+
64+
/*
65+
* Bluetooth SCO socket PCB
66+
*/
67+
68+
struct ng_btsocket_sco_pcb {
69+
struct socket *so; /* Pointer to socket */
70+
71+
bdaddr_t src; /* Source address */
72+
bdaddr_t dst; /* Destination address */
73+
74+
u_int16_t con_handle; /* connection handle */
75+
76+
u_int16_t flags; /* socket flags */
77+
#define NG_BTSOCKET_SCO_CLIENT (1 << 0) /* socket is client */
78+
#define NG_BTSOCKET_SCO_TIMO (1 << 1) /* timeout pending */
79+
80+
u_int8_t state; /* socket state */
81+
#define NG_BTSOCKET_SCO_CLOSED 0 /* socket closed */
82+
#define NG_BTSOCKET_SCO_CONNECTING 1 /* wait for connect */
83+
#define NG_BTSOCKET_SCO_OPEN 2 /* socket open */
84+
#define NG_BTSOCKET_SCO_DISCONNECTING 3 /* wait for disconnect */
85+
86+
struct callout timo; /* timeout */
87+
88+
ng_btsocket_sco_rtentry_p rt; /* routing info */
89+
90+
struct mtx pcb_mtx; /* pcb mutex */
91+
92+
LIST_ENTRY(ng_btsocket_sco_pcb) next; /* link to next PCB */
93+
};
94+
typedef struct ng_btsocket_sco_pcb ng_btsocket_sco_pcb_t;
95+
typedef struct ng_btsocket_sco_pcb * ng_btsocket_sco_pcb_p;
96+
97+
#define so2sco_pcb(so) \
98+
((struct ng_btsocket_sco_pcb *)((so)->so_pcb))
99+
100+
/*
101+
* Bluetooth SCO socket methods
102+
*/
103+
104+
#ifdef _KERNEL
105+
106+
void ng_btsocket_sco_init (void);
107+
void ng_btsocket_sco_abort (struct socket *);
108+
void ng_btsocket_sco_close (struct socket *);
109+
int ng_btsocket_sco_accept (struct socket *, struct sockaddr **);
110+
int ng_btsocket_sco_attach (struct socket *, int, struct thread *);
111+
int ng_btsocket_sco_bind (struct socket *, struct sockaddr *,
112+
struct thread *);
113+
int ng_btsocket_sco_connect (struct socket *, struct sockaddr *,
114+
struct thread *);
115+
int ng_btsocket_sco_control (struct socket *, u_long, caddr_t,
116+
struct ifnet *, struct thread *);
117+
int ng_btsocket_sco_ctloutput (struct socket *, struct sockopt *);
118+
void ng_btsocket_sco_detach (struct socket *);
119+
int ng_btsocket_sco_disconnect (struct socket *);
120+
int ng_btsocket_sco_listen (struct socket *, int, struct thread *);
121+
int ng_btsocket_sco_peeraddr (struct socket *, struct sockaddr **);
122+
int ng_btsocket_sco_send (struct socket *, int, struct mbuf *,
123+
struct sockaddr *, struct mbuf *,
124+
struct thread *);
125+
int ng_btsocket_sco_sockaddr (struct socket *, struct sockaddr **);
126+
127+
#endif /* _KERNEL */
128+
129+
#endif /* _NETGRAPH_BTSOCKET_SCO_H_ */
130+

sys/netgraph/bluetooth/socket/ng_btsocket.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <netgraph/bluetooth/include/ng_btsocket_hci_raw.h>
5555
#include <netgraph/bluetooth/include/ng_btsocket_l2cap.h>
5656
#include <netgraph/bluetooth/include/ng_btsocket_rfcomm.h>
57+
#include <netgraph/bluetooth/include/ng_btsocket_sco.h>
5758

5859
static int ng_btsocket_modevent (module_t, int, void *);
5960
extern struct domain ng_btsocket_domain;
@@ -138,6 +139,27 @@ static struct pr_usrreqs ng_btsocket_rfcomm_usrreqs = {
138139
.pru_close = ng_btsocket_rfcomm_close,
139140
};
140141

142+
/*
143+
* Bluetooth SEQPACKET SCO sockets
144+
*/
145+
146+
static struct pr_usrreqs ng_btsocket_sco_usrreqs = {
147+
.pru_abort = ng_btsocket_sco_abort,
148+
.pru_accept = ng_btsocket_sco_accept,
149+
.pru_attach = ng_btsocket_sco_attach,
150+
.pru_bind = ng_btsocket_sco_bind,
151+
.pru_connect = ng_btsocket_sco_connect,
152+
.pru_control = ng_btsocket_sco_control,
153+
.pru_detach = ng_btsocket_sco_detach,
154+
.pru_disconnect = ng_btsocket_sco_disconnect,
155+
.pru_listen = ng_btsocket_sco_listen,
156+
.pru_peeraddr = ng_btsocket_sco_peeraddr,
157+
.pru_send = ng_btsocket_sco_send,
158+
.pru_shutdown = NULL,
159+
.pru_sockaddr = ng_btsocket_sco_sockaddr,
160+
.pru_close = ng_btsocket_sco_close,
161+
};
162+
141163
/*
142164
* Definitions of protocols supported in the BLUETOOTH domain
143165
*/
@@ -177,7 +199,16 @@ static struct protosw ng_btsocket_protosw[] = {
177199
.pr_ctloutput = ng_btsocket_rfcomm_ctloutput,
178200
.pr_init = ng_btsocket_rfcomm_init,
179201
.pr_usrreqs = &ng_btsocket_rfcomm_usrreqs,
180-
}
202+
},
203+
{
204+
.pr_type = SOCK_SEQPACKET,
205+
.pr_domain = &ng_btsocket_domain,
206+
.pr_protocol = BLUETOOTH_PROTO_SCO,
207+
.pr_flags = PR_ATOMIC|PR_CONNREQUIRED,
208+
.pr_ctloutput = ng_btsocket_sco_ctloutput,
209+
.pr_init = ng_btsocket_sco_init,
210+
.pr_usrreqs = &ng_btsocket_sco_usrreqs,
211+
},
181212
};
182213
#define ng_btsocket_protosw_size \
183214
(sizeof(ng_btsocket_protosw)/sizeof(ng_btsocket_protosw[0]))
@@ -205,6 +236,8 @@ SYSCTL_NODE(_net_bluetooth_l2cap, OID_AUTO, sockets, CTLFLAG_RW,
205236
0, "Bluetooth L2CAP sockets family");
206237
SYSCTL_NODE(_net_bluetooth_rfcomm, OID_AUTO, sockets, CTLFLAG_RW,
207238
0, "Bluetooth RFCOMM sockets family");
239+
SYSCTL_NODE(_net_bluetooth_sco, OID_AUTO, sockets, CTLFLAG_RW,
240+
0, "Bluetooth SCO sockets family");
208241

209242
/*
210243
* Module

0 commit comments

Comments
 (0)