Wed Nov 3 08:27:27 2010 UTC ()
In server mode, relax the requirement to specify a channel number. If
one is not given, attempt to allocate the first unused one.


(plunky)
diff -r1.8 -r1.9 src/usr.bin/rfcomm_sppd/rfcomm_sppd.1
diff -r1.12 -r1.13 src/usr.bin/rfcomm_sppd/rfcomm_sppd.c

cvs diff -r1.8 -r1.9 src/usr.bin/rfcomm_sppd/rfcomm_sppd.1 (expand / switch to context diff)
--- src/usr.bin/rfcomm_sppd/rfcomm_sppd.1 2010/11/02 19:44:09 1.8
+++ src/usr.bin/rfcomm_sppd/rfcomm_sppd.1 2010/11/03 08:27:27 1.9
@@ -1,4 +1,4 @@
-.\" $NetBSD: rfcomm_sppd.1,v 1.8 2010/11/02 19:44:09 plunky Exp $
+.\" $NetBSD: rfcomm_sppd.1,v 1.9 2010/11/03 08:27:27 plunky Exp $
 .\"
 .\" Copyright (c) 2006 Itronix Inc.
 .\" All rights reserved.
@@ -65,7 +65,7 @@
 .Op Fl p Ar psm
 .Op Fl s Ar service
 .Op Fl t Ar tty
-.Brq Fl a Ar address | Fl c Ar channel
+.Brq Fl a Ar address | Op Fl c Ar channel
 .Sh DESCRIPTION
 The
 .Nm
@@ -87,7 +87,8 @@
 .Ar service
 with the local SDP server and listens on the specified RFCOMM
 .Ar channel
-for an incoming connection.
+for an incoming connection, or the first unused channel if none
+was given.
 .Pp
 The options are as follows:
 .Bl -tag -width ".Fl c Ar channel"
@@ -100,8 +101,7 @@
 utility will attempt to resolve the name via
 .Xr bt_gethostbyname 3 .
 .It Fl c Ar channel
-Server mode.
-Specify the RFCOMM channel number to listen on.
+In server mode, specify the RFCOMM channel number to listen on.
 .Nm
 will register the service with the local
 .Xr sdpd 8

cvs diff -r1.12 -r1.13 src/usr.bin/rfcomm_sppd/rfcomm_sppd.c (expand / switch to context diff)
--- src/usr.bin/rfcomm_sppd/rfcomm_sppd.c 2009/09/24 18:30:37 1.12
+++ src/usr.bin/rfcomm_sppd/rfcomm_sppd.c 2010/11/03 08:27:27 1.13
@@ -1,4 +1,4 @@
-/*	$NetBSD: rfcomm_sppd.c,v 1.12 2009/09/24 18:30:37 plunky Exp $	*/
+/*	$NetBSD: rfcomm_sppd.c,v 1.13 2010/11/03 08:27:27 plunky Exp $	*/
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -62,7 +62,7 @@
   Copyright (c) 2006 Itronix, Inc.\
   Copyright (c) 2003 Maksim Yevmenkin m_evmenkin@yahoo.com.\
   All rights reserved.");
-__RCSID("$NetBSD: rfcomm_sppd.c,v 1.12 2009/09/24 18:30:37 plunky Exp $");
+__RCSID("$NetBSD: rfcomm_sppd.c,v 1.13 2010/11/03 08:27:27 plunky Exp $");
 
 #include <sys/param.h>
 
@@ -128,7 +128,7 @@
 	bdaddr_copy(&raddr, BDADDR_ANY);
 	service = "SP";
 	tty = NULL;
-	channel = 0;
+	channel = RFCOMM_CHANNEL_ANY;
 	psm = L2CAP_PSM_RFCOMM;
 	lm = 0;
 
@@ -149,7 +149,9 @@
 
 		case 'c': /* RFCOMM channel */
 			channel = strtoul(optarg, &ep, 10);
-			if (*ep != '\0' || channel < 1 || channel > 30)
+			if (*ep != '\0'
+			    || channel < RFCOMM_CHANNEL_MIN
+			    || channel > RFCOMM_CHANNEL_MAX)
 				errx(EXIT_FAILURE, "Invalid channel: %s", optarg);
 
 			break;
@@ -200,10 +202,9 @@
 
 	/*
 	 * validate options:
-	 *	must have channel or remote address but not both
+	 *	cannot have remote address if channel was given
 	 */
-	if ((channel == 0 && bdaddr_any(&raddr))
-	    || (channel != 0 && !bdaddr_any(&raddr)))
+	if (channel != RFCOMM_CHANNEL_ANY && !bdaddr_any(&raddr))
 		usage();
 
 	/*
@@ -218,7 +219,7 @@
 	}
 
 	/* open RFCOMM */
-	if (channel == 0)
+	if (!bdaddr_any(&raddr))
 		rfcomm = open_client(&laddr, &raddr, lm, psm, service);
 	else
 		rfcomm = open_server(&laddr, psm, channel, lm, service);
@@ -433,6 +434,12 @@
 	if (listen(sv, 1) < 0)
 		err(EXIT_FAILURE, "listen()");
 
+	len = sizeof(sa);
+	if (getsockname(sv, (struct sockaddr *)&sa, &len) < 0)
+		err(EXIT_FAILURE, "getsockname()");
+	if (len != sizeof(sa))
+		errx(EXIT_FAILURE, "getsockname()");
+
 	/* Build SDP record */
 	rec.next = buffer;
 	rec.end = buffer + sizeof(buffer);
@@ -454,7 +461,7 @@
 		sdp_put_uint16(&rec, psm);
 	sdp_put_seq(&rec, 5);
 	sdp_put_uuid16(&rec, SDP_UUID_PROTOCOL_RFCOMM);
-	sdp_put_uint8(&rec, channel);
+	sdp_put_uint8(&rec, sa.bt_channel);
 
 	sdp_put_uint16(&rec, SDP_ATTR_BROWSE_GROUP_LIST);
 	sdp_put_seq(&rec, 3);
@@ -671,7 +678,7 @@
 	struct service *s;
 
 	fprintf(stderr, "Usage: %s [-d device] [-m mode] [-p psm] [-s service] [-t tty]\n"
-			"       %*s {-a bdaddr | -c channel}\n"
+			"       %*s {-a bdaddr | [-c channel]}\n"
 			"\n"
 			"Where:\n"
 			"\t-a bdaddr    remote device address\n"