allow listening to channel RFCOMM_CHANNEL_ANY, which means that

we should allocate the first available channel at the given
device address.
This commit is contained in:
plunky 2007-11-20 20:25:57 +00:00
parent fb5c91f9fc
commit 166b860e06
3 changed files with 40 additions and 10 deletions

View File

@ -1,4 +1,4 @@
.\" $NetBSD: bluetooth.4,v 1.7 2007/09/30 04:22:52 kiyohara Exp $
.\" $NetBSD: bluetooth.4,v 1.8 2007/11/20 20:25:57 plunky Exp $
.\"
.\" Copyright (c) 2006 Itronix Inc.
.\" All rights reserved.
@ -189,7 +189,15 @@ and
fields in the
.Ar sockaddr_bt
structure.
The channel number must be between 1 and 30 inclusive.
The channel number must be between 1 and 30 inclusive except that if the
special value
.Dv RFCOMM_CHANNEL_ANY
is bound, when the
.Xr listen 2
call is made, the first unused channel for the relevant bdaddr will be
allocated and may be discovered using the
.Xr getsockname 2
call.
If no PSM is specified, a default value of
.Dv L2CAP_PSM_RFCOMM
(0x0003) will be used.

View File

@ -1,4 +1,4 @@
/* $NetBSD: rfcomm.h,v 1.5 2007/11/03 17:39:14 plunky Exp $ */
/* $NetBSD: rfcomm.h,v 1.6 2007/11/20 20:25:58 plunky Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
@ -55,7 +55,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: rfcomm.h,v 1.5 2007/11/03 17:39:14 plunky Exp $
* $Id: rfcomm.h,v 1.6 2007/11/20 20:25:58 plunky Exp $
* $FreeBSD: src/sys/netgraph/bluetooth/include/ng_btsocket_rfcomm.h,v 1.4 2005/01/11 01:39:53 emax Exp $
*/
@ -77,6 +77,7 @@
#define RFCOMM_CREDITS_MAX 255 /* in any single packet */
#define RFCOMM_CREDITS_DEFAULT 7 /* default initial value */
#define RFCOMM_CHANNEL_ANY 0
#define RFCOMM_CHANNEL_MIN 1
#define RFCOMM_CHANNEL_MAX 30

View File

@ -1,4 +1,4 @@
/* $NetBSD: rfcomm_upper.c,v 1.9 2007/11/20 20:19:24 plunky Exp $ */
/* $NetBSD: rfcomm_upper.c,v 1.10 2007/11/20 20:25:57 plunky Exp $ */
/*-
* Copyright (c) 2006 Itronix Inc.
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rfcomm_upper.c,v 1.9 2007/11/20 20:19:24 plunky Exp $");
__KERNEL_RCSID(0, "$NetBSD: rfcomm_upper.c,v 1.10 2007/11/20 20:25:57 plunky Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -305,20 +305,23 @@ rfcomm_detach(struct rfcomm_dlc **handle)
*
* This DLC is a listener. We look for an existing listening session
* with a matching address to attach to or else create a new one on
* the listeners list.
* the listeners list. If the ANY channel is given, allocate the first
* available for the session.
*/
int
rfcomm_listen(struct rfcomm_dlc *dlc)
{
struct rfcomm_session *rs;
struct rfcomm_dlc *used;
struct sockaddr_bt addr;
int err;
int err, channel;
if (dlc->rd_state != RFCOMM_DLC_CLOSED)
return EISCONN;
if (dlc->rd_laddr.bt_channel < RFCOMM_CHANNEL_MIN
|| dlc->rd_laddr.bt_channel > RFCOMM_CHANNEL_MAX)
if (dlc->rd_laddr.bt_channel != RFCOMM_CHANNEL_ANY
&& (dlc->rd_laddr.bt_channel < RFCOMM_CHANNEL_MIN
|| dlc->rd_laddr.bt_channel > RFCOMM_CHANNEL_MAX))
return EADDRNOTAVAIL;
if (dlc->rd_laddr.bt_psm == L2CAP_PSM_ANY)
@ -353,6 +356,24 @@ rfcomm_listen(struct rfcomm_dlc *dlc)
}
}
if (dlc->rd_laddr.bt_channel == RFCOMM_CHANNEL_ANY) {
channel = RFCOMM_CHANNEL_MIN;
used = LIST_FIRST(&rs->rs_dlcs);
while (used != NULL) {
if (used->rd_laddr.bt_channel == channel) {
if (channel++ == RFCOMM_CHANNEL_MAX)
return EADDRNOTAVAIL;
used = LIST_FIRST(&rs->rs_dlcs);
} else {
used = LIST_NEXT(used, rd_next);
}
}
dlc->rd_laddr.bt_channel = channel;
}
dlc->rd_session = rs;
dlc->rd_state = RFCOMM_DLC_LISTEN;
LIST_INSERT_HEAD(&rs->rs_dlcs, dlc, rd_next);