Skip to contentSkip to conversation

Fix for disconnection in new serial service

Bluez-devel Frederic Danis 3 participants 12 messages May 16, 2007 – May 23, 2007 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hello,

I find a little bug preventing disconnection in new serial service.

Fred

Signature · 7 lines
-----------------------------------------------
It is not by improving the oil lamp that one invents the electric bulb!
-----------------------------------------------
Danis Frederic                   Access Company
Software engineer
Mail : mailto:[email protected]
-----------------------------------------------

Index: serial/manager.c
===================================================================
RCS file: /cvsroot/bluez/utils/serial/manager.c,v
retrieving revision 1.36

manager.c +1 -0
diff -a -u -r1.36 manager.c
@@ -254,6 +254,7 @@
 
 	node->io_id = g_io_add_watch(io, G_IO_ERR | G_IO_NVAL | G_IO_HUP,
 					(GIOFunc) rfcomm_disconnect_cb, node);
+	g_io_channel_set_close_on_unref(io, TRUE);
 
 	connected_nodes = g_slist_append(connected_nodes, node);
 

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#1 lore raw

Hi Frederic,

Quoted 1 line

I find a little bug preventing disconnection in new serial service.

can you check against latest CVS. I am not sure if Claudio fixed this or not. Thanks.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#2 lore raw
Quoted 10 lines · Marcel Holtmann

Hi Frederic,

Quoted 1 line

I find a little bug preventing disconnection in new serial service.

can you check against latest CVS. I am not sure if Claudio fixed this or not. Thanks.

Regards

Marcel

Hi Frederic,

using g_io_channel_set_close_on_unref(io, TRUE) will trigger the following warning for G_IO_NVAL condition:

(process:8085): GLib-WARNING **: Invalid file descriptor.

BR,
Claudio.

Signature · 13 lines
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#3 lore raw
Quoted 13 lines · Claudio Takahasi
Quoted 9 lines · Marcel Holtmann

Hi Frederic,

Quoted 1 line

I find a little bug preventing disconnection in new serial service.

can you check against latest CVS. I am not sure if Claudio fixed this or not. Thanks.

Regards

Marcel

Hi Frederic,

Quoted 7 lines

using g_io_channel_set_close_on_unref(io, TRUE) will trigger the following warning for G_IO_NVAL condition:

(process:8085): GLib-WARNING **: Invalid file descriptor.

BR,
Claudio.

Hello Claudio,

I understand your comment.

But, I am trying to use the serial service and I do not understand one point :
after a ConnectService, the only way to disconnect it (disconnect rfcomm and acl), is by closing connection from remote side.

~ # dbus-send --system --type=method_call --print-reply --dest=:1.19 /org/bluez/serial org.bluez.serial.Manager.ConnectService string:00:01:02:03:05:06
string:spp
serial[1048]: /org/bluez/serial: org.bluez.serial.Manager.ConnectService()
serial[1048]: Connect in progress
serial[1048]: rfcomm_connect_cb: connected
serial[1048]: name_listener_add(:1.28)
method return sender=:1.19 -> dest=:1.28
string "/dev/rfcomm0"
serial[1048]: Connect requestor :1.28 exited. Releasing /dev/rfcomm0 node
~ # dbus-send --system --type=method_call --print-reply --dest=:1.19 /org/bluez/serial org.bluez.serial.Manager.DisconnectService string:/dev/rfcomm0 serial[1048]: /org/bluez/serial: org.bluez.serial.Manager.DisconnectService()
Error org.bluez.serial.Error.DoesNotExist: Invalid node

     // Here, the RFComm connection is still up until remote side disconnect

How can I disconnect rfcomm (and acl) connection from local side (currently, the serial service has opened a file descriptor on /dev/rfcommX, that is close only on remote disconnection, keeping up the /dev/rfcommX device) ?

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

Hope I am clear

Regards

Fred

Signature · 17 lines
-----------------------------------------------
It is not by improving the oil lamp that one invents the electric bulb!
-----------------------------------------------
Danis Frederic                   Access Company
Software engineer
Mail : mailto:[email protected]
-----------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
maintainer
#4 lore raw

Hi Frederic,

Quoted 2 lines

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

that is not the the use case for ConnectService and DisconnectService. It is as simple as that. What you want is more like the CreatePort methods that create persistent RFCOMM bindings.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#5 lore raw

Hello Marcel,

Quoted 6 lines
Quoted 2 lines

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

that is not the the use case for ConnectService and DisconnectService. It is as simple as that. What you want is more like the CreatePort methods that create persistent RFCOMM bindings.

Even if I change to : ConnectService, open rfcommX, use file descriptor on rfcommX, close rfcommX, DisconnectService (that is a more classical use), the rfcommX connection is not released (and acl connection, until remote close it), as serial service keep a file descriptor opened on the rfcommX device (no close on node->io).

What I want to do is a non persistent rfcomm connection, only use "one-shot", but closable on local side.

Regards

Fred

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#6 lore raw

Hi Frederic,

Quoted 10 lines
Quoted 6 lines
Quoted 2 lines

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

that is not the the use case for ConnectService and DisconnectService. It is as simple as that. What you want is more like the CreatePort methods that create persistent RFCOMM bindings.

Even if I change to : ConnectService, open rfcommX, use file descriptor on rfcommX, close rfcommX, DisconnectService (that is a more classical use), the rfcommX connection is not released (and acl connection, until remote close it), as serial service keep a file descriptor opened on the rfcommX device (no close on node->io).

that is the use case this is designed for. If this doesn't seem to work than it actually looks like a bug. Can you provide further information for Claudio so he can debug it.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#7 lore raw

Hello Marcel, Claudio,

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

that is not the the use case for ConnectService and DisconnectService. It is as simple as that. What you want is more like the CreatePort methods that create persistent RFCOMM bindings.

Quoted 7 lines
Quoted 3 lines

Even if I change to : ConnectService, open rfcommX, use file descriptor on rfcommX, close rfcommX, DisconnectService (that is a more classical use), the rfcommX connection is not released (and acl connection, until remote close it), as serial service keep a file descriptor opened on the rfcommX device (no close on node->io).

that is the use case this is designed for. If this doesn't seem to work than it actually looks like a bug. Can you provide further information for Claudio so he can debug it.

To simply check this, I do :

- on remote, I create a SPP server :

     frederic.danis@remote:~$ sdptool add --channel=5 sp
     Serial Port service registered
     frederic.danis@remote:~$ rfcomm listen 0 5
     Waiting for connection on channel 5

- on local, I connect to remote using serial service :

     ~ # dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez org.bluez.Manager.ActivateService string:serial
     method return sender=:1.0 -> dest=:1.22
        string ":1.19"
     ~ # dbus-send --system --type=method_call --print-reply --dest=:1.19 /org/bluez/serial org.bluez.serial.Manager.ConnectService string:00:01:02:03:04:05 

string:spp
serial[1040]: /org/bluez/serial: org.bluez.serial.Manager.ConnectService() serial[1040]: Connect in progress
serial[1040]: rfcomm_connect_cb: connected
serial[1040]: name_listener_add(:1.23)
method return sender=:1.19 -> dest=:1.23
string "/dev/rfcomm0"
serial[1040]: Connect requestor :1.23 exited. Releasing /dev/rfcomm0 node ~ # ls -l /dev/rfcomm0
crw-rw---- 1 root dialout 216, 0 May 22 21:37 /dev/rfcomm0
- on remote I get :
Connection from 00:01:02:03:04:05 to /dev/rfcomm0
Press CTRL-C for hangup

As there is no program using /dev/rfcomm0, and it has been released at end of "ConnectService call by dbus-send", it should no more exist and rfcomm (and acl) connection should be closed. It does not occur until pressing ctrl-c on remote. (I do not see any way to close the rfcomm connection from local)

- on local I have :

     ~ # hcitool con
     Connections:
             < ACL 00:01:02:03:04:05 handle 42 state 1 lm MASTER
     ~ # ls -l /dev/rfcomm0
     crw-rw----    1 root     dialout  216,   0 May 22 21:37 /dev/rfcomm0

- I press ctrl-c on remote :
Disconnected
- on local I have :
~ # hcitool con
Connections:
~ # ls -l /dev/rfcomm0
ls: /dev/rfcomm0: No such file or directory

To me it seems that this bug is due to the file descriptor on /dev/rfcomm0 opened during connection and set in a g_io_channel. This file descriptor is not closed before the g_io_channel is unreferenced (so reference to this file descriptor is lost, but still opened) preventing rfcomm stack to really release connection.

Hope this helps,

Regards

Fred

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#8 lore raw

Hi Frederic,

Quoted 21 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

that is not the the use case for ConnectService and DisconnectService. It is as simple as that. What you want is more like the CreatePort methods that create persistent RFCOMM bindings.

Quoted 7 lines
Quoted 3 lines

Even if I change to : ConnectService, open rfcommX, use file descriptor on rfcommX, close rfcommX, DisconnectService (that is a more classical use), the rfcommX connection is not released (and acl connection, until remote close it), as serial service keep a file descriptor opened on the rfcommX device (no close on node->io).

that is the use case this is designed for. If this doesn't seem to work than it actually looks like a bug. Can you provide further information for Claudio so he can debug it.

To simply check this, I do :

- on remote, I create a SPP server :

     frederic.danis@remote:~$ sdptool add --channel=5 sp
     Serial Port service registered
     frederic.danis@remote:~$ rfcomm listen 0 5
     Waiting for connection on channel 5
Quoted 4 lines

- on local, I connect to remote using serial service :

     ~ # dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez org.bluez.Manager.ActivateService string:serial
     method return sender=:1.0 -> dest=:1.22
        string ":1.19"

if the process goes away that called ConnectService() which is the care here since dbus-send will exit from the system bus, the connection should be automatically terminated. This is a meant to be cleanup of the serial service.

Quoted 6 lines
     ~ # dbus-send --system --type=method_call --print-reply --dest=:1.19 /org/bluez/serial org.bluez.serial.Manager.ConnectService string:00:01:02:03:04:05 

string:spp
serial[1040]: /org/bluez/serial: org.bluez.serial.Manager.ConnectService() serial[1040]: Connect in progress
serial[1040]: rfcomm_connect_cb: connected
serial[1040]: name_listener_add(:1.23)

Claudio, this is way to late to call name_listener_add(). You need to call it during the method call actually.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#9 lore raw

Hello,

Using the latest cvs revision, I saw that this problem has been fixed (using RFCOMM_HANGUP_NOW when rfcomm device is released).

Sorry

Fred

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#10 lore raw
In reply to Marcel Holtmann

Hello Marcel,

Quoted 7 lines
Quoted 2 lines

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

that is not the the use case for ConnectService and DisconnectService. It is as simple as that. What you want is more like the CreatePort methods that create persistent RFCOMM bindings.

Regarding the Serial service API, I am not sure to understand difference between ConnectService and CreatePort.
Is it possible to use port like this : CreatePort, open rfcomm, RemovePort, use file descriptor on rfcomm, than close it (that should disconnect bluetooth) ?

Regards

Fred

-----------------------------------------------
Danis Frederic Access Company
Software engineer
Mail : mailto:[email protected]
-----------------------------------------------

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#11 lore raw

Hi Frederic,

Quoted 10 lines
Quoted 7 lines
Quoted 2 lines

What I want to do in my program is : ConnectService, open rfcomm, DisconnectService, than use file descriptor on rfcomm. Close rfcomm after, that should disconnect the bluetooth connection.

that is not the the use case for ConnectService and DisconnectService. It is as simple as that. What you want is more like the CreatePort methods that create persistent RFCOMM bindings.

Regarding the Serial service API, I am not sure to understand difference between ConnectService and CreatePort.
Is it possible to use port like this : CreatePort, open rfcomm, RemovePort, use file descriptor on rfcomm, than close it (that should disconnect bluetooth) ?

the CreatePort is a permanent binding that will be even restored after reboot. The ConnectService is one-time use when you can't use the RFCOMM socket directly or need a TTY. The advantage of ConnectService is that the daemons cleans up after your process exits.

Regards

Marcel

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Bluez-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel