Skip to contentSkip to conversation

Issues with multiple (concurrent) rfcomm connections

Bluez-users George Fankhauser 2 participants 4 messages Jan 9, 2005 – Jan 11, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Dear all

I just ran across an issue with setting up multiple rfcomm connections from a linux laptop with kernel 2.4.28-mh1 using an Anycom USB-120 dongle with Silicon Wave chipset.

I just tried to maintain 2 connections to 2 seperate commercial rs232 adapters (roalan wcs 232) using the socket API (test source attached). While connection setup is ok, and reconnects (e.g. after powerfail of peers) work too for a single device, running the same procedure in parallel leads to a behavor where no more sockets can be opened. It starts with a write failed to the socket (ok so far), but the following connection attempts lead to errors 16 (resource or device busy) and 11 (resource temp. unavailable) or 110 (timeout). From this state, the system does not recover and all bluez modules have to be reloaded ;-(

as an alternative I tried the same thing using seperate processes instead of threads or, using the rfcomm utility and cat for sending data. I always end up with the same errors.

I wonder whether this problem is known, or related to Silicon Wave. Could anyone try this with a CSR based system?

thanks and regards
George

-----------

compile with

	gcc -g -c -std=c99 prog.c
	gcc -lbluetooth -lpthread prog.o -o prog

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

#include <errno.h>

#include <sys/time.h>
#include <sys/select.h>
#include <sys/socket.h>

#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>

#define TESTSIZE 10

void do_rw(int s) {
	char x[TESTSIZE];
	char y[TESTSIZE];
	int err, count = 0;

	for (int i = 0; i < TESTSIZE; i++) { x[i] = (s + i) % 10 + '0'; }

	while(1) {
		fd_set fds;
		struct timeval t = {0,0};
		
		FD_ZERO(&fds);
		select(s, &fds, NULL, NULL, &t);
		
		if (FD_ISSET(s, &fds)) {
			err = read(s, y, TESTSIZE);
			if (err < 0) { printf("read: %d\n", err); perror(""); }
			else if (err == 0) {}
			else { printf("read %d bytes\n", err); }
		}		
		
		err = write(s, x, TESTSIZE);
		if (err < 0) {
			printf("cannot write to socket %d: %d (errno=%d)\n", s, err, errno);
			perror("");
			if (errno == 11) { sleep(1); continue; }
			break;
		} else if (err == 0) {
			printf("write returns 0\n");
		} else if (err != TESTSIZE) {
			printf("bytes written < bytes to write\n (%d < %d)\n", err, TESTSIZE);
		} else {
			if (!(count++ % 10)) { printf("%d ", s); fflush(NULL); }
		}
		//sleep(1);
	}
}
void do_connect(char* addrstring) {
	int s, err;
	struct sockaddr_rc addr;

	s = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
	if (s < 0) {
		printf("socket failed\n");
		return;
	}
	printf("do_connect %s, sock no %d\n", addrstring, s);
		
	addr.rc_family = AF_BLUETOOTH;
	bacpy(&addr.rc_bdaddr, BDADDR_ANY);
	addr.rc_channel = 0;
	err = bind(s, (struct sockaddr *)&addr, sizeof(addr));
	if (err < 0) {
		printf("bind failed: %d (errno=%d)\n", err, errno);
		perror("");
		close(s);
		return;
	}
	addr.rc_family = AF_BLUETOOTH;
	str2ba(addrstring, &addr.rc_bdaddr);
	addr.rc_channel = 1;
	err = connect(s, (struct sockaddr *)&addr, sizeof(addr));
	
	if (err == 0) {
		printf("connection established\n");
		do_rw(s);
	}
	else {
		printf("connect failed: %d (errno=%d)\n", err, errno);
		perror("");
	}
	close(s);
}

void* thread_main(void* addrstring)

{
	while(1) {
		do_connect((char*)addrstring);		
		sleep(1);
	}
}
int main(int argc, char **argv) {
	pthread_t       thread1;
	pthread_t       thread2;
		
	pthread_create(&thread1, NULL, thread_main, "00:02:78:02:84:CB"); // rs232 (2)
	pthread_create(&thread2, NULL, thread_main, "00:02:78:02:85:84");//WCS-232 (3)

	//single threads or sep. processes
	//thread_main("00:02:78:02:84:CB");
	//thread_main("00:02:78:02:85:84");
	
	while (1) sleep(1);

	printf("main exit...\n");
}

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

maintainer
#1 lore raw

Hi George,

Quoted 13 lines

I just ran across an issue with setting up multiple rfcomm connections from a linux laptop with kernel 2.4.28-mh1 using an Anycom USB-120 dongle with Silicon Wave chipset.

I just tried to maintain 2 connections to 2 seperate commercial rs232 adapters (roalan wcs 232) using the socket API (test source attached). While connection setup is ok, and reconnects (e.g. after powerfail of peers) work too for a single device, running the same procedure in parallel leads to a behavor where no more sockets can be opened. It starts with a write failed to the socket (ok so far), but the following connection attempts lead to errors 16 (resource or device busy) and 11 (resource temp. unavailable) or 110 (timeout). From this state, the system does not recover and all bluez modules have to be reloaded ;-(

Quoted 6 lines

as an alternative I tried the same thing using seperate processes instead of threads or, using the rfcomm utility and cat for sending data. I always end up with the same errors.

I wonder whether this problem is known, or related to Silicon Wave. Could anyone try this with a CSR based system?

try to reproduce it with a 2.6.10-mh1 kernel.

Regards

Marcel

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

#2 lore raw
Quoted 4 lines · Marcel Holtmann <marcel <at> holtmann.org> writes:

Hi George,

Quoted 1 line

I just ran across an issue with setting up multiple rfcomm connections

from a

Quoted 1 line
Quoted 1 line

linux laptop with kernel 2.4.28-mh1 using an Anycom USB-120 dongle with

Silicon

Quoted 3 lines
Quoted 3 lines

Wave chipset.

I just tried to maintain 2 connections to 2 seperate commercial rs232

[...]

Quoted 6 lines
Quoted 3 lines

I wonder whether this problem is known, or related to Silicon Wave. Could anyone try this with a CSR based system?

try to reproduce it with a 2.6.10-mh1 kernel.

Marcel

you're right, 2.6.10-mh works fine; no problems and reasonably fast reconnects after all kinds of reset, power loss, etc. Very well done!

also, it seems to be independent of SiW or CSR chip set... (changed the bt adapter too...)

Is there a chance to seperate this issue and have it back-ported to 2.4?

best regards
George

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users

maintainer
#3 lore raw

Hi George,

Quoted 7 lines

you're right, 2.6.10-mh works fine; no problems and reasonably fast reconnects after all kinds of reset, power loss, etc. Very well done!

also, it seems to be independent of SiW or CSR chip set... (changed the bt adapter too...)

Is there a chance to seperate this issue and have it back-ported to 2.4?

there are so many changes that are not backported to 2.4 and at the moment I have to no idea which one will help you. Why don't you use a 2.6 kernel?

Regards

Marcel

-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek. It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
Bluez-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users