Deleted Added
full compact
ng_btsocket_rfcomm.c (188452) ng_btsocket_rfcomm.c (193272)
1/*
2 * ng_btsocket_rfcomm.c
3 */
4
5/*-
6 * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7 * All rights reserved.
8 *

--- 14 unchanged lines hidden (view full) ---

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_rfcomm.c,v 1.28 2003/09/14 23:29:06 max Exp $
1/*
2 * ng_btsocket_rfcomm.c
3 */
4
5/*-
6 * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7 * All rights reserved.
8 *

--- 14 unchanged lines hidden (view full) ---

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_rfcomm.c,v 1.28 2003/09/14 23:29:06 max Exp $
31 * $FreeBSD: head/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c 188452 2009-02-10 20:27:05Z emax $
31 * $FreeBSD: head/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c 193272 2009-06-01 21:17:03Z jhb $
32 */
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/bitstring.h>
37#include <sys/domain.h>
38#include <sys/endian.h>
39#include <sys/errno.h>

--- 48 unchanged lines hidden (view full) ---

88#define NG_BTSOCKET_RFCOMM_ALERT \
89 if (ng_btsocket_rfcomm_debug_level >= NG_BTSOCKET_ALERT_LEVEL && \
90 ppsratecheck(&ng_btsocket_rfcomm_lasttime, &ng_btsocket_rfcomm_curpps, 1)) \
91 printf
92
93#define ALOT 0x7fff
94
95/* Local prototypes */
32 */
33
34#include <sys/param.h>
35#include <sys/systm.h>
36#include <sys/bitstring.h>
37#include <sys/domain.h>
38#include <sys/endian.h>
39#include <sys/errno.h>

--- 48 unchanged lines hidden (view full) ---

88#define NG_BTSOCKET_RFCOMM_ALERT \
89 if (ng_btsocket_rfcomm_debug_level >= NG_BTSOCKET_ALERT_LEVEL && \
90 ppsratecheck(&ng_btsocket_rfcomm_lasttime, &ng_btsocket_rfcomm_curpps, 1)) \
91 printf
92
93#define ALOT 0x7fff
94
95/* Local prototypes */
96static void ng_btsocket_rfcomm_upcall
96static int ng_btsocket_rfcomm_upcall
97 (struct socket *so, void *arg, int waitflag);
98static void ng_btsocket_rfcomm_sessions_task
99 (void *ctx, int pending);
100static void ng_btsocket_rfcomm_session_task
101 (ng_btsocket_rfcomm_session_p s);
102#define ng_btsocket_rfcomm_task_wakeup() \
103 taskqueue_enqueue(taskqueue_swi_giant, &ng_btsocket_rfcomm_task)
104

--- 897 unchanged lines hidden (view full) ---

1002
1003 return ((*nam == NULL)? ENOMEM : 0);
1004} /* ng_btsocket_rfcomm_sockaddr */
1005
1006/*
1007 * Upcall function for L2CAP sockets. Enqueue RFCOMM task.
1008 */
1009
97 (struct socket *so, void *arg, int waitflag);
98static void ng_btsocket_rfcomm_sessions_task
99 (void *ctx, int pending);
100static void ng_btsocket_rfcomm_session_task
101 (ng_btsocket_rfcomm_session_p s);
102#define ng_btsocket_rfcomm_task_wakeup() \
103 taskqueue_enqueue(taskqueue_swi_giant, &ng_btsocket_rfcomm_task)
104

--- 897 unchanged lines hidden (view full) ---

1002
1003 return ((*nam == NULL)? ENOMEM : 0);
1004} /* ng_btsocket_rfcomm_sockaddr */
1005
1006/*
1007 * Upcall function for L2CAP sockets. Enqueue RFCOMM task.
1008 */
1009
1010static void
1010static int
1011ng_btsocket_rfcomm_upcall(struct socket *so, void *arg, int waitflag)
1012{
1013 int error;
1014
1015 if (so == NULL)
1016 panic("%s: so == NULL\n", __func__);
1017
1018 if ((error = ng_btsocket_rfcomm_task_wakeup()) != 0)
1019 NG_BTSOCKET_RFCOMM_ALERT(
1020"%s: Could not enqueue RFCOMM task, error=%d\n", __func__, error);
1011ng_btsocket_rfcomm_upcall(struct socket *so, void *arg, int waitflag)
1012{
1013 int error;
1014
1015 if (so == NULL)
1016 panic("%s: so == NULL\n", __func__);
1017
1018 if ((error = ng_btsocket_rfcomm_task_wakeup()) != 0)
1019 NG_BTSOCKET_RFCOMM_ALERT(
1020"%s: Could not enqueue RFCOMM task, error=%d\n", __func__, error);
1021 return (SU_OK);
1021} /* ng_btsocket_rfcomm_upcall */
1022
1023/*
1024 * RFCOMM task. Will handle all RFCOMM sessions in one pass.
1025 * XXX FIXME does not scale very well
1026 */
1027
1028static void

--- 13 unchanged lines hidden (view full) ---

1042 /* Unlink and clean the session */
1043 LIST_REMOVE(s, next);
1044
1045 NG_BT_MBUFQ_DRAIN(&s->outq);
1046 if (!LIST_EMPTY(&s->dlcs))
1047 panic("%s: DLC list is not empty\n", __func__);
1048
1049 /* Close L2CAP socket */
1022} /* ng_btsocket_rfcomm_upcall */
1023
1024/*
1025 * RFCOMM task. Will handle all RFCOMM sessions in one pass.
1026 * XXX FIXME does not scale very well
1027 */
1028
1029static void

--- 13 unchanged lines hidden (view full) ---

1043 /* Unlink and clean the session */
1044 LIST_REMOVE(s, next);
1045
1046 NG_BT_MBUFQ_DRAIN(&s->outq);
1047 if (!LIST_EMPTY(&s->dlcs))
1048 panic("%s: DLC list is not empty\n", __func__);
1049
1050 /* Close L2CAP socket */
1050 s->l2so->so_upcallarg = NULL;
1051 s->l2so->so_upcall = NULL;
1052 SOCKBUF_LOCK(&s->l2so->so_rcv);
1051 SOCKBUF_LOCK(&s->l2so->so_rcv);
1053 s->l2so->so_rcv.sb_flags &= ~SB_UPCALL;
1052 soupcall_clear(s->l2so, SO_RCV);
1054 SOCKBUF_UNLOCK(&s->l2so->so_rcv);
1055 SOCKBUF_LOCK(&s->l2so->so_snd);
1053 SOCKBUF_UNLOCK(&s->l2so->so_rcv);
1054 SOCKBUF_LOCK(&s->l2so->so_snd);
1056 s->l2so->so_snd.sb_flags &= ~SB_UPCALL;
1055 soupcall_clear(s->l2so, SO_SND);
1057 SOCKBUF_UNLOCK(&s->l2so->so_snd);
1058 soclose(s->l2so);
1059
1060 mtx_unlock(&s->session_mtx);
1061
1062 mtx_destroy(&s->session_mtx);
1063 bzero(s, sizeof(*s));
1064 free(s, M_NETGRAPH_BTSOCKET_RFCOMM);

--- 216 unchanged lines hidden (view full) ---

1281 */
1282
1283 mtx_init(&s->session_mtx, "btsocks_rfcomm_session_mtx", NULL,
1284 MTX_DEF|MTX_DUPOK);
1285
1286 LIST_INIT(&s->dlcs);
1287
1288 /* Prepare L2CAP socket */
1056 SOCKBUF_UNLOCK(&s->l2so->so_snd);
1057 soclose(s->l2so);
1058
1059 mtx_unlock(&s->session_mtx);
1060
1061 mtx_destroy(&s->session_mtx);
1062 bzero(s, sizeof(*s));
1063 free(s, M_NETGRAPH_BTSOCKET_RFCOMM);

--- 216 unchanged lines hidden (view full) ---

1280 */
1281
1282 mtx_init(&s->session_mtx, "btsocks_rfcomm_session_mtx", NULL,
1283 MTX_DEF|MTX_DUPOK);
1284
1285 LIST_INIT(&s->dlcs);
1286
1287 /* Prepare L2CAP socket */
1289 l2so->so_upcallarg = NULL;
1290 l2so->so_upcall = ng_btsocket_rfcomm_upcall;
1291 SOCKBUF_LOCK(&l2so->so_rcv);
1288 SOCKBUF_LOCK(&l2so->so_rcv);
1292 l2so->so_rcv.sb_flags |= SB_UPCALL;
1289 soupcall_set(l2so, SO_RCV, ng_btsocket_rfcomm_upcall, NULL);
1293 SOCKBUF_UNLOCK(&l2so->so_rcv);
1294 SOCKBUF_LOCK(&l2so->so_snd);
1290 SOCKBUF_UNLOCK(&l2so->so_rcv);
1291 SOCKBUF_LOCK(&l2so->so_snd);
1295 l2so->so_snd.sb_flags |= SB_UPCALL;
1292 soupcall_set(l2so, SO_SND, ng_btsocket_rfcomm_upcall, NULL);
1296 SOCKBUF_UNLOCK(&l2so->so_snd);
1297 l2so->so_state |= SS_NBIO;
1298 s->l2so = l2so;
1299
1300 mtx_lock(&s->session_mtx);
1301
1302 /*
1303 * "src" == NULL and "dst" == NULL means just create session.

--- 61 unchanged lines hidden (view full) ---

1365 mtx_unlock(&s->session_mtx);
1366
1367 return (0);
1368
1369bad:
1370 mtx_unlock(&s->session_mtx);
1371
1372 /* Return L2CAP socket back to its original state */
1293 SOCKBUF_UNLOCK(&l2so->so_snd);
1294 l2so->so_state |= SS_NBIO;
1295 s->l2so = l2so;
1296
1297 mtx_lock(&s->session_mtx);
1298
1299 /*
1300 * "src" == NULL and "dst" == NULL means just create session.

--- 61 unchanged lines hidden (view full) ---

1362 mtx_unlock(&s->session_mtx);
1363
1364 return (0);
1365
1366bad:
1367 mtx_unlock(&s->session_mtx);
1368
1369 /* Return L2CAP socket back to its original state */
1373 l2so->so_upcallarg = NULL;
1374 l2so->so_upcall = NULL;
1375 SOCKBUF_LOCK(&l2so->so_rcv);
1370 SOCKBUF_LOCK(&l2so->so_rcv);
1376 l2so->so_rcv.sb_flags &= ~SB_UPCALL;
1371 soupcall_clear(s->l2so, SO_RCV);
1377 SOCKBUF_UNLOCK(&l2so->so_rcv);
1378 SOCKBUF_LOCK(&l2so->so_snd);
1372 SOCKBUF_UNLOCK(&l2so->so_rcv);
1373 SOCKBUF_LOCK(&l2so->so_snd);
1379 l2so->so_snd.sb_flags &= ~SB_UPCALL;
1374 soupcall_clear(s->l2so, SO_SND);
1380 SOCKBUF_UNLOCK(&l2so->so_snd);
1381 l2so->so_state &= ~SS_NBIO;
1382
1383 mtx_destroy(&s->session_mtx);
1384 bzero(s, sizeof(*s));
1385 free(s, M_NETGRAPH_BTSOCKET_RFCOMM);
1386
1387 return (error);

--- 2187 unchanged lines hidden ---
1375 SOCKBUF_UNLOCK(&l2so->so_snd);
1376 l2so->so_state &= ~SS_NBIO;
1377
1378 mtx_destroy(&s->session_mtx);
1379 bzero(s, sizeof(*s));
1380 free(s, M_NETGRAPH_BTSOCKET_RFCOMM);
1381
1382 return (error);

--- 2187 unchanged lines hidden ---