From: Stephen Keegan <stephen.keegan@ucd.ie>
To: bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] rfcomm connection using multiple dongles
Date: Thu, 02 Aug 2007 17:57:47 +0100 [thread overview]
Message-ID: <46B20D0B.7000106@ucd.ie> (raw)
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
next reply other threads:[~2007-08-02 16:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-02 16:57 Stephen Keegan [this message]
2007-08-07 11:52 ` [Bluez-devel] rfcomm connection using multiple dongles 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)
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=46B20D0B.7000106@ucd.ie \
--to=stephen.keegan@ucd.ie \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.