public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* RFComm dynamic channel allocation
@ 2004-05-21 11:17 Stephen Crane
  2004-07-08 13:02 ` [Bluez-devel] " Collin R. Mulliner
  0 siblings, 1 reply; 2+ messages in thread
From: Stephen Crane @ 2004-05-21 11:17 UTC (permalink / raw)
  To: bluez-devel; +Cc: marcel

[-- Attachment #1: Type: text/plain, Size: 496 bytes --]

Hi,
The attached patch (against 2.6.6) provides dynamic channel allocation
for RFComm listening sockets. This means that you can bind to channel #0
and the kernel will allocate a channel for you when you call listen() on
it. Retrieve the allocated channel number via getsockname().

The only query I have is what to return if there are no free channels.
Is ENOMEM right?

Steve
-- 
Stephen Crane, Rococo Software Ltd. http://www.rococosoft.com
steve.crane@rococosoft.com +353-1-6601315 (ext 209)

[-- Attachment #2: rfcomm.dynamic.patch --]
[-- Type: text/x-patch, Size: 564 bytes --]

--- net/bluetooth/rfcomm/sock.c-	2004-05-21 11:49:58.375676516 +0100
+++ net/bluetooth/rfcomm/sock.c	2004-05-21 12:00:33.374126744 +0100
@@ -397,6 +397,19 @@
 		err = -EBADFD;
 		goto done;
 	}
+	if (!rfcomm_pi(sk)->channel) {
+		u8 channel;
+		bdaddr_t *src = &bt_sk(sk)->src;
+		for (channel = 1; channel < 31; channel++)
+			if (!__rfcomm_get_sock_by_addr(channel, src)) {
+				rfcomm_pi(sk)->channel = channel;
+				break;
+			}
+		if (channel == 31) {
+			err = -ENOMEM;
+			goto done;
+		}
+	}
 
 	sk->sk_max_ack_backlog = backlog;
 	sk->sk_ack_backlog = 0;

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Bluez-devel] RFComm dynamic channel allocation
  2004-05-21 11:17 RFComm dynamic channel allocation Stephen Crane
@ 2004-07-08 13:02 ` Collin R. Mulliner
  0 siblings, 0 replies; 2+ messages in thread
From: Collin R. Mulliner @ 2004-07-08 13:02 UTC (permalink / raw)
  To: bluez-devel

Hi,

does the dynamic rfcomm channel allocation work? I'm running 2.6.7-mh1
and I allways get channel 1, which is used (listend and connected) by a
other process. I don't get any error it just binds and listens on
channel 1.

cat /proc/bluetooth/rfcomm/sock 

/* created thru: rfcomm listen /dev/rfcomm0 1 */
00:00:00:00:00:00 00:00:00:00:00:00 4 1
00:00:00:00:00:00 00:00:00:00:00:00 2 0
/* created thru: running my server */
xx:xx:xx:xx:xx:xx 00:00:00:00:00:00 4 1

my code:

server_sa.rc_family = AF_BLUETOOTH;
server_sa.rc_channel = channel;		
server_sa.rc_bdaddr = self.addr;

if (bind(server, (struct sockaddr*) &server_sa, sizeof(server_sa)) < 0){
 return(-1);
}
		
if (listen(server, 1) < 0) {
 return(-1);
}
	
if (channel == 0) {
 remote_len = sizeof(struct sockaddr_rc);
 memset(&remote_sa, 0, sizeof(struct sockaddr_rc));
 if (getsockname(server, (struct sockaddr*) &remote_sa, &remote_len) <
	0) {
  return(-1);
 }

 channel = remote_sa.rc_channel;
 printf("bt_server(): channel %d\n", remote_sa.rc_channel);		}
			
thanks ... Collin

-- 
Collin R. Mulliner <collin@betaversion.net>
BETAVERSiON Systems [www.betaversion.net]
info/pgp: finger collin@betaversion.net
To know recursion, you must first know recursion.


-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 - 
digital self defense, top technical experts, no vendor pitches, 
unmatched networking opportunities. Visit www.blackhat.com
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-07-08 13:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-21 11:17 RFComm dynamic channel allocation Stephen Crane
2004-07-08 13:02 ` [Bluez-devel] " Collin R. Mulliner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox