* [Bluez-devel] rfcomm connection using multiple dongles
@ 2007-08-02 16:57 Stephen Keegan
2007-08-07 11:52 ` Marcel Holtmann
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Keegan @ 2007-08-02 16:57 UTC (permalink / raw)
To: bluez-devel
Hi,
I'd really appreciate some help on a problem I'm having. I've tried to
solve it myself but have been unable to do so for quite some time.
Basically, I want to create an rfcomm connection to a remote device
using 2 different dongles (at different times). My local devices are
shown here:
root@3[src]# hciconfig
hci0: Type: USB
BD Address: 00:0A:3A:66:62:57 ACL MTU: 1017:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:12081 acl:204 sco:0 events:308 errors:0
TX bytes:4672 acl:204 sco:0 commands:125 errors:0
hci1: Type: USB
BD Address: 00:0A:3A:66:63:31 ACL MTU: 1017:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:2535 acl:28 sco:0 events:77 errors:0
TX bytes:1044 acl:28 sco:0 commands:41 errors:0
Here is the code I am using:
****************************************************************************************************************
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
int main(int argc, char* argv[])
{
bdaddr_t m_bdaddrDongle;
char thedongle[20];
strcpy(thedongle,argv[1]);
if(argc != 3)
{
printf("%s <mac_address> <channel>\n\n", argv[0]);
return 1;
}
int dev_id = hci_devid( thedongle );
struct hci_dev_info m_DevInfo;
int dd = hci_open_dev(dev_id);
if (dd < 0)
{
printf("Error opening bluetooth device\n");
}
m_DevInfo.dev_id = dev_id;
if (ioctl(dd, HCIGETDEVINFO, (void*) &m_DevInfo))
{
printf("Error opening bluetooth device\n");
hci_close_dev(dd);
return 1;
}
char addr[18];
ba2str(&m_DevInfo.bdaddr, addr);
printf("Attached to BT adapter: %s\t%s\n", m_DevInfo.name, addr);
bacpy(&m_bdaddrDongle, &m_DevInfo.bdaddr);
struct sockaddr_rc laddr, raddr;
laddr.rc_family = AF_BLUETOOTH;
bacpy(&laddr.rc_bdaddr, &m_bdaddrDongle);
laddr.rc_channel = 0;
char remote_bdaddr[20] = "08:00:17:1B:13:DE";
printf("Remote Mac address: %s\n", remote_bdaddr);
raddr.rc_family = AF_BLUETOOTH;
str2ba(remote_bdaddr, &raddr.rc_bdaddr);
raddr.rc_channel = atoi(argv[2]);
printf("Channel: %d\n", raddr.rc_channel);
int m_CommHandle;
if ((m_CommHandle = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0)
{
printf("Can't create RFCOMM socketi\n");
return 1;
}
int r, e = 0;
errno = 0;
while ((r = connect(m_CommHandle, (struct sockaddr *)&raddr,
sizeof(raddr))) == -1)
{
e = errno;
if (e != EBUSY)
break;
errno = e = 0;
usleep(500000);
}
printf("r=%d; errno=%d; result=%s\n", r, e, strerror(e));
return r != 0;
}
****************************************************************************************************************
So then, I attempt to run the code with each of my dongles using the
following commands:
./test 00:0A:3A:66:63:31 6
and
./test 00:0A:3A:66:62:57 6
When I run the code, the connection is detected by the remote
device(08:00:17:1B:13:DE) and the connection is created successfully.
The problem is that each time I run the code, the first dongle (hci0) is
used by the bluetooth stack. (That dongle starts flashing). Why is this?
I believe that it is due to a problem with the command:
while ((r = connect(m_CommHandle, (struct sockaddr *)&raddr,
sizeof(raddr))) == -1)
I think that I may need to specify which dongle (hc0 or hci1) should be
used in this command.
If anybody could advise on a solution, I would be very grateful.
regards,
Stephen.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bluez-devel] rfcomm connection using multiple dongles
[not found] <mailman.159099.1186455104.21973.bluez-devel@lists.sourceforge.net>
@ 2007-08-07 11:20 ` Stephen Keegan
2007-08-07 12:30 ` Heiko Wundram (Beenic)
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Keegan @ 2007-08-07 11:20 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1.1: Type: text/plain, Size: 3705 bytes --]
hi-Can anybody offer some sort of solution for this? if somebody could,
I could offer some sort of reward. regards. S.
*[Bluez-devel] rfcomm connection using multiple dongles*
From: Stephen Keegan <stephen.keegan@uc...> - 2007-08-02 16:58
Hi,
I'd really appreciate some help on a problem I'm having. I've tried to
solve it myself but have been unable to do so for quite some time.
Basically, I want to create an rfcomm connection to a remote device
using 2 different dongles (at different times). My local devices are
shown here:
root@3[src]# hciconfig
hci0: Type: USB
BD Address: 00:0A:3A:66:62:57 ACL MTU: 1017:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:12081 acl:204 sco:0 events:308 errors:0
TX bytes:4672 acl:204 sco:0 commands:125 errors:0
hci1: Type: USB
BD Address: 00:0A:3A:66:63:31 ACL MTU: 1017:8 SCO MTU: 64:8
UP RUNNING PSCAN ISCAN
RX bytes:2535 acl:28 sco:0 events:77 errors:0
TX bytes:1044 acl:28 sco:0 commands:41 errors:0
Here is the code I am using:
****************************************************************************************************************
#include <errno.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
int main(int argc, char* argv[])
{
bdaddr_t m_bdaddrDongle;
char thedongle[20];
strcpy(thedongle,argv[1]);
if(argc != 3)
{
printf("%s <mac_address> <channel>\n\n", argv[0]);
return 1;
}
int dev_id = hci_devid( thedongle );
struct hci_dev_info m_DevInfo;
int dd = hci_open_dev(dev_id);
if (dd < 0)
{
printf("Error opening bluetooth device\n");
}
m_DevInfo.dev_id = dev_id;
if (ioctl(dd, HCIGETDEVINFO, (void*) &m_DevInfo))
{
printf("Error opening bluetooth device\n");
hci_close_dev(dd);
return 1;
}
char addr[18];
ba2str(&m_DevInfo.bdaddr, addr);
printf("Attached to BT adapter: %s\t%s\n", m_DevInfo.name, addr);
bacpy(&m_bdaddrDongle, &m_DevInfo.bdaddr);
struct sockaddr_rc laddr, raddr;
laddr.rc_family = AF_BLUETOOTH;
bacpy(&laddr.rc_bdaddr, &m_bdaddrDongle);
laddr.rc_channel = 0;
char remote_bdaddr[20] = "08:00:17:1B:13:DE";
printf("Remote Mac address: %s\n", remote_bdaddr);
raddr.rc_family = AF_BLUETOOTH;
str2ba(remote_bdaddr, &raddr.rc_bdaddr);
raddr.rc_channel = atoi(argv[2]);
printf("Channel: %d\n", raddr.rc_channel);
int m_CommHandle;
if ((m_CommHandle = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)) < 0)
{
printf("Can't create RFCOMM socketi\n");
return 1;
}
int r, e = 0;
errno = 0;
while ((r = connect(m_CommHandle, (struct sockaddr *)&raddr,
sizeof(raddr))) == -1)
{
e = errno;
if (e != EBUSY)
break;
errno = e = 0;
usleep(500000);
}
printf("r=%d; errno=%d; result=%s\n", r, e, strerror(e));
return r != 0;
}
****************************************************************************************************************
So then, I attempt to run the code with each of my dongles using the
following commands:
./test 00:0A:3A:66:63:31 6
and
./test 00:0A:3A:66:62:57 6
When I run the code, the connection is detected by the remote
device(08:00:17:1B:13:DE) and the connection is created successfully.
The problem is that each time I run the code, the first dongle (hci0) is
used by the bluetooth stack. (That dongle starts flashing). Why is this?
I believe that it is due to a problem with the command:
while ((r = connect(m_CommHandle, (struct sockaddr *)&raddr,
sizeof(raddr))) == -1)
I think that I may need to specify which dongle (hc0 or hci1) should be
used in this command.
If anybody could advise on a solution, I would be very grateful.
regards,
Stephen.
[-- Attachment #1.2: Type: text/html, Size: 5229 bytes --]
[-- Attachment #2: Type: text/plain, Size: 315 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
[-- Attachment #3: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Bluez-devel] rfcomm connection using multiple dongles
2007-08-02 16:57 [Bluez-devel] rfcomm connection using multiple dongles Stephen Keegan
@ 2007-08-07 11:52 ` Marcel Holtmann
0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2007-08-07 11:52 UTC (permalink / raw)
To: BlueZ development
Hi Stephen,
> I'd really appreciate some help on a problem I'm having. I've tried to
> solve it myself but have been unable to do so for quite some time.
> Basically, I want to create an rfcomm connection to a remote device
> using 2 different dongles (at different times). My local devices are
> shown here:
the function you are looking for is hci_devba() which gives you the
local BD_ADDR of an adapter that then have to be used for bind().
Regards
Marcel
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Bluez-devel] rfcomm connection using multiple dongles
2007-08-07 11:20 ` Stephen Keegan
@ 2007-08-07 12:30 ` Heiko Wundram (Beenic)
0 siblings, 0 replies; 4+ messages in thread
From: Heiko Wundram (Beenic) @ 2007-08-07 12:30 UTC (permalink / raw)
To: BlueZ development
Am Dienstag 07 August 2007 13:20:06 schrieb Stephen Keegan:
> while ((r = connect(m_CommHandle, (struct sockaddr *)&raddr,
> sizeof(raddr))) == -1)
>
> I think that I may need to specify which dongle (hc0 or hci1) should be
> used in this command.
>
> If anybody could advise on a solution, I would be very grateful.
bind() the RFCOMM socket to the local BT-address of the dongle you want to use
before connecting it.
man 2 bind
is your friend.
--
Heiko Wundram
Product & Application Development
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-08-07 12:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-02 16:57 [Bluez-devel] rfcomm connection using multiple dongles Stephen Keegan
2007-08-07 11:52 ` Marcel Holtmann
[not found] <mailman.159099.1186455104.21973.bluez-devel@lists.sourceforge.net>
2007-08-07 11:20 ` Stephen Keegan
2007-08-07 12:30 ` Heiko Wundram (Beenic)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox