Skip to contentSkip to conversation

DBus interface - determining whether a device exists

Bluez-devel In review Matthew Garrett 6 participants 31 messages Aug 16, 2006 – Nov 10, 2006 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

I'd like to use the DBus interface to determine whether or not a Bluetooth device is currently in range of the computer in order to work out whether or not it's possible to connect to it. Checking through the API suggests that there's currently nothing suitable for doing that. What would be the best way to implement it?

Thanks,

Signature · 11 lines
Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#1 lore raw

PATCH 1/1 - add ConnectRemoteDevice method to dbus

I'm not sure if this is the best approach, but still:

The included patch adds a ConnectRemoteDevice method to the Bluez DBus interface. It's the effective equivalent of hcitool cc. The idea is to have somthing that can be used by a session daemon when it wants to reconnect to devices on login.

Index: dbus-adapter.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-adapter.c,v retrieving revision 1.70

dbus-adapter.c +51 -0
diff -u -r1.70 dbus-adapter.c
@@ -1648,6 +1648,56 @@
 
 }
 
+static DBusHandlerResult handle_dev_connect_remote_device_req(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	DBusMessage *reply;
+	DBusError err;
+
+	struct hci_dbus_data *dbus_data = data;
+
+	const char *peer_addr;
+	bdaddr_t peer_bdaddr;
+	int dd, ptype;
+	uint16_t handle = 0;
+
+	dbus_error_init(&err);
+	dbus_message_get_args(msg, &err,
+				DBUS_TYPE_STRING, &peer_addr,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_error_is_set(&err)) {
+		error("Can't extract message arguments:%s", err.message);
+		dbus_error_free(&err);
+		return error_invalid_arguments(conn, msg);
+	}
+
+	if (check_address(peer_addr) < 0)
+		return error_invalid_arguments(conn, msg);
+
+	str2ba(peer_addr, &peer_bdaddr);
+
+	dd = hci_open_dev(dbus_data->dev_id);
+	if (dd < 0)
+		return error_no_such_adapter(conn, msg);
+
+	ptype = HCI_DM1 | HCI_DM3 | HCI_DM5 | HCI_DH1 | HCI_DH3 | HCI_DH5;
+
+	/* Send the HCI connect command */
+	if (hci_create_connection (dd, &peer_bdaddr, htobs(ptype), 0, 0x01, &handle, 25000) < 0) {		
+		error("Connect failed");
+		hci_close_dev(dd);
+		return error_failed(conn, msg, errno);
+	}
+
+	hci_close_dev(dd);
+
+	reply = dbus_message_new_method_return(msg);
+	if (!reply)
+		return DBUS_HANDLER_RESULT_NEED_MEMORY;
+
+	return send_reply_and_unref(conn, reply);
+}
+
 static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBusMessage *msg, void *data)
 {
 	char filename[PATH_MAX + 1];
@@ -2365,6 +2415,7 @@
 
 	{ "DisconnectRemoteDevice",			handle_dev_disconnect_remote_device_req	},
 
+	{ "ConnectRemoteDevice",                        handle_dev_connect_remote_device_req },
 	{ "CreateBonding",				handle_dev_create_bonding_req		},
 	{ "CancelBonding",				handle_dev_cancel_bonding_req		},
 	{ "RemoveBonding",				handle_dev_remove_bonding_req		},

Index: dbus-api.txt
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-api.txt,v retrieving revision 1.40

dbus-api.txt +9 -0
diff -u -r1.40 dbus-api.txt
@@ -553,6 +553,15 @@
 
 			Question: Can we find a better name?
 
+		void ConnectRemoteDevice(string address)
+
+		        This method creates a baseband connection to a specific
+			remote device.
+
+			Possible errors: org.bluez.Error.InvalidArguments
+					 org.bluez.Error.NoSuchAdapter
+					 org.bluez.Error.Failed
+
 		void DisconnectRemoteDevice(string address)
 
 			This method disconnects a specific remote device by

Index: dbus-test
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-test,v
retrieving revision 1.22

dbus-test +7 -1
diff -u -r1.22 dbus-test
@@ -45,6 +45,7 @@
              "ClearRemoteAlias",
              "LastSeen",
              "LastUsed",
+	     "ConnectRemoteDevice",
              "DisconnectRemoteDevice",
              "CreateBonding",
              "CancelBondingProcess",
@@ -343,9 +344,14 @@
                    print self.device.LastUsed(self.cmd_args[0])
                else:
                    print 'Usage: %s -i <dev> LastUsed address' % self.name
+           elif self.cmd == 'ConnectRemoteDevice':
+               if len(self.cmd_args) == 1:
+                   print self.device.ConnectRemoteDevice(self.cmd_args[0])
+               else:
+                   print 'Usage: %s -i <dev> ConnectRemoteDevice address' % self.name
            elif self.cmd == 'DisconnectRemoteDevice':
                if len(self.cmd_args) == 1:
-                   print self.device.LastUsed(self.cmd_args[0])
+                   print self.device.DisconnectRemoteDevice(self.cmd_args[0])
                else:
                    print 'Usage: %s -i <dev> DisconnectRemoteDevice address' % self.name
            elif self.cmd == 'CreateBonding':
Signature · 11 lines
Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
maintainer
#2 lore raw

Re: [Bluez-devel] [PATCH] - add ConnectRemoteDevice method to dbus

Hi Matthew,

Quoted 6 lines

I'm not sure if this is the best approach, but still:

The included patch adds a ConnectRemoteDevice method to the Bluez DBus interface. It's the effective equivalent of hcitool cc. The idea is to have somthing that can be used by a session daemon when it wants to reconnect to devices on login.

we left this out on purpose. The disconnect was a compromise for systems where we might end up with stuck connections. The "hcitool cc ..." is for debugging purpose only and so this patch is not acceptable.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#3 lore raw
In reply to Matthew Garrett

Hi Matthew,

Quoted 5 lines

I'd like to use the DBus interface to determine whether or not a Bluetooth device is currently in range of the computer in order to work out whether or not it's possible to connect to it. Checking through the API suggests that there's currently nothing suitable for doing that. What would be the best way to implement it?

this is a general Bluetooth problem. If you don't have a connection between two devices then there is no radio traffic. This is one of big difference between Bluetooth and WiFi.

The only possible solution is to have the other device always be in discoverable mode and use periodic inquiry with the RSSI values or defines something for extended inquiry to transmit additional information.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#4 lore raw
Quoted 3 lines · Marcel Holtmann

this is a general Bluetooth problem. If you don't have a connection between two devices then there is no radio traffic. This is one of big difference between Bluetooth and WiFi.

Right. But the DBus interface doesn't seem to provide any mechanism for initiating a connection to the device. GetName and the like appear to provide cached results even if the device is now out of range, which isn't what I want.

There's an obvious use case for having a function that is, effectively, "Can I currently connect to the device with this bluetooth address". The patch I sent provides that, but if that's unacceptable then what should the interface look like?

Thanks,

Signature · 11 lines
Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#5 lore raw
Quoted 4 lines

Right. But the DBus interface doesn't seem to provide any mechanism for initiating a connection to the device. GetName and the like appear to provide cached results even if the device is now out of range, which isn't what I want.

Hi Matthew,

What about RFCOMM ConnectByChannel? Wouldn't it do the job?

Best Regards,
Cezar

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#6 lore raw
Quoted 8 lines · On Wed, Aug 16, 2006 at 10:21:19PM -0300, Cezar S=E1 Espinola wrote:
Quoted 4 lines

Right. But the DBus interface doesn't seem to provide any mechanism for initiating a connection to the device. GetName and the like appear to provide cached results even if the device is now out of range, which isn't what I want.

Hi Matthew,
=

What about RFCOMM ConnectByChannel? Wouldn't it do the job?

Well, it's not necessarily an RFCOMM connection. I'd prefer to just be =

able to store the fact that a device exists rather than what sort of =

connection and on what channels, especially since Marcel mentioned that =

the channel may well have changed if the Bluetooth device has been =

rebooted.

-- =

Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easi= er
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D1=
21642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#7 lore raw

Hi Matthew,

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

Right. But the DBus interface doesn't seem to provide any mechanism for initiating a connection to the device. GetName and the like appear to provide cached results even if the device is now out of range, which isn't what I want.

Hi Matthew,

Quoted 7 lines
Quoted 1 line

What about RFCOMM ConnectByChannel? Wouldn't it do the job?

Well, it's not necessarily an RFCOMM connection. I'd prefer to just be able to store the fact that a device exists rather than what sort of connection and on what channels, especially since Marcel mentioned that the channel may well have changed if the Bluetooth device has been rebooted.

what you actually want is something like l2ping so see if a device is alive or not. At the moment I am not considering such an extension, because we shouldn't page devices to see if they are active or not.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#8 lore raw
Quoted 3 lines · Marcel Holtmann

what you actually want is something like l2ping so see if a device is alive or not. At the moment I am not considering such an extension, because we shouldn't page devices to see if they are active or not.

Why not? It seems more sensible to do that than to blindly attempt to set up a hid connection without knowing whether the device actually exists or not.

Signature · 11 lines
Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
maintainer
#9 lore raw

Hi Matthew,

Quoted 7 lines
Quoted 3 lines

what you actually want is something like l2ping so see if a device is alive or not. At the moment I am not considering such an extension, because we shouldn't page devices to see if they are active or not.

Why not? It seems more sensible to do that than to blindly attempt to set up a hid connection without knowing whether the device actually exists or not.

the HID case doesn't fly. All HID devices only need an initial connect and the they reconnect to the host.

But again, the costs of getting this knowledge are to expensive. In most cases you have to serialize page attempts and make sure you don't interrupt inquiries or disturb other connections. For example the high quality audio part might not really like that you try to page other devices a lot of times. It will work, but if the audio stream breaks to often you have a bad user experience.

Once we offer such a method it gets used and it will get abused for weird tricks application wanna play. So you need a better argument to convince me to include something like this.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#10 lore raw
In reply to Matthew Garrett

Hi Matthew,

Quoted 8 lines
Quoted 3 lines

this is a general Bluetooth problem. If you don't have a connection between two devices then there is no radio traffic. This is one of big difference between Bluetooth and WiFi.

Right. But the DBus interface doesn't seem to provide any mechanism for initiating a connection to the device. GetName and the like appear to provide cached results even if the device is now out of range, which isn't what I want.

the GetName results are cached. That is correct, but they are also updated every time we get new information about it. For example if hcid sees a ACL connection, it requests the remote name again. This is a cheap operation at no costs and keeps the name up-to-date. Also if you see an extended inquiry or a name resolve itself it will update the cache and send out a RemoteNameChanged signal. The same applies to other information like class of device etc.

Quoted 4 lines

There's an obvious use case for having a function that is, effectively, "Can I currently connect to the device with this bluetooth address". The patch I sent provides that, but if that's unacceptable then what should the interface look like?

You must understand that you can't do this with Bluetooth. If you wanna know if you can connect to a device then the baseband has to page the other device. This is an expensive operation and it will stall all ongoing paging or inquiry operations. So in general you don't wanna do this unless you are in a special environment and know what all users are doing. For the normal desktop case we simply don't know this. So it is not a good idea. Not speaking of the higher power consumption of such operations.

You also have to think about moving targets. For example at an airport where a lot of devices will pass you. Trying to page them and waiting for a page timeout is an even more expensive operation.

So what you actually want is to set a device in periodic inquiry mode and then make it constantly report devices in range. However this should be an optional operation, because the power consumption argument is here valid, too. For most Bluetooth 1.2 and 2.0 dongles you then get inquiry results that also include the RSSI value. From these you can make an assumption if a device is near enough. There is threshold of RSSI that indicates a device will not be in range for a connection even if an inquiry sees it.

So from my part I am happy to see support for periodic inquiry and this is what you actually should go with. I can't think of an API at the moment, but I must admit that I didn't put any big effort into it right now. Feel free to propose something.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#11 lore raw
Quoted 8 lines · Marcel Holtmann

You must understand that you can't do this with Bluetooth. If you wanna know if you can connect to a device then the baseband has to page the other device. This is an expensive operation and it will stall all ongoing paging or inquiry operations. So in general you don't wanna do this unless you are in a special environment and know what all users are doing. For the normal desktop case we simply don't know this. So it is not a good idea. Not speaking of the higher power consumption of such operations.

In this specific case, it's done at login time. That's a point where we /do/ know whether or not there are any existing connections (I'm ignoring the multiple user case, because the DBus API doesn't really deal with that at the moment anyway).

Quoted 3 lines

You also have to think about moving targets. For example at an airport where a lot of devices will pass you. Trying to page them and waiting for a page timeout is an even more expensive operation.

Sorry, possibly I should be clearer about the behaviour I'm talking about here.

Imagine the case where a user has bound a set of headphones. They've chosen to make them their default audio device. At login time, we wish to attempt to reconnect to the headphones. It would be nice to be able to do so by checking whether the device exists or not first.

At the moment, the method for doing that would appear to be to store the following information:

1) The bluetooth address
2) The fact that it's a set of headphones
3) Whether it uses rfcomm or l2cap

and then at login time do service discovery (because we don't know whether the channel may have changed) and attempt to set up a connection. The alternative would be to store:

1) The bluetooth address

and then at login time attempt a baseband connection to the device. If it exists, then we can do service discovery and worry about the other pieces of information. If we can't set up a baseband connection, we don't need to bother.

The second approach strikes me as simpler than the first approach, but it requires the ability to set up that baseband connection which you're clearly unhappy with. Is the first approach how I should be doing this?

Quoted 2 lines

So what you actually want is to set a device in periodic inquiry mode and then make it constantly report devices in range.

Well, no - I don't actually care what happens to the device after that. If the user moves the device out of range, or if the user logs in without the device being switched on, then it's acceptable to require the user to manually reenable the device. But it's entirely reasonable for the user to say "If the device is switched on when I log in, please automatically connect to it". That's the problem that I'm trying to solve. Unlike periodic inquiry, this wouldn't result in any significant increase in power consumption. It's a one-shot-per-session thing.

Signature · 11 lines
Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
maintainer
#12 lore raw

Hi Matthew,

Quoted 9 lines
Quoted 8 lines

You must understand that you can't do this with Bluetooth. If you wanna know if you can connect to a device then the baseband has to page the other device. This is an expensive operation and it will stall all ongoing paging or inquiry operations. So in general you don't wanna do this unless you are in a special environment and know what all users are doing. For the normal desktop case we simply don't know this. So it is not a good idea. Not speaking of the higher power consumption of such operations.

Quoted 4 lines

In this specific case, it's done at login time. That's a point where we /do/ know whether or not there are any existing connections (I'm ignoring the multiple user case, because the DBus API doesn't really deal with that at the moment anyway).

actually the API can handle it, but we don't honor different users from the backend part at the moment. We talked about it, but it was put off as something to address later when all Bluetooth parts are working smoothly together.

Quoted 25 lines
Quoted 3 lines

You also have to think about moving targets. For example at an airport where a lot of devices will pass you. Trying to page them and waiting for a page timeout is an even more expensive operation.

Sorry, possibly I should be clearer about the behaviour I'm talking about here.

Imagine the case where a user has bound a set of headphones. They've chosen to make them their default audio device. At login time, we wish to attempt to reconnect to the headphones. It would be nice to be able to do so by checking whether the device exists or not first.

At the moment, the method for doing that would appear to be to store the following information:

1) The bluetooth address
2) The fact that it's a set of headphones
3) Whether it uses rfcomm or l2cap

and then at login time do service discovery (because we don't know whether the channel may have changed) and attempt to set up a connection. The alternative would be to store:

1) The bluetooth address

Quoted 8 lines

and then at login time attempt a baseband connection to the device. If it exists, then we can do service discovery and worry about the other pieces of information. If we can't set up a baseband connection, we don't need to bother.

The second approach strikes me as simpler than the first approach, but it requires the ability to set up that baseband connection which you're clearly unhappy with. Is the first approach how I should be doing this?

I personally don't like to page a bunch of devices at login time. This can end up in a bad user experience. For example if they use a Bluetooth mouse and keyboard. This might block with some older chips or they experience some rough time.

For this specific case we should only page the device if the audio device has been opened and there is actually an audio stream. I is not important if the device is in range or not. If it is not in range then you won't hear anything or we need to choose a fallback. I think that these stuff doesn't belong in the core Bluetooth daemon. You want to have an btaudiod that handles all these stuff in the back for you. The user only configures once the possible connections to headphones and headsets and then the daemon will take care of everything.

This will be complete new D-Bus API for Bluetooth. I talked about my ideas for it at the OLS, but no actual code has been written so far.

Quoted 11 lines
Quoted 2 lines

So what you actually want is to set a device in periodic inquiry mode and then make it constantly report devices in range.

Well, no - I don't actually care what happens to the device after that. If the user moves the device out of range, or if the user logs in without the device being switched on, then it's acceptable to require the user to manually reenable the device. But it's entirely reasonable for the user to say "If the device is switched on when I log in, please automatically connect to it". That's the problem that I'm trying to solve. Unlike periodic inquiry, this wouldn't result in any significant increase in power consumption. It's a one-shot-per-session thing.

Except that you wanna keep up the connection. Even with sniff mode, this consumes more power than a disconnected device. This is one of the reasons why mice and keyboards are shutting down the connections after a specific idle time. Same applies to other devices. If you don't actually need the connection, then don't have it. In the case of headphones you don't wanna have a connection if you don't have any audio.

I know that these models doesn't really fit into the Linux way at the moment, but we will see them more and more. Bluetooth is only the first technology used a "disconnected model". Wireless USB and UWB will have to deal with it, too. And power consumption is a big factor. I just applied a patch to use ppoll() instead of poll() for a couple of our deaemons.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#13 lore raw
Quoted 8 lines · Marcel Holtmann

For this specific case we should only page the device if the audio device has been opened and there is actually an audio stream. I is not important if the device is in range or not. If it is not in range then you won't hear anything or we need to choose a fallback. I think that these stuff doesn't belong in the core Bluetooth daemon. You want to have an btaudiod that handles all these stuff in the back for you. The user only configures once the possible connections to headphones and headsets and then the daemon will take care of everything.

The problem isn't just in actually setting up the connections, it's in providing the information about available devices to other applications. Nowadays, the right layer for device enumeration is HAL. If I tell my system about a mobile phone, then the correct behaviour is for it to appear as a HAL object. In order for Network Manager to offer me the choice of connecting via my phone, the phone needs to be in HAL. So, somehow, at login time the phone needs to be added.

There's two ways of dealing with this. The one that I prefer is that we make some effort to determine that the phone actually exists, and then add it to HAL in the same way that we would if we'd just done device discovery and the phone was discoverable. This needs us to have some mechanism for determining whether the phone actually exists. The second is that we store the HAL data and repopulate HAL at login time. This is more hacky, since we're adding information without even having made a token effort to determine whether the device exists or not.

I guess that since we don't have any guarantees that the device exists at any given point in time anyway, this makes less difference and we should just populate HAL regardless. I suppose I'm open to that.

Thanks,

Signature · 11 lines
Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#14 lore raw

Hi Matthew,

Quoted 17 lines · Matthew Garrett

The problem isn't just in actually setting up the connections, it's in providing the information about available devices to other applications. Nowadays, the right layer for device enumeration is HAL. If I tell my system about a mobile phone, then the correct behaviour is for it to appear as a HAL object. In order for Network Manager to offer me the choice of connecting via my phone, the phone needs to be in HAL. So, somehow, at login time the phone needs to be added.

There's two ways of dealing with this. The one that I prefer is that we make some effort to determine that the phone actually exists, and then add it to HAL in the same way that we would if we'd just done device discovery and the phone was discoverable. This needs us to have some mechanism for determining whether the phone actually exists. The second is that we store the HAL data and repopulate HAL at login time. This is more hacky, since we're adding information without even having made a token effort to determine whether the device exists or not.

Quoted 3 lines

I guess that since we don't have any guarantees that the device exists at any given point in time anyway, this makes less difference and we should just populate HAL regardless. I suppose I'm open to that.

Maybe you could simply use the list of bonded devices to populate HAL? You could use the ListBondings method and BondingCreated/BondingRemoved signals for that.

Johan

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#15 lore raw
Quoted 3 lines · Johan Hedberg

Maybe you could simply use the list of bonded devices to populate HAL? You could use the ListBondings method and BondingCreated/BondingRemoved signals for that.

Is that persistant over restarts of the daemon? I've remembered why repopulating HAL is difficult - only root can add devices (for fairly obvious reasons). I'll have to see what I can do about that.

Signature · 11 lines
Matthew Garrett | [email protected]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
#16 lore raw
Quoted 7 lines · Matthew Garrett
Quoted 3 lines · Johan Hedberg

Maybe you could simply use the list of bonded devices to populate HAL? You could use the ListBondings method and BondingCreated/BondingRemoved signals for that.

Is that persistant over restarts of the daemon?

Yes.

Johan

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#17 lore raw
In reply to Johan Hedberg
Quoted 3 lines · Johan Hedberg

Hi Matthew,

On Thu, Aug 17, 2006, Matthew Garrett wrote:

<snip>

Quoted 7 lines
Quoted 3 lines

I guess that since we don't have any guarantees that the device exists at any given point in time anyway, this makes less difference and we should just populate HAL regardless. I suppose I'm open to that.

Maybe you could simply use the list of bonded devices to populate HAL? You could use the ListBondings method and BondingCreated/BondingRemoved signals for that.

This is how MacOS X populates its selection lists. They have the list of paired devices, as well as "Favourite" devices.

Signature · 12 lines
Bastien Nocera <[email protected]> 


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
maintainer
#18 lore raw

Hi Bastien,

Quoted 10 lines
Quoted 7 lines
Quoted 3 lines

I guess that since we don't have any guarantees that the device exists at any given point in time anyway, this makes less difference and we should just populate HAL regardless. I suppose I'm open to that.

Maybe you could simply use the list of bonded devices to populate HAL? You could use the ListBondings method and BondingCreated/BondingRemoved signals for that.

This is how MacOS X populates its selection lists. They have the list of paired devices, as well as "Favourite" devices.

we also store the last seen (inquiry) and last used (connected) time of any device. This can be also used to populate the HAL list. For example it should include all bonded devices and additionally devices that have been connected in the last 7 days or so.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#19 lore raw

Hello,

Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

I guess that since we don't have any guarantees that the device exists at any given point in time anyway, this makes less difference and we should just populate HAL regardless. I suppose I'm open to that.

Maybe you could simply use the list of bonded devices to populate HAL?
You could use the ListBondings method and BondingCreated/BondingRemoved signals for that.

This is how MacOS X populates its selection lists. They have the list of paired devices, as well as "Favourite" devices.

Quoted 6 lines

we also store the last seen (inquiry) and last used (connected) time of any device. This can be also used to populate the HAL list. For example it should include all bonded devices and additionally devices that have been connected in the last 7 days or so.

In this case, I think it can be usefull to have same APIs in DBus for "used devices" than for "paired devices". You can find in attachement a patch that add ListUsed and RemovedUsed methods to hcid. Hope this helps.

Regards

Fred

-----------------------------------------------
It is not by improving the oil lamp that one invents the electric bulb!
-----------------------------------------------
Danis Frederic PalmSource Europe
Software engineer
Mail : mailto:[email protected]
-----------------------------------------------

dbus-adapter.c +77 -0
diff -Naur hcid/dbus-adapter.c hcid.new/dbus-adapter.c
@@ -1592,6 +1592,81 @@
 	return send_reply_and_unref(conn, reply);
 }
 
+static DBusHandlerResult handle_dev_remove_used_req(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessage *reply;
+	DBusMessage *signal;
+	DBusError err;
+	char filename[PATH_MAX + 1];
+	char *addr_ptr;
+
+	dbus_error_init(&err);
+	dbus_message_get_args(msg, &err,
+				DBUS_TYPE_STRING, &addr_ptr,
+				DBUS_TYPE_INVALID);
+
+	if (dbus_error_is_set(&err)) {
+		error("Can't extract message arguments:%s", err.message);
+		dbus_error_free(&err);
+		return error_invalid_arguments(conn, msg);
+	}
+
+	if (check_address(addr_ptr) < 0)
+		return error_invalid_arguments(conn, msg);
+
+	snprintf(filename, PATH_MAX, "%s/%s/lastused", STORAGEDIR, dbus_data->address);
+
+	/* Delete the used info from storage */
+	if (textfile_del(filename, addr_ptr))
+		return error_bonding_does_not_exist(conn, msg);
+
+	/* FIXME: which condition must be verified before send the signal */
+	signal = dev_signal_factory(dbus_data->dev_id, "UsedRemoved",
+					DBUS_TYPE_STRING, &addr_ptr,
+					DBUS_TYPE_INVALID);
+	if (signal) {
+		dbus_connection_send(conn, signal, NULL);
+		dbus_connection_flush(conn);
+		dbus_message_unref(signal);
+	}
+
+	reply = dbus_message_new_method_return(msg);
+
+	return send_reply_and_unref(conn, reply);
+}
+
+static DBusHandlerResult handle_dev_list_used_req(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	void do_append(char *key, char *value, void *data)
+	{
+		DBusMessageIter *iter = data;
+
+		dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &key);
+	}
+
+	struct hci_dbus_data *dbus_data = data;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+
+	snprintf(filename, PATH_MAX, "%s/%s/lastused", STORAGEDIR, dbus_data->address);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	textfile_foreach(filename, do_append, &array_iter);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_reply_and_unref(conn, reply);
+}
+
 static DBusHandlerResult handle_dev_disconnect_remote_device_req(DBusConnection *conn, DBusMessage *msg, void *data)
 {
 	DBusMessage *reply;
@@ -2362,6 +2437,8 @@
 
 	{ "LastSeen",					handle_dev_last_seen_req		},
 	{ "LastUsed",					handle_dev_last_used_req		},
+	{ "RemoveUsed",					handle_dev_remove_used_req		},
+	{ "ListUsed",					handle_dev_list_used_req		},
 
 	{ "DisconnectRemoteDevice",			handle_dev_disconnect_remote_device_req	},
 
dbus-api.txt +21 -0
diff -Naur hcid/dbus-api.txt hcid.new/dbus-api.txt
@@ -553,6 +553,23 @@
 
 			Question: Can we find a better name?
 
+		array{string} ListUsed()
+
+			List device addresses of already used adapter.
+
+			Possible errors: none
+
+		void RemoveUsed(string address)
+
+			This method removes the used info of a remote device.
+
+			After deleting the link key this method will send a
+			UsedRemoved signal.
+
+			Possible errors: org.bluez.Error.Failed
+					 org.bluez.Error.InvalidArguments
+					 org.bluez.Error.DoesNotExist
+
 		void DisconnectRemoteDevice(string address)
 
 			This method disconnects a specific remote device by
@@ -791,6 +808,10 @@
 
 			Signals that a bonding was removed.
 
+		void UsedRemoved(string address)
+
+			Signals that a used info was removed.
+
 
 Security hierarchy
 ==================
dbus-test +13 -1
diff -Naur hcid/dbus-test hcid.new/dbus-test
@@ -45,6 +45,8 @@
              "ClearRemoteAlias",
              "LastSeen",
              "LastUsed",
+             "RemoveUsed",
+             "ListUsed",
              "DisconnectRemoteDevice",
              "CreateBonding",
              "CancelBondingProcess",
@@ -69,7 +71,8 @@
                 "RemoteDeviceConnected",
                 "RemoteDeviceDisconnected",
                 "BondingCreated",
-                "BondingRemoved" ]
+                "BondingRemoved",
+                "UsedRemoved" ]
 
 dev_signals_filter = [ "/org/bluez/hci0", "/org/bluez/hci1",
                        "/org/bluez/hci2", "/org/bluez/hci3",
@@ -343,6 +346,15 @@
                    print self.device.LastUsed(self.cmd_args[0])
                else:
                    print 'Usage: %s -i <dev> LastUsed address' % self.name
+           elif self.cmd == 'RemoveUsed':
+               if len(self.cmd_args) == 1:
+                   print self.device.RemoveUsed(self.cmd_args[0])
+               else:
+                   print 'Usage: %s -i <dev> RemoveUsed address' % self.name
+           elif self.cmd == 'ListUsed':
+               used = self.device.ListUsed()
+               for address in used: 
+                   print address,
            elif self.cmd == 'DisconnectRemoteDevice':
                if len(self.cmd_args) == 1:
                    print self.device.LastUsed(self.cmd_args[0])

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

maintainer
#20 lore raw

Hi Frederic,

Quoted 9 lines
Quoted 5 lines

we also store the last seen (inquiry) and last used (connected) time of any device. This can be also used to populate the HAL list. For example it should include all bonded devices and additionally devices that have been connected in the last 7 days or so.

In this case, I think it can be usefull to have same APIs in DBus for "used devices" than for "paired devices". You can find in attachement a patch that add ListUsed and RemovedUsed methods to hcid. Hope this helps.

I am not happy about the RemoveUsed method. I am not sure if one application should be able to say when a used device will be removed from the list. I think this should be application specific.

I also might prefer to name the method ListRemoteDevices to list all paired, seen and used remote devices. We can then have special versions of this method for specific tasks. For example ListRecentRemoteDevices with a date parameter that will only list paired and used devices in that time frame.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#21 lore raw

Hello Marcel,

Quoted 20 lines
Quoted 9 lines
Quoted 6 lines

we also store the last seen (inquiry) and last used (connected) time of any device. This can be also used to populate the HAL list. For example it should include all bonded devices and additionally devices that have been connected in the last 7 days or so.

In this case, I think it can be usefull to have same APIs in DBus for "used devices" than for "paired devices". You can find in attachement a patch that add ListUsed and RemovedUsed methods to hcid. Hope this helps.

I am not happy about the RemoveUsed method. I am not sure if one application should be able to say when a used device will be removed from the list. I think this should be application specific.

I also might prefer to name the method ListRemoteDevices to list all paired, seen and used remote devices. We can then have special versions of this method for specific tasks. For example ListRecentRemoteDevices with a date parameter that will only list paired and used devices in that time frame.

Quoted 5 lines

Regards

Marcel

You can find attached a new patch implementing ListRemoteDevices and ListRecentRemoteDevices.

Regards

Fred

dbus-adapter.c +122 -0
diff -Naur hcid.orig/dbus-adapter.c hcid.new/dbus-adapter.c
@@ -2615,6 +2615,125 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+struct remote_device_list_t {
+	struct slist *list;
+	time_t time;
+};
+
+static void list_remote_devices_do_append(char *key, char *value, void *data)
+{
+	struct remote_device_list_t *param = data;
+	char *address;
+	struct tm date;
+
+	if (slist_find(param->list, key, (cmp_func_t) bacmp))
+		return;
+
+	// TODO: check date
+	if (param->time){
+		strptime (value, "%Y-%m-%d %H:%M:%S %Z", &date);
+		if (difftime(mktime(&date), param->time) < 0)
+			return;
+	}
+
+	address = strdup(key);
+	if (!address)
+		return;
+
+	slist_append(param->list, address);
+}
+
+static void remote_devices_do_append(void *data, void *user_data)
+{
+	DBusMessageIter *iter = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data);
+}
+
+static DBusHandlerResult adapter_list_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
+		return error_invalid_arguments(conn, msg);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Seen devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
+static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	const char *string;
+	struct tm date;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_get_args(msg, NULL,
+				DBUS_TYPE_STRING, &string,
+				DBUS_TYPE_INVALID))
+		return error_invalid_arguments(conn, msg);
+
+	if (strptime (string, "%Y-%m-%d %H:%M:%S", &date) == NULL)
+		return error_invalid_arguments(conn, msg);
+	param.time = mktime(&date);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
 const char *major_class_str(uint32_t class)
 {
 	uint8_t index = (class >> 8) & 0x1F;
@@ -2746,6 +2865,9 @@
 	{ "DiscoverDevicesWithoutNameResolving",	adapter_discover_devices	},
 	{ "CancelDiscovery",			adapter_cancel_discovery	},
 
+	{ "ListRemoteDevices",				adapter_list_remote_devices		},
+	{ "ListRecentRemoteDevices",		adapter_list_recent_remote_devices		},
+
 	{ NULL, NULL }
 };
 
dbus-api.txt +14 -0
diff -Naur hcid.orig/dbus-api.txt hcid.new/dbus-api.txt
@@ -789,6 +789,20 @@
 					 org.bluez.Error.InProgress
 					 org.bluez.Error.Failed
 
+		array{string} ListRemoteDevices()
+
+			List device addresses of all known adapters (seen, used or bonded).
+
+			Possible errors: none
+
+		array{string} ListRecentRemoteDevices(string date)
+
+			List device addresses of all used or bonded adapters since date.
+
+			date format is "YYYY-MM-DD HH:MM:SS GMT"
+
+			Possible errors: none
+
 
 Signals		void ModeChanged(string mode)
 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

#22 lore raw

Hi Fred,

Quoted 2 lines · Frederic Danis

You can find attached a new patch implementing ListRemoteDevices and ListRecentRemoteDevices.

Couple of notes about your patch:

dbus-adapter.c line 2630

Quoted 8 lines
dbus-adapter.c +8 -0
+static void list_remote_devices_do_append(char *key, char *value, void *data)
+{
+	struct remote_device_list_t *param = data;
+	char *address;
+	struct tm date;
+
+	if (slist_find(param->list, key, (cmp_func_t) bacmp))
+		return;

bacmp takes bdaddr_t pointers not char pointers. You probably want to use strcasecmp.

dbus-adapter.c line 2643

Quoted 1 line
dbus-adapter.c +1 -0
+	slist_append(param->list, address);

This should be:
param->list = slist_append(param->list, address);

Quoted 12 lines
dbus-adapter.c +12 -0
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Seen devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+

dbus-adapter.c line 2686

Quoted 10 lines
dbus-adapter.c +10 -0
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_free(param.list);

slist_free only frees the nodes in the list but not the data they point to (the strings which have been allocated with strdup). So you probably want to call slist_foreach(param.list, (slist_func_t) free, NULL) before slist_free or free the data in remote_devices_do_append.

Quoted 8 lines
dbus-adapter.c +8 -0
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+

dbus-adapter.c line 2686

Quoted 10 lines
dbus-adapter.c +10 -0
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_free(param.list);

And same applies here.

Johan

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#23 lore raw

Hello Johan,

Here is a new version of the patch updated.
Thanks for your commented.

Fred

dbus-adapter.c +125 -0
diff -Naur hcid.orig/dbus-adapter.c hcid.new/dbus-adapter.c
@@ -25,10 +25,12 @@
 #include <config.h>
 #endif
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <time.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -2615,6 +2617,126 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+struct remote_device_list_t {
+	struct slist *list;
+	time_t time;
+};
+
+static void list_remote_devices_do_append(char *key, char *value, void *data)
+{
+	struct remote_device_list_t *param = data;
+	char *address;
+	struct tm date;
+
+	if (slist_find(param->list, key, (cmp_func_t) strcasecmp))
+		return;
+
+	if (param->time){
+		strptime (value, "%Y-%m-%d %H:%M:%S %Z", &date);
+		if (difftime(mktime(&date), param->time) < 0)
+			return;
+	}
+
+	address = strdup(key);
+	if (!address)
+		return;
+
+	param->list = slist_append(param->list, address);
+}
+
+static void remote_devices_do_append(void *data, void *user_data)
+{
+	DBusMessageIter *iter = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data);
+}
+
+static DBusHandlerResult adapter_list_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
+		return error_invalid_arguments(conn, msg);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Seen devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_foreach(param.list, (slist_func_t)free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
+static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	const char *string;
+	struct tm date;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_get_args(msg, NULL,
+				DBUS_TYPE_STRING, &string,
+				DBUS_TYPE_INVALID))
+		return error_invalid_arguments(conn, msg);
+
+	if (strptime (string, "%Y-%m-%d %H:%M:%S", &date) == NULL)
+		return error_invalid_arguments(conn, msg);
+	param.time = mktime(&date);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_foreach(param.list, (slist_func_t)free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
 const char *major_class_str(uint32_t class)
 {
 	uint8_t index = (class >> 8) & 0x1F;
@@ -2746,6 +2868,9 @@
 	{ "DiscoverDevicesWithoutNameResolving",	adapter_discover_devices	},
 	{ "CancelDiscovery",			adapter_cancel_discovery	},
 
+	{ "ListRemoteDevices",				adapter_list_remote_devices		},
+	{ "ListRecentRemoteDevices",		adapter_list_recent_remote_devices		},
+
 	{ NULL, NULL }
 };
 
dbus-api.txt +14 -0
diff -Naur hcid.orig/dbus-api.txt hcid.new/dbus-api.txt
@@ -789,6 +789,20 @@
 					 org.bluez.Error.InProgress
 					 org.bluez.Error.Failed
 
+		array{string} ListRemoteDevices()
+
+			List device addresses of all known adapters (seen, used or bonded).
+
+			Possible errors: none
+
+		array{string} ListRecentRemoteDevices(string date)
+
+			List device addresses of all used or bonded adapters since date.
+
+			date format is "YYYY-MM-DD HH:MM:SS GMT"
+
+			Possible errors: none
+
 
 Signals		void ModeChanged(string mode)
 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

#24 lore raw
In reply to Johan Hedberg

Hello Johan,

Here is a new version of the patch updated.
Thanks for your comments.

Fred

dbus-adapter.c +125 -0
diff -Naur hcid.orig/dbus-adapter.c hcid.new/dbus-adapter.c
@@ -25,10 +25,12 @@
 #include <config.h>
 #endif
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <time.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -2615,6 +2617,126 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+struct remote_device_list_t {
+	struct slist *list;
+	time_t time;
+};
+
+static void list_remote_devices_do_append(char *key, char *value, void *data)
+{
+	struct remote_device_list_t *param = data;
+	char *address;
+	struct tm date;
+
+	if (slist_find(param->list, key, (cmp_func_t) strcasecmp))
+		return;
+
+	if (param->time){
+		strptime (value, "%Y-%m-%d %H:%M:%S %Z", &date);
+		if (difftime(mktime(&date), param->time) < 0)
+			return;
+	}
+
+	address = strdup(key);
+	if (!address)
+		return;
+
+	param->list = slist_append(param->list, address);
+}
+
+static void remote_devices_do_append(void *data, void *user_data)
+{
+	DBusMessageIter *iter = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data);
+}
+
+static DBusHandlerResult adapter_list_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
+		return error_invalid_arguments(conn, msg);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Seen devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_foreach(param.list, (slist_func_t)free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
+static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	const char *string;
+	struct tm date;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_get_args(msg, NULL,
+				DBUS_TYPE_STRING, &string,
+				DBUS_TYPE_INVALID))
+		return error_invalid_arguments(conn, msg);
+
+	if (strptime (string, "%Y-%m-%d %H:%M:%S", &date) == NULL)
+		return error_invalid_arguments(conn, msg);
+	param.time = mktime(&date);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_foreach(param.list, (slist_func_t)free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
 const char *major_class_str(uint32_t class)
 {
 	uint8_t index = (class >> 8) & 0x1F;
@@ -2746,6 +2868,9 @@
 	{ "DiscoverDevicesWithoutNameResolving",	adapter_discover_devices	},
 	{ "CancelDiscovery",			adapter_cancel_discovery	},
 
+	{ "ListRemoteDevices",				adapter_list_remote_devices		},
+	{ "ListRecentRemoteDevices",		adapter_list_recent_remote_devices		},
+
 	{ NULL, NULL }
 };
 
dbus-api.txt +14 -0
diff -Naur hcid.orig/dbus-api.txt hcid.new/dbus-api.txt
@@ -789,6 +789,20 @@
 					 org.bluez.Error.InProgress
 					 org.bluez.Error.Failed
 
+		array{string} ListRemoteDevices()
+
+			List device addresses of all known adapters (seen, used or bonded).
+
+			Possible errors: none
+
+		array{string} ListRecentRemoteDevices(string date)
+
+			List device addresses of all used or bonded adapters since date.
+
+			date format is "YYYY-MM-DD HH:MM:SS GMT"
+
+			Possible errors: none
+
 
 Signals		void ModeChanged(string mode)
 

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

#25 lore raw

Hello,

Are you OK with this patch ?

Regards

Fred

-----------------------------------------------
It is not by improving the oil lamp that one invents the electric bulb!
-----------------------------------------------
Danis Frederic PalmSource Europe
Software engineer
Mail : mailto:[email protected]
-----------------------------------------------

Frederic Danis a =E9crit :

Quoted 28 lines

Hello Johan,

Here is a new version of the patch updated.
Thanks for your comments.

Fred

------------------------------------------------------------------------

diff -Naur hcid.orig/dbus-adapter.c hcid.new/dbus-adapter.c

dbus-adapter.c +2 -0
@@ -25,10 +25,12 @@
 #include <config.h>
 #endif
 =
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <time.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>

#include <sys/socket.h>

dbus-adapter.c line 2626

Quoted 10 lines
dbus-adapter.c +6 -0
@@ -2615,6 +2617,126 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 =
 
+struct remote_device_list_t {
+	struct slist *list;
+	time_t time;
+};
+
+static void list_remote_devices_do_append(char *key, char *value, void *=

data)

Quoted 19 lines
dbus-adapter.c +19 -0
+{
+	struct remote_device_list_t *param =3D data;
+	char *address;
+	struct tm date;
+
+	if (slist_find(param->list, key, (cmp_func_t) strcasecmp))
+		return;
+
+	if (param->time){
+		strptime (value, "%Y-%m-%d %H:%M:%S %Z", &date);
+		if (difftime(mktime(&date), param->time) < 0)
+			return;
+	}
+
+	address =3D strdup(key);
+	if (!address)
+		return;
+
+	param->list =3D slist_append(param->list, address);

dbus-adapter.c

Quoted 10 lines
dbus-adapter.c +10 -0
+}
+
+static void remote_devices_do_append(void *data, void *user_data)
+{
+	DBusMessageIter *iter =3D user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data);
+}
+
+static DBusHandlerResult adapter_list_remote_devices(DBusConnection *con=

n, DBusMessage *msg, void *data)

dbus-adapter.c

Quoted 13 lines
dbus-adapter.c +13 -0
+{
+	struct adapter *adapter =3D data;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param =3D {NULL, 0};
+
+	if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
+		return error_invalid_arguments(conn, msg);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys=

");

dbus-adapter.c

Quoted 4 lines
dbus-adapter.c +4 -0
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused=

");

dbus-adapter.c

Quoted 4 lines
dbus-adapter.c +4 -0
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Seen devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen=

");

Quoted 10 lines
dbus-adapter.c +10 -0
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply =3D dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);

dbus-adapter.c

Quoted 10 lines
dbus-adapter.c +10 -0
+
+	slist_foreach(param.list, (slist_func_t)free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
+static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnecti=

on *conn, DBusMessage *msg, void *data)

Quoted 11 lines
dbus-adapter.c +11 -0
+{
+	struct adapter *adapter =3D data;
+	const char *string;
+	struct tm date;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param =3D {NULL, 0};
+
+	if (!dbus_message_get_args(msg, NULL,

dbus-adapter.c

Quoted 10 lines
dbus-adapter.c +10 -0
+				DBUS_TYPE_STRING, &string,
+				DBUS_TYPE_INVALID))
+		return error_invalid_arguments(conn, msg);
+
+	if (strptime (string, "%Y-%m-%d %H:%M:%S", &date) =3D=3D NULL)
+		return error_invalid_arguments(conn, msg);
+	param.time =3D mktime(&date);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys=

");

dbus-adapter.c

Quoted 4 lines
dbus-adapter.c +4 -0
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused=

");

Quoted 61 lines
dbus-adapter.c +19 -0
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply =3D dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_foreach(param.list, (slist_func_t)free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
 const char *major_class_str(uint32_t class)
 {
dbus-adapter.c +3 -0
 	uint8_t index =3D (class >> 8) & 0x1F;
@@ -2746,6 +2868,9 @@
 	{ "DiscoverDevicesWithoutNameResolving",	adapter_discover_devices	},
 	{ "CancelDiscovery",			adapter_cancel_discovery	},
 =
 
+	{ "ListRemoteDevices",				adapter_list_remote_devices		},
+	{ "ListRecentRemoteDevices",		adapter_list_recent_remote_devices		},
+
 	{ NULL, NULL }
 };

=

diff -Naur hcid.orig/dbus-api.txt hcid.new/dbus-api.txt

dbus-api.txt +14 -0
@@ -789,6 +789,20 @@
 					 org.bluez.Error.InProgress
 					 org.bluez.Error.Failed
 =
 
+		array{string} ListRemoteDevices()
+
+			List device addresses of all known adapters (seen, used or bonded).
+
+			Possible errors: none
+
+		array{string} ListRecentRemoteDevices(string date)
+
+			List device addresses of all used or bonded adapters since date.
+
+			date format is "YYYY-MM-DD HH:MM:SS GMT"
+
+			Possible errors: none
+
 =
 

Signals void ModeChanged(string mode)
=

Quoted 7 lines

=

------------------------------------------------------------------------

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job ea=

sier

Quoted 2 lines

Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=

=3D121642

Quoted 7 lines

------------------------------------------------------------------------

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

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easi= er
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat=3D1=
21642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#26 lore raw

Hi Fred,

Quoted 1 line · Frederic Danis

Are you OK with this patch ?

I'm fine with it (although I don't have a good use case for it). However, it'll still need Marcel's blessing before being included.

Johan

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#27 lore raw

Hi Johan,

Quoted 4 lines
Quoted 1 line

Are you OK with this patch ?

I'm fine with it (although I don't have a good use case for it). However, it'll still need Marcel's blessing before being included.

looks okay to me. Except there are two or three minor whitespace issues in the patch. One in a function call and others for the casts. Please fix them and then I am okay with that patch. I would prefer that apitest also gets updated to use these two new methods.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#28 lore raw

Hi Marcel,

Quoted 5 lines

Hi Johan,

Quoted 2 lines
Quoted 2 lines

Are you OK with this patch ?

Quoted 9 lines
Quoted 2 lines

I'm fine with it (although I don't have a good use case for it). However, it'll still need Marcel's blessing before being included.

looks okay to me. Except there are two or three minor whitespace issues in the patch. One in a function call and others for the casts. Please fix them and then I am okay with that patch. I would prefer that apitest also gets updated to use these two new methods.

Here is a new version of the patch updated. apitest is updated. Hope it is OK.

Regards

Fred

Index: hcid/dbus-adapter.c
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-adapter.c,v retrieving revision 1.135

dbus-adapter.c +125 -0
diff -u -r1.135 dbus-adapter.c
@@ -25,10 +25,12 @@
 #include <config.h>
 #endif
 
+#define _GNU_SOURCE
 #include <stdio.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <time.h>
 #include <sys/param.h>
 #include <sys/ioctl.h>
 #include <sys/socket.h>
@@ -2644,6 +2646,126 @@
 	return DBUS_HANDLER_RESULT_HANDLED;
 }
 
+struct remote_device_list_t {
+	struct slist *list;
+	time_t time;
+};
+
+static void list_remote_devices_do_append(char *key, char *value, void *data)
+{
+	struct remote_device_list_t *param = data;
+	char *address;
+	struct tm date;
+
+	if (slist_find(param->list, key, (cmp_func_t) strcasecmp))
+		return;
+
+	if (param->time){
+		strptime(value, "%Y-%m-%d %H:%M:%S %Z", &date);
+		if (difftime(mktime(&date), param->time) < 0)
+			return;
+	}
+
+	address = strdup(key);
+	if (!address)
+		return;
+
+	param->list = slist_append(param->list, address);
+}
+
+static void remote_devices_do_append(void *data, void *user_data)
+{
+	DBusMessageIter *iter = user_data;
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &data);
+}
+
+static DBusHandlerResult adapter_list_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING))
+		return error_invalid_arguments(conn, msg);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Seen devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastseen");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_foreach(param.list, (slist_func_t) free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
+static DBusHandlerResult adapter_list_recent_remote_devices(DBusConnection *conn, DBusMessage *msg, void *data)
+{
+	struct adapter *adapter = data;
+	const char *string;
+	struct tm date;
+	DBusMessageIter iter;
+	DBusMessageIter array_iter;
+	DBusMessage *reply;
+	char filename[PATH_MAX + 1];
+	struct remote_device_list_t param = {NULL, 0};
+
+	if (!dbus_message_get_args(msg, NULL,
+				DBUS_TYPE_STRING, &string,
+				DBUS_TYPE_INVALID))
+		return error_invalid_arguments(conn, msg);
+
+	if (strptime(string, "%Y-%m-%d %H:%M:%S", &date) == NULL)
+		return error_invalid_arguments(conn, msg);
+	param.time = mktime(&date);
+
+	/* Add Bonded devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "linkkeys");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	/* Add Last Used devices to the list */
+	create_name(filename, PATH_MAX, STORAGEDIR, adapter->address, "lastused");
+	textfile_foreach(filename, list_remote_devices_do_append, &param);
+
+	reply = dbus_message_new_method_return(msg);
+
+	dbus_message_iter_init_append(reply, &iter);
+
+	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+				DBUS_TYPE_STRING_AS_STRING, &array_iter);
+
+	slist_foreach(param.list, remote_devices_do_append, &array_iter);
+
+	slist_foreach(param.list, (slist_func_t) free, NULL);
+	slist_free(param.list);
+
+	dbus_message_iter_close_container(&iter, &array_iter);
+
+	return send_message_and_unref(conn, reply);
+}
+
 const char *major_class_str(uint32_t class)
 {
 	uint8_t index = (class >> 8) & 0x1F;
@@ -2776,6 +2898,9 @@
 	{ "DiscoverDevicesWithoutNameResolving",	adapter_discover_devices	},
 	{ "CancelDiscovery",			adapter_cancel_discovery	},
 
+	{ "ListRemoteDevices",			adapter_list_remote_devices		},
+	{ "ListRecentRemoteDevices",		adapter_list_recent_remote_devices		},
+
 	{ NULL, NULL }
 };
 

Index: hcid/dbus-api.txt
===================================================================
RCS file: /cvsroot/bluez/utils/hcid/dbus-api.txt,v retrieving revision 1.82

dbus-api.txt +14 -0
diff -u -r1.82 dbus-api.txt
@@ -947,6 +947,20 @@
 
 			Signals that a bonding was removed.
 
+		array{string} ListRemoteDevices()
+
+			List device addresses of all known adapters (seen, used or bonded).
+
+			Possible errors: none
+
+		array{string} ListRecentRemoteDevices(string date)
+
+			List device addresses of all used or bonded adapters since date.
+
+			date format is "YYYY-MM-DD HH:MM:SS GMT"
+
+			Possible errors: none
+
 
 Security hierarchy
 ==================

Index: test/apitest
===================================================================
RCS file: /cvsroot/bluez/utils/test/apitest,v
retrieving revision 1.2

apitest +14 -1
diff -u -r1.2 apitest
@@ -55,7 +55,9 @@
              "GetEncryptionKeySize",
              "DiscoverDevices",
              "DiscoverDevicesWithoutNameResolving",
-             "CancelDiscovery" ]
+             "CancelDiscovery",
+             "ListRemoteDevices",
+             "ListRecentRemoteDevices" ]
 dev_signals = [ "ModeChanged",
                 "NameChanged",
                 "MinorClassChanged",
@@ -386,6 +388,17 @@
                print self.device.DiscoverDevices()
            elif self.cmd == 'DiscoverDevicesWithoutNameResolving':
                print self.device.DiscoverDevicesWithoutNameResolving()
+           elif self.cmd == 'ListRemoteDevices':
+               devices = self.device.ListRemoteDevices()
+               for device in devices: 
+                   print device,
+           elif self.cmd == 'ListRecentRemoteDevices':
+               if len(self.cmd_args) == 1:
+                   devices = self.device.ListRecentRemoteDevices(self.cmd_args[0])
+                   for device in devices: 
+                       print device,
+               else:
+                   print 'Usage: %s -i <dev> ListRecentRemoteDevices date' % self.name
            else:
                 # FIXME: remove at future version
                 print 'Script Error: Method %s not found. Maybe a mispelled word.' % (self.cmd_args)

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

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

#29 lore raw

Hi Fred,

Quoted 2 lines · Frederic Danis

Here is a new version of the patch updated. apitest is updated. Hope it is OK.

It's in the CVS now. There were a few more white space issues I fixed as well as some wording in dbus-api.txt (we use "adapter" to mean a local device and "device" to mean a remote device).

Johan

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

maintainer
#30 lore raw
In reply to Matthew Garrett

Hi Matthew,

Quoted 17 lines
Quoted 8 lines

For this specific case we should only page the device if the audio device has been opened and there is actually an audio stream. I is not important if the device is in range or not. If it is not in range then you won't hear anything or we need to choose a fallback. I think that these stuff doesn't belong in the core Bluetooth daemon. You want to have an btaudiod that handles all these stuff in the back for you. The user only configures once the possible connections to headphones and headsets and then the daemon will take care of everything.

The problem isn't just in actually setting up the connections, it's in providing the information about available devices to other applications. Nowadays, the right layer for device enumeration is HAL. If I tell my system about a mobile phone, then the correct behaviour is for it to appear as a HAL object. In order for Network Manager to offer me the choice of connecting via my phone, the phone needs to be in HAL. So, somehow, at login time the phone needs to be added.

Quoted 8 lines

There's two ways of dealing with this. The one that I prefer is that we make some effort to determine that the phone actually exists, and then add it to HAL in the same way that we would if we'd just done device discovery and the phone was discoverable. This needs us to have some mechanism for determining whether the phone actually exists. The second is that we store the HAL data and repopulate HAL at login time. This is more hacky, since we're adding information without even having made a token effort to determine whether the device exists or not.

is the HAL data user specific and do we always need to populate it on login time. I think doing it once at boot and then update it on regular basis once hcid has more information about devices and/or new devices.

Regards

Marcel

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel