* [Bluez-devel] HCI forwarding
@ 2005-01-02 4:29 radeX
2005-01-02 11:39 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: radeX @ 2005-01-02 4:29 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 1488 bytes --]
Hi everybody:
I've been months reading the bluez source and learning about the bluetooth
specification, plus other documents (the correct coding style, Wireless
Technologies Congress 2003 and other documents by Marcel holtmann)
I'm developing an application to connect two Bluetooth-enabled phones via
internet using two Bluetooth-enabled PCs both connected to internet. I mean
that I can transmit files and play Bluetooth multiplayer games to my friend
that is 25 miles away like if it were in my device's Bluetooth radio range.
(I know that ping times would be very ugly!).
I use a raw socket as hcidump does, then I send the data trough TCP to the
other peer, when received is sent over Bluetooth hoping that the other
device receives it, this is more complex than it seems since bluez handles
and answers all HCI requests, i.e (when a device performs a SDP request to
find a service UUID bluez handles and answers the request) but this is not
correct for my application, hci responses and data acks may be received via
TCP from the other peer, in other words: no bluez support, only HCI frames
sniffing, sending, receiving and transmitting. Now my questions are:
- Can I send HCI frames with a raw socket ?
- How can I tell the bluez stack not to answer HCI requests
(receiving only, leave the sends to me).
- Is there a better way to make this application?
Any help would be greatly appreciated.
Thanks in advance and happy new year.
[-- Attachment #2: Type: text/html, Size: 6474 bytes --]
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] HCI forwarding
2005-01-02 4:29 [Bluez-devel] HCI forwarding radeX
@ 2005-01-02 11:39 ` Marcel Holtmann
2005-01-02 16:58 ` radeX
0 siblings, 1 reply; 14+ messages in thread
From: Marcel Holtmann @ 2005-01-02 11:39 UTC (permalink / raw)
To: BlueZ Mailing List
Hi,
> I=FFm developing an application to connect two Bluetooth-enabled phones
> via internet using two Bluetooth-enabled PCs both connected to
> internet. I mean that I can transmit files and play Bluetooth
> multiplayer games to my friend that is 25 miles away like if it were
> in my device=FFs Bluetooth radio range. (I know that ping times would b=
e
> very ugly!).
>=20
> I use a raw socket as hcidump does, then I send the data trough TCP to
> the other peer, when received is sent over Bluetooth hoping that the
> other device receives it, this is more complex than it seems since
> bluez handles and answers all HCI requests, i.e (when a device
> performs a SDP request to find a service UUID bluez handles and
> answers the request) but this is not correct for my application, hci
> responses and data acks may be received via TCP from the other peer,
> in other words: no bluez support, only HCI frames sniffing, sending,
> receiving and transmitting. Now my questions are:
>=20
> =20
>=20
> - Can I send HCI frames with a raw socket ?
yes, you can.
> - How can I tell the bluez stack not to answer HCI requests
> (receiving only, leave the sends to me).
Set the device into raw mode. This should stop any processing.
> - Is there a better way to make this application?
Use the hci_vhci driver.
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [Bluez-devel] HCI forwarding
2005-01-02 11:39 ` Marcel Holtmann
@ 2005-01-02 16:58 ` radeX
2005-01-02 17:32 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: radeX @ 2005-01-02 16:58 UTC (permalink / raw)
To: bluez-devel
> Set the device into raw mode. This should stop any processing.
Thanks, this really helped, with de hci device in raw mode now bluez does
not attend the hci requests, but... how do I transmit hci frames?, simply by
using send() function with the raw socket? (I'm doing this. I hope the
frames to be sent to all bt devices in range of my usb dongle).
> Use the hci_vhci driver.
How would be useful the virtual hci driver for this purpose? Did you mean
that I must set a virtual hci device for receiving and transmitting hci
traffic?, would it work even if hci_vhci is not attached to a real bt radio?
- Will do all game and application traffic (L2CAP and RFCOMM connections are
used only) go trough the hci traffic I'm forwarding? (I've seen that device
discovery (COD detection, clock offset....) is not sniffed with the raw
socket).
I think that's all.
Regards.
Thank you very much - I'll give you credit in the authors section. ;)
-----Mensaje original-----
De: bluez-devel-admin@lists.sourceforge.net
[mailto:bluez-devel-admin@lists.sourceforge.net] En nombre de Marcel
Holtmann
Enviado el: domingo, 02 de enero de 2005 12:39
Para: BlueZ Mailing List
Asunto: Re: [Bluez-devel] HCI forwarding
Hi,
> I'm developing an application to connect two Bluetooth-enabled phones
> via internet using two Bluetooth-enabled PCs both connected to
> internet. I mean that I can transmit files and play Bluetooth
> multiplayer games to my friend that is 25 miles away like if it were
> in my device's Bluetooth radio range. (I know that ping times would be
> very ugly!).
>
> I use a raw socket as hcidump does, then I send the data trough TCP to
> the other peer, when received is sent over Bluetooth hoping that the
> other device receives it, this is more complex than it seems since
> bluez handles and answers all HCI requests, i.e (when a device
> performs a SDP request to find a service UUID bluez handles and
> answers the request) but this is not correct for my application, hci
> responses and data acks may be received via TCP from the other peer,
> in other words: no bluez support, only HCI frames sniffing, sending,
> receiving and transmitting. Now my questions are:
>
>
>
> - Can I send HCI frames with a raw socket ?
yes, you can.
> - How can I tell the bluez stack not to answer HCI requests
> (receiving only, leave the sends to me).
Set the device into raw mode. This should stop any processing.
> - Is there a better way to make this application?
Use the hci_vhci driver.
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
-------------------------------------------------------
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [Bluez-devel] HCI forwarding
2005-01-02 16:58 ` radeX
@ 2005-01-02 17:32 ` Marcel Holtmann
2005-01-02 19:02 ` radeX
0 siblings, 1 reply; 14+ messages in thread
From: Marcel Holtmann @ 2005-01-02 17:32 UTC (permalink / raw)
To: BlueZ Mailing List
Hi,
> > Set the device into raw mode. This should stop any processing.
>
> Thanks, this really helped, with de hci device in raw mode now bluez does
> not attend the hci requests, but... how do I transmit hci frames?, simply by
> using send() function with the raw socket? (I'm doing this. I hope the
> frames to be sent to all bt devices in range of my usb dongle).
the HCI is for using the local Bluetooth chip. You can deal with HCI
interfaces of remote chips. You write HCI commands and read HCI event on
the HCI raw socket.
> > Use the hci_vhci driver.
>
> How would be useful the virtual hci driver for this purpose? Did you mean
> that I must set a virtual hci device for receiving and transmitting hci
> traffic?, would it work even if hci_vhci is not attached to a real bt radio?
Look at hciemu. It uses hci_vhci to emulate a Bluetooth device.
> - Will do all game and application traffic (L2CAP and RFCOMM connections are
> used only) go trough the hci traffic I'm forwarding? (I've seen that device
> discovery (COD detection, clock offset....) is not sniffed with the raw
> socket).
Parts of this are LMP or lower. You won't get them.
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [Bluez-devel] HCI forwarding
2005-01-02 17:32 ` Marcel Holtmann
@ 2005-01-02 19:02 ` radeX
2005-01-02 19:21 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: radeX @ 2005-01-02 19:02 UTC (permalink / raw)
To: bluez-devel
Understood!
Device detection is not a problem since bluez does it for me (I only have to
set the local class of device to the correct value (0x500204) in order to
deceiving mobile phones in both sides). I conform with forwarding L2CAP and
RFCOMM profile connection data, SDP and the rest of necessary HCI commands
and events to make possible a long-distance L2CAP / RFCOMM session.
Is this possible in this way?, In other?, Am I wrong?
(I wrote the app sniffing and forwarding hci frames (it seems that "works")
but I had no chance for testing it).
Hciemu reading in progess ;)
Regards.
-----Mensaje original-----
De: bluez-devel-admin@lists.sourceforge.net
[mailto:bluez-devel-admin@lists.sourceforge.net] En nombre de Marcel
Holtmann
Enviado el: domingo, 02 de enero de 2005 18:32
Para: BlueZ Mailing List
Asunto: RE: [Bluez-devel] HCI forwarding
Hi,
> > Set the device into raw mode. This should stop any processing.
>
> Thanks, this really helped, with de hci device in raw mode now bluez does
> not attend the hci requests, but... how do I transmit hci frames?, simply
by
> using send() function with the raw socket? (I'm doing this. I hope the
> frames to be sent to all bt devices in range of my usb dongle).
the HCI is for using the local Bluetooth chip. You can deal with HCI
interfaces of remote chips. You write HCI commands and read HCI event on
the HCI raw socket.
> > Use the hci_vhci driver.
>
> How would be useful the virtual hci driver for this purpose? Did you mean
> that I must set a virtual hci device for receiving and transmitting hci
> traffic?, would it work even if hci_vhci is not attached to a real bt
radio?
Look at hciemu. It uses hci_vhci to emulate a Bluetooth device.
> - Will do all game and application traffic (L2CAP and RFCOMM connections
are
> used only) go trough the hci traffic I'm forwarding? (I've seen that
device
> discovery (COD detection, clock offset....) is not sniffed with the raw
> socket).
Parts of this are LMP or lower. You won't get them.
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
-------------------------------------------------------
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [Bluez-devel] HCI forwarding
2005-01-02 19:02 ` radeX
@ 2005-01-02 19:21 ` Marcel Holtmann
2005-01-02 20:26 ` radeX
0 siblings, 1 reply; 14+ messages in thread
From: Marcel Holtmann @ 2005-01-02 19:21 UTC (permalink / raw)
To: BlueZ Mailing List
Hi,
> Device detection is not a problem since bluez does it for me (I only have to
> set the local class of device to the correct value (0x500204) in order to
> deceiving mobile phones in both sides). I conform with forwarding L2CAP and
> RFCOMM profile connection data, SDP and the rest of necessary HCI commands
> and events to make possible a long-distance L2CAP / RFCOMM session.
forwarding L2CAP channels or also ACL data packets is very easy. However
the ACL MTU should match. The role switches might be a little tricky.
Forwarding the HCI commands and events is not that easy. You must keep
an eye on the flow control mechanism of HCI, but this is all still
doable and there are more ways for doing it.
> Is this possible in this way?, In other?, Am I wrong?
> (I wrote the app sniffing and forwarding hci frames (it seems that "works")
> but I had no chance for testing it).
It is possible and the best way depends on what you wanna do. Basically
I used L2CAP and RFCOMM forwarding a lot of this to crack protocol stuff
that was going on between some devices. Best example is the Nokia PhoNet
protocol.
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [Bluez-devel] HCI forwarding
2005-01-02 19:21 ` Marcel Holtmann
@ 2005-01-02 20:26 ` radeX
2005-01-02 20:45 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: radeX @ 2005-01-02 20:26 UTC (permalink / raw)
To: bluez-devel
Hi again Marcel:
Ok, I'll keep track of the ACL MTU's.
I'm a little lost in other implementation point:
If we have the A peer and B peer connected trough tcp, Imagine that the A
phone wants to connect B one, then it inquires and finds the hci device of
the A PC and sends the connection requests and all other stuff, these data
is sniffed with the A raw socket and forwarded to the B PC by TCP where is
sent over B's hci device again, but... hci frames from A phone may be sent
to the A PC's hci device's bluetooth address, not to B phone's Bluetooth
address, may this be a problem? Would I need to parse the frames to change
the destination address or change the A hci device address to B phone's
address and B one to A phone address?
Can I change the local chip BT address?
I'll try to get more familiar with this low-level Bluetooth stuff.
Thank you for spending your time helping me.
-----Mensaje original-----
De: bluez-devel-admin@lists.sourceforge.net
[mailto:bluez-devel-admin@lists.sourceforge.net] En nombre de Marcel
Holtmann
Enviado el: domingo, 02 de enero de 2005 20:21
Para: BlueZ Mailing List
Asunto: RE: [Bluez-devel] HCI forwarding
Hi,
> Device detection is not a problem since bluez does it for me (I only have
to
> set the local class of device to the correct value (0x500204) in order to
> deceiving mobile phones in both sides). I conform with forwarding L2CAP
and
> RFCOMM profile connection data, SDP and the rest of necessary HCI commands
> and events to make possible a long-distance L2CAP / RFCOMM session.
forwarding L2CAP channels or also ACL data packets is very easy. However
the ACL MTU should match. The role switches might be a little tricky.
Forwarding the HCI commands and events is not that easy. You must keep
an eye on the flow control mechanism of HCI, but this is all still
doable and there are more ways for doing it.
> Is this possible in this way?, In other?, Am I wrong?
> (I wrote the app sniffing and forwarding hci frames (it seems that
"works")
> but I had no chance for testing it).
It is possible and the best way depends on what you wanna do. Basically
I used L2CAP and RFCOMM forwarding a lot of this to crack protocol stuff
that was going on between some devices. Best example is the Nokia PhoNet
protocol.
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
-------------------------------------------------------
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* RE: [Bluez-devel] HCI forwarding
2005-01-02 20:26 ` radeX
@ 2005-01-02 20:45 ` Marcel Holtmann
0 siblings, 0 replies; 14+ messages in thread
From: Marcel Holtmann @ 2005-01-02 20:45 UTC (permalink / raw)
To: BlueZ Mailing List
Hi,
> I'm a little lost in other implementation point:
> If we have the A peer and B peer connected trough tcp, Imagine that the A
> phone wants to connect B one, then it inquires and finds the hci device of
> the A PC and sends the connection requests and all other stuff, these data
> is sniffed with the A raw socket and forwarded to the B PC by TCP where is
> sent over B's hci device again, but... hci frames from A phone may be sent
> to the A PC's hci device's bluetooth address, not to B phone's Bluetooth
> address, may this be a problem? Would I need to parse the frames to change
> the destination address or change the A hci device address to B phone's
> address and B one to A phone address?
maybe you need to map the ACL connection handle.
> Can I change the local chip BT address?
If you now the specific vendor address and if it is not a ROM chip then
you can. Ask the manufacturer for details.
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-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bluez-devel] Several bluetooth dongles at time
@ 2005-02-10 12:19 schnelte
2005-02-10 12:41 ` Marcel Holtmann
0 siblings, 1 reply; 14+ messages in thread
From: schnelte @ 2005-02-10 12:19 UTC (permalink / raw)
To: bluez-devel
Hi there,
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)
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?
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?
Tnx very much in advance for your answers.
Matthias
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);
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);
}
if (hci_switch_role(dev, &addr.rc_bdaddr, 0, 10000) <0) {
printf("Role switch failed!");
}
close(dev);
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] Several bluetooth dongles at time
2005-02-10 12:19 [Bluez-devel] Several bluetooth dongles at time schnelte
@ 2005-02-10 12:41 ` Marcel Holtmann
2005-02-10 13:10 ` [Bluez-devel] HCI Forwarding radeX
2005-02-11 18:51 ` [Bluez-devel] Several bluetooth dongles at time Matthias Schnelte
0 siblings, 2 replies; 14+ messages in thread
From: Marcel Holtmann @ 2005-02-10 12:41 UTC (permalink / raw)
To: BlueZ Mailing List
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [Bluez-devel] HCI Forwarding
2005-02-10 12:41 ` Marcel Holtmann
@ 2005-02-10 13:10 ` radeX
2005-02-10 14:47 ` Marcel Holtmann
2005-02-11 18:51 ` [Bluez-devel] Several bluetooth dongles at time Matthias Schnelte
1 sibling, 1 reply; 14+ messages in thread
From: radeX @ 2005-02-10 13:10 UTC (permalink / raw)
To: bluez-devel
Hi Marcel:
As you remember I was developing a gateway for tunneling the hci traffic
over TCP and be able to transfer files and play bluetooth games at long
distances.
I wrote a simple and very rudimentary C++ test program but didn't work. =
I
think the problem is the destination bluetooth address, would I need to
parse
the hci frames to set the bt address to its correct value?, I don't know
how to do this, I am really lost.
I tested the program with another friend running the same program with =
two
nokia n-gage.
If you can help me here is the source code, please feel free to modify
whatever
you want and tell me how can I solve this problem or give me a new way =
of
doing this.
(I marked up the important part of the main loop so you can see the main
idea witouth reading the full source), at the end is the program and =
hcidump
output.
If you want the full source (all files and makefile) tell me.
Thanks in advance.
-------------------------------------------------------------------------=
---
-
----main.cpp-----
#include <iostream.h>
#include <stdlib.h>
#include <sys/types.h>
#include <asm/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "btsniffer.h"
#include "Socket.h"
using namespace std;
bt_sniffer bt;
Socket sk;
int op;
fd_set master;
fd_set read_fds;
int fdmax;
int newfd;
struct timeval tv;
int menu()
{
int op;
system("clear");
cout << "Net-Gage testing program\n";
cout << "-------------------------\n";
cout << "[1] -- Connect to host\n";
cout << "[2] -- Wait for connections\n";
cout << "[0] -- Quit\n";
cout << " Select option: ";
cin >> op;
return op;
}
void loop() {
string buf;
int rres =3D 0;
int i;
tv.tv_sec =3D 2;
tv.tv_usec =3D 500000;
sk.set_non_blocking(true);
FD_SET(sk.m_sock, &master);
FD_SET(bt.sock, &master);
fdmax =3D bt.sock;
cout << "Connection complete!.\n";
cout << "---------------------\n";
cout << "Running .....\n";
cout << "<Press Ctrl-C to abort the program>\n";
for(;;) {
read_fds =3D master;
if(select(fdmax+1, &read_fds, NULL, &read_fds, &tv) =3D=3D -1) {
perror("select()!\n");
exit(1);
}
/********************/
/** IMPORTANT PART **/
/********************/
if((rres =3D bt.receive()) > 0) {
// BT Data received
cout << "BT Data received: " << bt.buf << endl;
sk.sendall(string(bt.buf));
}
if((rres =3D sk.recv(buf)) =3D=3D 0) {
// Connection closed
break;
} else {
if(rres > 0) {
// TCP Data received
cout << "TCP Data received: " << buf << endl;
bt.send(buf.c_str());
}
}
/***************************/
/** END OF IMPORTANT PART **/
/***************************/
}
FD_CLR( sk.m_sock,&master);
FD_CLR( bt.sock,&master);
cout << "Connection closed.\n";
}
void do_connect()
{
string ip;
cout << "Enter IP address of the opponent: ";
cin >> ip;
cout << "Connecting to " << ip << " at port 1984 ...\n";
sk.create();
if(!sk.connect(ip, 1984)) {
cout << "Connection failed !\n";
exit(1);
}
}
void do_listen()
{
sk.create();
if(!sk.bind(1984)) {
cout << "Socket error: bind()! \n";
exit(1);
}
cout << "Waiting for connections at port 1984 ...\n";
sk.listen();
while(!sk.accept(sk));
}
int main(void)
{
FD_ZERO(&master);
FD_ZERO(&read_fds);
cout << "Starting netgage ...\n";
bt.create();
sk.set_non_blocking(true);
bt.set_non_blocking(true);
op =3D menu();
switch(op) {
case 1:
do_connect();
break;
case 2:
do_listen();
break;
}
if(op) loop();
cout << "Thank you for testing this program!\n";
return EXIT_SUCCESS;
}
-------------------------------------------------------------------
-----btsniffer.cpp--------
#include "btsniffer.h"
#include "btsniffer_exception.h"
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
bt_sniffer::bt_sniffer()
{
one =3D 1;
}
int bt_sniffer::receive()
{
return recv(sock, buf, HCI_MAX_FRAME_SIZE, 0);
}
void bt_sniffer::send(const char * s)
{
::send(sock, s, HCI_MAX_FRAME_SIZE, 0);
}
void bt_sniffer::set_non_blocking ( const bool b )
{
int opts;
opts =3D fcntl ( sock,
F_GETFL );
if ( opts < 0 )
{
return;
}
if ( b )
opts =3D ( opts | O_NONBLOCK );
else
opts =3D ( opts & ~O_NONBLOCK );
fcntl ( sock,
F_SETFL,opts );
}
bool bt_sniffer::create()
{
if((sock =3D socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI)) < 0)
{
throw btsnifferException ( "Error creating socket" );
return false;
}
one =3D 1;
if(setsockopt(sock, SOL_HCI, HCI_DATA_DIR, &one, sizeof(one)) < 0)
{
throw btsnifferException ( "Can't enable data direction info" );
return false;
}
one =3D 1;
if(setsockopt(sock, SOL_HCI, HCI_TIME_STAMP, &one, sizeof(one)) < 0)
{
throw btsnifferException ( "Can't enable time stamp" );
return false;
}
hci_filter_clear(&filter);
hci_filter_all_ptypes(&filter);
hci_filter_all_events(&filter);
if(setsockopt(sock, SOL_HCI, HCI_FILTER, &filter, sizeof(filter)) < 0)
{
throw btsnifferException ( "Can't set HCI filter" );
return false;
}
addr.hci_family =3D AF_BLUETOOTH;
addr.hci_dev =3D 0;
if(bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
{
throw btsnifferException ( "Bind error" );
return false;
}
ioctl(sock, HCISETRAW);
return true;
}
-------------------------------------------------------------------------=
-
---- socket.cpp ----
// Implementation of the Socket class.
#include "Socket.h"
#include "string.h"
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <iostream.h>
using namespace std;
Socket::Socket() :
m_sock ( -1 )
{
memset ( &m_addr,
0,
sizeof ( m_addr ) );
}
Socket::~Socket()
{
if ( is_valid() )
::close ( m_sock );
}
bool Socket::create()
{
m_sock =3D socket ( AF_INET,
SOCK_STREAM,
0 );
if ( ! is_valid() )
return false;
// TIME_WAIT - argh
int on =3D 1;
if ( setsockopt ( m_sock, SOL_SOCKET, SO_REUSEADDR, ( const char* ) =
&on,
sizeof ( on ) ) =3D=3D -1 )
return false;
return true;
}
bool Socket::bind ( const int port )
{
if ( ! is_valid() )
{
return false;
}
m_addr.sin_family =3D AF_INET;
m_addr.sin_addr.s_addr =3D INADDR_ANY;
m_addr.sin_port =3D htons ( port );
memset(&(m_addr.sin_zero), '\0', 8);
int bind_return =3D ::bind ( m_sock,
( struct sockaddr * ) &m_addr,
sizeof ( m_addr ) );
if ( bind_return =3D=3D -1 )
{
return false;
}
return true;
}
bool Socket::listen() const
{
if ( ! is_valid() )
{
return false;
}
int listen_return =3D ::listen ( m_sock, MAXCONNECTIONS );
if ( listen_return =3D=3D -1 )
{
return false;
}
return true;
}
bool Socket::accept ( Socket& new_socket ) const
{
int addr_length =3D sizeof ( m_addr );
new_socket.m_sock =3D ::accept ( m_sock, ( sockaddr * ) &m_addr, ( =
socklen_t
* ) &addr_length );
if ( new_socket.m_sock <=3D 0 )
return false;
else
return true;
}
bool Socket::send ( const std::string s ) const
{
int status =3D ::send ( m_sock, s.c_str(), s.size(), MSG_NOSIGNAL );
if ( status =3D=3D -1 )
{
return false;
}
else
{
return true;
}
}
int Socket::recv ( std::string& s ) const
{
char buf [ MAXRECV + 1 ];
s =3D "";
memset ( buf, 0, MAXRECV + 1 );
int status =3D ::recv ( m_sock, buf, MAXRECV, 0 );
/* if ( status =3D=3D -1 )
{
// std::cout << "status =3D=3D -1 errno =3D=3D " << errno << " in =
Socket::recv\n";
return 0;
}
else if ( status =3D=3D 0 )
{
return 0;
}
else
{
*/ s =3D buf;
return status;
// }
}
bool Socket::connect ( const std::string host, const int port )
{
if ( ! is_valid() ) return false;
m_addr.sin_family =3D AF_INET;
m_addr.sin_port =3D htons ( port );
int status =3D inet_pton ( AF_INET, host.c_str(), &m_addr.sin_addr );
if ( errno =3D=3D EAFNOSUPPORT ) return false;
status =3D ::connect ( m_sock, ( sockaddr * ) &m_addr, sizeof ( m_addr =
)
);
if ( status =3D=3D 0 )
return true;
else
return false;
}
void Socket::set_non_blocking ( const bool b )
{
int opts;
opts =3D fcntl ( m_sock,
F_GETFL );
if ( opts < 0 )
{
return;
}
if ( b )
opts =3D ( opts | O_NONBLOCK );
else
opts =3D ( opts & ~O_NONBLOCK );
fcntl ( m_sock,
F_SETFL,opts );
}
bool Socket::sendall( const std::string s) const
{
int total =3D 0;
char * cstr =3D s.c_str();
int bytesleft =3D s.length();
int len =3D s.length();
int n;
while( total < len ) {
n =3D ::send(m_sock, cstr + total, bytesleft, 0);
if( n =3D=3D -1 ) break;
total +=3D n;
bytesleft -=3D n;
}
len =3D total;
return !(n=3D=3D-1);
}
--------------------------------------------------------
--- THE PROGRAM PRODUCED THIS HCIDUMP ---
HCIDump - HCI packet analyzer ver 1.16
device: hci0 snap_len: 1028 filter: 0xffffffff
< HCI Event: Connect Request (0x04) plen 10
< HCI Event: Connect Complete (0x03) plen 11
< HCI Event: Connect Request (0x04) plen 10
< HCI Event: Connect Complete (0x03) plen 11
< HCI Event: Connect Request (0x04) plen 10
< HCI Event: Connect Complete (0x03) plen 11
< HCI Event: Connect Request (0x04) plen 10
< HCI Event: Connect Complete (0x03) plen 11
< HCI Event: Connect Request (0x04) plen 10
< HCI Event: Connect Complete (0x03) plen 11
< HCI Event: Connect Request (0x04) plen 10
< HCI Event: Connect Complete (0x03) plen 11
< HCI Event: Connect Request (0x04) plen 10
< HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
> HCI Event: Connect Request (0x04) plen 10
> HCI Event: Connect Complete (0x03) plen 11
-------------------------------------------------------------------------=
---
-
---- AND THIS OUTPUT ----
Net-Gage testing program
-------------------------
[1] -- Connect to host
[2] -- Wait for connections
[3] -- Test console
[4] -- Other tests
[0] -- Quit
Select option: 2
Waiting for connections at port 1984 ...
Connection complete!.
---------------------
Running .....
<Press Ctrl-C to abort the program>
TCP Data received:
+=DCW`
TCP Data received:
)
TCP Data received:
+=DCW`
TCP Data received:
*
TCP Data received:
+=DCW`
TCP Data received:
)
TCP Data received:
+=DCW`
TCP Data received:
*
TCP Data received:
+=DCW`
TCP Data received:
)
TCP Data received:
+=DCW`
TCP Data received:
*
TCP Data received:
+=DCW`
TCP Data received:
)
BT Data received:
:=F5W`
BT Data received:
(
BT Data received:
:=F5W`
BT Data received:
)
BT Data received:
:=F5W`
BT Data received:
(
BT Data received:
:=F5W`
BT Data received:
)
BT Data received:
:=F5W`
BT Data received:
(
BT Data received:
:=F5W`
BT Data received:
)
BT Data received:
:=F5W`
BT Data received:
(
BT Data received:
:=F5W`
BT Data received:
)
BT Data received:
:=F5W`
Connection closed.
Thank you for testing this program!
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] HCI Forwarding
2005-02-10 13:10 ` [Bluez-devel] HCI Forwarding radeX
@ 2005-02-10 14:47 ` Marcel Holtmann
0 siblings, 0 replies; 14+ messages in thread
From: Marcel Holtmann @ 2005-02-10 14:47 UTC (permalink / raw)
To: BlueZ Mailing List
Hi,
> As you remember I was developing a gateway for tunneling the hci traffic
> over TCP and be able to transfer files and play bluetooth games at long
> distances.
> I wrote a simple and very rudimentary C++ test program but didn't work. I
> think the problem is the destination bluetooth address, would I need to
> parse
> the hci frames to set the bt address to its correct value?, I don't know
> how to do this, I am really lost.
> I tested the program with another friend running the same program with two
> nokia n-gage.
>
> If you can help me here is the source code, please feel free to modify
> whatever
> you want and tell me how can I solve this problem or give me a new way of
> doing this.
> (I marked up the important part of the main loop so you can see the main
> idea witouth reading the full source), at the end is the program and hcidump
> output.
>
> If you want the full source (all files and makefile) tell me.
using C++ is actually too much for such a project, because OO is useless
in this case and personally I don't like C++ and so I won't comment on
your code.
If you wanna do HCI forwarding then you must first use the HCI device in
raw mode and even then I don't think that this going to work. You must
map a lot of commands to events and vice versa. For example a connect
request from on side must result in a create connection on the other
side and then you must do the HCI flow control right.
And yes, you must do a BD_ADDR and also connection handle translation
for every command/event exchange. I am not sure if this will ever work,
but even if, it is a lot of work and you need a deep understanding of
the HCI.
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] Several bluetooth dongles at time
2005-02-10 12:41 ` Marcel Holtmann
2005-02-10 13:10 ` [Bluez-devel] HCI Forwarding radeX
@ 2005-02-11 18:51 ` Matthias Schnelte
2005-02-11 19:03 ` Marcel Holtmann
1 sibling, 1 reply; 14+ messages in thread
From: Matthias Schnelte @ 2005-02-11 18:51 UTC (permalink / raw)
To: bluez-devel
>>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.
So, if I have two phones that provide one service each, but both on the
same rfcomm channel i will not be able to connect to both of them, right?
Why is that? I mean, it is all brought done to l2cap connections and
l2cap is not limited in that case.
Hmm, so the only solution is to use l2cap instead of rfcomm, right?
Matthias
-------------------------------------------------------
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Bluez-devel] Several bluetooth dongles at time
2005-02-11 18:51 ` [Bluez-devel] Several bluetooth dongles at time Matthias Schnelte
@ 2005-02-11 19:03 ` Marcel Holtmann
0 siblings, 0 replies; 14+ messages in thread
From: Marcel Holtmann @ 2005-02-11 19:03 UTC (permalink / raw)
To: BlueZ Mailing List
Hi Matthias,
> >>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.
> So, if I have two phones that provide one service each, but both on the
> same rfcomm channel i will not be able to connect to both of them, right?
wrong. This limit is only a point-to-point limit. If you connect to
another phone the underlaying ACL link is different and so you won't
have any problem.
If you have a phone that provides for example FAX and DUN on channel 1
then you can't connect to FAX and DUN at the same time.
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
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2005-02-11 19:03 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-02-10 12:19 [Bluez-devel] Several bluetooth dongles at time schnelte
2005-02-10 12:41 ` Marcel Holtmann
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
-- strict thread matches above, loose matches on Subject: below --
2005-01-02 4:29 [Bluez-devel] HCI forwarding radeX
2005-01-02 11:39 ` Marcel Holtmann
2005-01-02 16:58 ` radeX
2005-01-02 17:32 ` Marcel Holtmann
2005-01-02 19:02 ` radeX
2005-01-02 19:21 ` Marcel Holtmann
2005-01-02 20:26 ` radeX
2005-01-02 20:45 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox