obexapp alloc server channel

Iain Hibbert plunky at rya-online.net
Tue Nov 2 22:26:31 UTC 2010


Hi,

one more thing for obexapp, I think FreeBSD has the thing of RFCOMM where
you can bind() to channel 0 and use getsockname() after listen() in order
to find the allocated channel?  It was discussed on the list some time ago
anyway, and I did implement it on NetBSD (using RFCOMM_CHANNEL_ANY == 0)

The patch attached implements this functionality in obexapp, allowing -C
to be optional in server mode.

regards,
iain

btw I implemented similar for L2CAP except that binding to L2CAP_PSM_ANY
gets you one of the dynamic PSM (1001->) after listen() call
-------------- next part --------------
--- main.c.orig	2010-10-22 07:29:06.000000000 +0100
+++ main.c	2010-11-02 22:05:08.000000000 +0000
@@ -266,7 +266,7 @@
 		}
 	}
 
-	if (context.channel <= 0 || context.channel > 30)
+	if ((context.channel == 0 && !context.server) || context.channel > 30)
 		errx(1, "Invalid RFCOMM channel %d",
 			context.channel);
 
--- transport.c.orig	2010-10-22 07:29:06.000000000 +0100
+++ transport.c	2010-11-02 22:11:19.000000000 +0000
@@ -202,6 +202,16 @@
 		return (-1);
 	}
 
+	if (context->channel == 0) {
+		addrlen = sizeof(addr);
+		if (getsockname(s, (struct sockaddr *) &addr, &addrlen) < 0) {
+			log_err("%s(): Could not get socket address. %s (%d)",
+				__func__,  strerror(errno), errno);
+			return (-1);
+		}
+		context->channel = addr.rfcomm_channel;
+	}
+
 	memset(&opush, 0, sizeof(opush));
 	opush.server_channel = context->channel;
 	opush.supported_formats_size = 7;
--- obexapp.1.orig	2009-08-20 22:57:18.000000000 +0100
+++ obexapp.1	2010-11-02 22:21:36.000000000 +0000
@@ -54,7 +54,7 @@
 .Fl s
 .Op Fl dDFOSRh
 .Op Fl A Ar BD_ADDR
-.Fl C Ar channel
+.Op Fl C Ar channel
 .Op Fl m Ar MTU
 .Op Fl r Ar path
 .Op Fl u Ar user
@@ -117,8 +117,9 @@ The path component of the constructed re
 .Pp
 In the server mode
 .Nm
-listens for incomming connections, on the specified BD_ADDR and channel, from
-remote clients.
+listens for incomming connections, on the specified BD_ADDR and channel
+when given, from remote clients.
+If no channel is given, the first unused RFCOMM channel will be allocated.
 Once new connection is accepted
 .Nm
 forks and start new OBEX server for the client.
@@ -145,7 +146,7 @@ If not specified, BDADDR_ANY will be use
 In the client mode this required option specifies the remote BD_ADDR of the
 OBEX server.
 .It Fl C Ar channel
-In both client and server modes this required option specifies RFCOMM channel
+In both client and server modes this option specifies RFCOMM channel
 to connect to or listen on.
 In the server mode RFCOMM channel should be number between 1 and 30.
 In the client mode RFCOMM channel could be either number between 1 and 30 or


More information about the freebsd-bluetooth mailing list