From: Marcel Holtmann <marcel@holtmann.org>
To: BlueZ Mailing List <bluez-devel@lists.sourceforge.net>
Subject: Re: [Bluez-devel] Several bluetooth dongles at time
Date: Thu, 10 Feb 2005 13:41:30 +0100 [thread overview]
Message-ID: <1108039290.15974.33.camel@pegasus> (raw)
In-Reply-To: <50142.195.22.30.15.1108037990.squirrel@195.22.30.15>
Hi Matthias,
> I am runnning a rfcomm server on a linux pc and want mobile phones to
> connect to it.
> I need some clearence about the following questions:
>
> 1) As the phone is connecting to the pc and not the other way around, the
> pc is the slave at first. As far as I know a slave cannot connect to more
> than one device at time. So I force a role switch to master after
> connection. What happend when another phone will connect? The PC will be
> master from the beginning and no role switch is needed? (I don't have a
> second mobile to test, at the moment)
there will be transient state and therefor you need at least a dongle
that can do scatternet. Not all mobile phones support role switch. This
is a hardware limitation, because some of them contain an old chip.
> 2) Can i have multiple connections on the same rfcomm channel? So more
> than one mobile can connect to my server at time or only one device per
> channel and i have to open more than one channel?
One connection per RFCOMM channel. On the RFCOMM level there is no
further multiplexing.
> 3) If I have more than one bluetooth dongle how can I say which dongle to
> use for the connections? At the moment I am setting the field rc_bdaddr to
> the address of the bluetooth dongle I am willing to use. Is that about
> right? What happens if I am using BDADDR_ANY, BDADDR_ALL or BDADDR_LOCAL
> instead? Is there any convinient way that bluez automatically chooses
> another dongle if all connections on one dongle are full?
When writing a RFCOMM server you can bind it to a specific local address
or to all local addresses (ANY). The ALL and LOCAL addreses are not
useful for this and they also won't work.
After the connection you can use getsockname() to get the address of the
local device.
There is no load-balancing for connections. It is point-to-point and the
mobile phone in your case decides what dongle to connect to.
> This is the code I am using:
>
> int sock, client, alen;
> int dev;
>
> struct sockaddr_rc addr;
> if( (sock = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0)
> {
> perror("socket");
> exit(1);
> }
>
> addr.rc_family = AF_BLUETOOTH;
> bdaddr_t local;
> str2ba("00:10:60:A4:03:01", &local);
> bacpy(&addr.rc_bdaddr, &local);
> addr.rc_channel = htobs(channel);
> alen = sizeof(addr);
I don't know where you guys copy your examples from. The htobs() for the
channel is wrong. This value is only uint8_t and so it won't on big
endian platforms.
And for what is this crazy str->local->rc_bdaddr thing needed?
> if(bind(sock, (struct sockaddr *)&addr, alen) < 0)
> {
> perror("bind");
> exit(1);
> }
>
> listen(sock,10);
> printf("%d Waiting for connections...\n\n",channel);
>
> if(client = accept(sock, (struct sockaddr *)&addr, &alen))
> {
> printf("%d Got a connection attempt!\n",channel);
> }
>
> dev=hci_open_dev(0);
> if (dev<0) {
> printf("Error opening hci dev");
> exit(1);
>
> }
This thing here is wrong and will only work as long as only one dongle
is attached. You need to find the correct one, see getsockname() etc.
> if (hci_switch_role(dev, &addr.rc_bdaddr, 0, 10000) <0) {
> printf("Role switch failed!");
> }
> close(dev);
This reminds me that the RFCOMM_MASTER link mode support is missing.
Feel free to send me a patch for that instead of hacking around it.
Regards
Marcel
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
next prev parent reply other threads:[~2005-02-10 12:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-10 12:19 [Bluez-devel] Several bluetooth dongles at time schnelte
2005-02-10 12:41 ` Marcel Holtmann [this message]
2005-02-10 13:10 ` [Bluez-devel] HCI Forwarding radeX
2005-02-10 14:47 ` Marcel Holtmann
2005-02-11 18:51 ` [Bluez-devel] Several bluetooth dongles at time Matthias Schnelte
2005-02-11 19:03 ` Marcel Holtmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1108039290.15974.33.camel@pegasus \
--to=marcel@holtmann.org \
--cc=bluez-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox