Skip to contentSkip to conversation

How to emulate slave serial ports ?

Bluez-users Rizzo Davide 2 participants 9 messages Nov 9, 2004 – Nov 10, 2004 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hi to all.
I'm experimenting with Bluez, I got some important results, but ...
I found a lot of mailings about how to use RFCOMM as a master, so how to use Phones as slaves to connect to internet or phone lines.
My approach is different: I have a target system based on Linux 2.6.9 (ARM architecture), on which I fitted an USB to Bluetooth dongle. I want my target system to make available one virtual serial port, and to connect to it from an external Windows-based PC. Now I have all low-level working, I use hciconfig, hcid and sdpd (currently my sdpd has some problems, it doesnt'returns so I have to call it as "hcid & ls"). Currently, from the Windows PC I successfully browsed my linux device and paired it, but I'm not able to view the list of exported services. I understand how to establish a serial connection to an external device, knowing its 6-bytes address, but I didn't found any literature on how to export a "virtual" serial port.
Should I use "sdptool add SP" ? Or maybe "rfcomm listen /dev/rfcomm0" ?
Which tool is needed to achieve this ?
Thanks
Davide

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

maintainer
#1 lore raw

Hi Davide,

Quoted 9 lines

I'm experimenting with Bluez, I got some important results, but ... I found a lot of mailings about how to use RFCOMM as a master, so how to use Phones as slaves to connect to internet or phone lines. My approach is different: I have a target system based on Linux 2.6.9 (ARM architecture), on which I fitted an USB to Bluetooth dongle. I want my target system to make available one virtual serial port, and to connect to it from an external Windows-based PC.
Now I have all low-level working, I use hciconfig, hcid and sdpd (currently my sdpd has some problems, it doesnt'returns so I have to

Quoted 8 lines

call it as "hcid & ls"). Currently, from the Windows PC I successfully browsed my linux device and paired it, but I'm not able to view the list of exported services.
I understand how to establish a serial connection to an external device, knowing its 6-bytes address, but I didn't found any literature on how to export a "virtual" serial port.
Should I use "sdptool add SP" ? Or maybe "rfcomm listen /dev/rfcomm0" ? Which tool is needed to achieve this ?

the question is what do you wanna do with the serial port on your machine? If you know that, then look for a profile that fits and use that program or write your own one.

Regards

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

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

the question is what do you wanna do with the serial port on your machine? If you know that, then look for a profile that fits and use that program or write your own one.

Regards

Quoted 9 lines

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click

Hi Marcel,
On the linux machine now I have a program that opens the serial device (and keeps it opened), periodically polls it for incoming requests, and eventually responds to the requests.
I wish to substitute this physical RS232 line with a bluetooth connection, without changing the Windows software on the PC (and the software on the target), except for the device names. Is it possible ?
Which bluez tools should I run on the init script ?
Thanks
Davide

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

maintainer
#3 lore raw

Hi Davide,

Quoted 3 lines

On the linux machine now I have a program that opens the serial device (and keeps it opened), periodically polls it for incoming requests, and eventually responds to the requests.

I don't understand this. Show me that program.

Quoted 3 lines

I wish to substitute this physical RS232 line with a bluetooth connection, without changing the Windows software on the PC (and the software on the target), except for the device names. Is it possible ?

It is possible, but I still don't know what you really wanna do. Replace some serial port is not a detailed description.

Quoted 1 line

Which bluez tools should I run on the init script ?

Besides hcid and sdpd, nothing more. But you must write a program that accepts connections on RFCOMM and that also registers a service record for your serial port.

Regards

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

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

Hi Davide,

Quoted 3 lines

On the linux machine now I have a program that opens the serial device (and keeps it opened), periodically polls it for incoming requests, and eventually responds to the requests.

I don't understand this. Show me that program.

Quoted 3 lines

I wish to substitute this physical RS232 line with a bluetooth connection, without changing the Windows software on the PC (and the software on the target), except for the device names. Is it possible ?

It is possible, but I still don't know what you really wanna do. Replace some serial port is not a detailed description.

Quoted 1 line

Which bluez tools should I run on the init script ?

Besides hcid and sdpd, nothing more. But you must write a program that accepts connections on RFCOMM and that also registers a service record for your serial port.

Regards

Quoted 9 lines

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click

Hi Marcel,

Let me start from the outside.

The final result I want to obtain is:

Quoted 1 line

From a PC running Windows (master):

1) I scan the bluetooth devices, and find one (or more) my linux devices
2) I pair the device with the correct PIN code
3) I browse the device's services and find one communication ports
4) I establish a Link with that comm port to a Windows virtual COMx port
5) I use the connected COMx port like any other "true" COMx port, sending inquiries and reading results in a proprietary format.
Until now I succeeded in points 1) and 2)

Quoted 1 line

From the target running linux 2.6.9 on an ARM9 (slave):

1) I run hciconfig
2) I start hcid
3) I start sdpd
4) My application opens /dev/rfcomm0 and keeps it opened
5) My application polls with read() on /dev/rfcomm0 for incoming messages

Question 1:
Is necessary to have on the target my application running with /dev/rfcomm0 opened for the Windows PC to look at the exported serial port ?

Question 2:
I setted up /usr/local/etc/bluetooth/pin and /usr/local/etc/bluetooth/hcid.conf for hcid, and it works OK. Does sdpd needs any configuration file ? Where is stored the sdpd configuration ? Where is stored the fact that I want to export one virtual serial port ?

Question 3:
If I run sdpd without any flags, it doesn't fork() because getppid()==1. Why ? Which is the correct mode of starting sdpd like a daemon ?

Thanks

Davide

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

maintainer
#5 lore raw

Hi Davide,

Quoted 13 lines

Let me start from the outside.

The final result I want to obtain is:

From a PC running Windows (master):
1) I scan the bluetooth devices, and find one (or more) my linux devices
2) I pair the device with the correct PIN code
3) I browse the device's services and find one communication ports
4) I establish a Link with that comm port to a Windows virtual COMx port
5) I use the connected COMx port like any other "true" COMx port, sending inquiries and reading results in a proprietary format.
Until now I succeeded in points 1) and 2)

Quoted 6 lines

From the target running linux 2.6.9 on an ARM9 (slave):
1) I run hciconfig
2) I start hcid
3) I start sdpd
4) My application opens /dev/rfcomm0 and keeps it opened
5) My application polls with read() on /dev/rfcomm0 for incoming messages

point 4 and 5 don't work this way on the server side, because you need to listen on incoming connections first before you can use the device node. What is the program on the ARM9 (slave) doing? I think you need to rewrite it and add native RFCOMM support.

Quoted 3 lines

Question 1:
Is necessary to have on the target my application running with /dev/rfcomm0 opened for the Windows PC to look at the exported serial port ?

No. You need to setup a service record for the serial port profile and listen on incoming connection on the RFCOMM channel.

Quoted 5 lines

Question 2:
I setted up /usr/local/etc/bluetooth/pin and /usr/local/etc/bluetooth/hcid.conf for hcid, and it works OK. Does sdpd needs any configuration file ? Where is stored the sdpd configuration ? Where is stored the fact that I want to export one virtual serial port ?

The SDP records are runtime records.

Quoted 3 lines

Question 3:
If I run sdpd without any flags, it doesn't fork() because getppid()==1. Why ? Which is the correct mode of starting sdpd like a daemon ?

Maybe this is problem with your ARM platform or your compiler.

Regards

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

#6 lore raw

Hi Marcel,

I solved (almost) all problems !

The correct solution is:

hciconfig hci0 up
hcid
sdpd &
sdptool add SP
rfcomm listen /dev/rfcomm0 &

... and now the program on the target can use /dev/rfcomm0 exactly like before it worked with /dev/TTYSACx !

The only problem is that rfcomm exits when windows closes the connection, so I need to run it again to be ready to listen for the next connection. But this is a minor problem, I'll investigate in the rfcomm code to get the parts I need, so I'll be able also to understand if the connection is on or not.

Thank you very much for your precious effort.

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

maintainer
#7 lore raw

Hi Davide,

Quoted 4 lines

I solved (almost) all problems !

The correct solution is:

Quoted 8 lines

hciconfig hci0 up
hcid
sdpd &
sdptool add SP
rfcomm listen /dev/rfcomm0 &

... and now the program on the target can use /dev/rfcomm0 exactly like before it worked with /dev/TTYSACx !

no it is not. This is only a workaround. Change your program to use a socket descriptor instead of a TTY descriptor and handle the incoming connection request and the SDP service registration by yourself.

Quoted 5 lines

The only problem is that rfcomm exits when windows closes the connection, so I need to run it again to be ready to listen for the next connection. But this is a minor problem, I'll investigate in the rfcomm code to get the parts I need, so I'll be able also to understand if the connection is on or not.

As I said, it is only a workaround.

Regards

Marcel

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users

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

Hi Davide,

Quoted 1 line

I solved (almost) all problems !

no it is not. This is only a workaround. Change your program to use a socket descriptor instead of a TTY descriptor and handle the incoming connection request and the SDP service registration by yourself.

Quoted 5 lines

The only problem is that rfcomm exits when windows closes the connection, so I need to run it again to be ready to listen for the next connection. But this is a minor problem, I'll investigate in the rfcomm code to get the parts I need, so I'll be able also to understand if the connection is on or not.

Quoted 5 lines

As I said, it is only a workaround.

Regards

Marcel

Hi Marcel,

You're absolutely right.
I'll use the socket interface instead of /dev/rfcomm0, it's much more flexible and powerful.

Thank you again,

Davide

All difficult problems have a simple solution.
That is wrong.
(A. Einstein)

-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
Bluez-users mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-users/listinfo/bluez-users