scan mode timeout
PATCH 1/1 scan mode timeout
Hi guys,
Here is the first proposal to support the discoverable timeout.
Current behaviour:
* it's using SIGALARM. We can try integrate in the main loop in the future..
* the scan mode is changed automatically to connectable mode after 3 min
* multiple local adapters are handled: there are separated timers.
* scan mode changes requested by other applications(hciconfig and other dbus clients) are monitored too.
Some points to things about:
* bluez_timeout_add consider the function handler and the user data to compare if it's necessary update or add new timer. Is this approach acceptable?
* Is it necessary handle race condition when updating the timeout array?
* 8 positions to timeout handler are enough?
Any comments?
Regards,
Claudio.
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
hcid/dbus.h +15 -3
@@ -65,7 +65,8 @@struct hci_dbus_data {uint16_t dev_id;uint16_t path_id; -uint32_t path_data; +uint32_t discoverable_timeout; +uint8_t mode; };typedef int register_function_t (DBusConnection *conn,uint16_t id);
@@ -106,7 +107,7 @@#define DEV_GET_ADDRESS "GetAddress"#define DEV_GET_ALIAS "GetAlias"#define DEV_GET_COMPANY "GetCompany" -#define DEV_GET_DISCOVERABLE_TO "GetDiscoverableTimeOut" +#define DEV_GET_DISCOVERABLE_TO "GetDiscoverableTimeout"#define DEV_GET_FEATURES "GetFeatures"#define DEV_GET_MANUFACTURER "GetManufacturer"#define DEV_GET_MODE "GetMode"
@@ -117,7 +118,7 @@#define DEV_IS_DISCOVERABLE "IsDiscoverable"#define DEV_SET_ALIAS "SetAlias"#define DEV_SET_CLASS "SetClass" -#define DEV_SET_DISCOVERABLE_TO "SetDiscoverableTimeOut" +#define DEV_SET_DISCOVERABLE_TO "SetDiscoverableTimeout"#define DEV_SET_MODE "SetMode"#define DEV_SET_NAME "SetName"#define DEV_DISCOVER "Discover"
@@ -219,6 +220,9 @@#define MODE_DISCOVERABLE "discoverable"#define MODE_UNKNOWN "unknown" +#define DFT_DISCOVERABLE_TIMEOUT 180/* 3 seconds */ +#define DISCOVERABLE_TIMEOUT_OFF 0 +/* BLUEZ_DBUS_ERROR * EFailed error messages signature is : su * Where the first argument is a string(error message description),
@@ -247,4 +251,12 @@/* BLUEZ_DBUS_ERR_NO_MEMORY */ #define BLUEZ_DBUS_ERR_NO_MEMORY_STR "No memory" +/*======================================================================== +timeout handler functions prototypes +*========================================================================*/ +typedef int8_t (timeout_handler_func_t ) (void *data); +int8_t bluez_timeout_add (timeout_handler_func_t *handler,uint32_t interval,void *data); +void bluez_timeout_remove (timeout_handler_func_t *handler,void *data); +int8_t scan_mode_timeout_handler (void *data); +#endif /* __H_BLUEZ_DBUS_H__ */
hcid/dbus-device.c +34 -8
78 lines not on this page · raw message
hcid/dbus.c +209 -33
337 lines not on this page · raw message
Marcel Holtmann
maintainerHi Claudio,
Quoted 10 lines
Here is the first proposal to support the discoverable timeout.
Current behaviour:
* it's using SIGALARM. We can try integrate in the main loop in the future..
* the scan mode is changed automatically to connectable mode after 3 min
* multiple local adapters are handled: there are separated timers.
* scan mode changes requested by other applications(hciconfig and other dbus clients) are monitored too.
Quoted 8 lines
Some points to things about:
*bluez_timeout_addconsider the function handler and the user data to compare if it's necessary update or add new timer. Is this approach acceptable?
* Is it necessary handle race condition when updating the timeout array?
* 8 positions to timeout handler are enough?Any comments?
maybe you wanna separate the {Set|Get}DiscoverableTimeout code, because this is obviously correct and would apply right away.
Using an array of 8 handles is actually not enough. Even if no sane person would ever attach more than 8 dongles, but I might do ;)
However you need at least to support HCI_MAX_DEV from hci.h and this is currently 16 adapters. Remember that the kernel will still accept more than 16 device, but the userspace simply can't handle them (except you recompile the Bluetooth library).
Do we have a function to iterate over the registered device paths and retrieve their hci_dbus_data structures? If yes, then I would prefer to include everything from timeout_settings there and use it.
Regards
Marcel
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Hi Marcel,
Quoted 6 lines · Marcel Holtmann
Hi Claudio,
Quoted 4 lines
Here is the first proposal to support the discoverable timeout.
Current behaviour:
* it's using SIGALARM. We can try integrate in the main loop in the fut=
ure..
Quoted 1 line
Quoted 1 line
* the scan mode is changed automatically to connectable mode after 3 mi=
n
Quoted 10 lines
Quoted 10 lines
* multiple local adapters are handled: there are separated timers.
* scan mode changes requested by other applications(hciconfig and other dbus clients) are monitored too.Some points to things about:
*bluez_timeout_addconsider the function handler and the user data to compare if it's necessary update or add new timer. Is this approach acceptable?
* Is it necessary handle race condition when updating the timeout array=
?
Quoted 6 lines
Quoted 3 lines
* 8 positions to timeout handler are enough?
Any comments?
maybe you wanna separate the {Set|Get}DiscoverableTimeout code, because this is obviously correct and would apply right away.
[Claudio Takahasi]
Ok. I will split into two patches.
Quoted 8 lines
Using an array of 8 handles is actually not enough. Even if no sane person would ever attach more than 8 dongles, but I might do ;)
However you need at least to support
HCI_MAX_DEVfromhci.hand this is currently 16 adapters. Remember that the kernel will still accept more than 16 device, but the userspace simply can't handle them (except you recompile the Bluetooth library).
[Claudio Takahasi]
ok. I will fix it.
Quoted 4 lines
Do we have a function to iterate over the registered device paths and retrieve their
hci_dbus_datastructures? If yes, then I would prefer to include everything fromtimeout_settingsthere and use it.
[Claudio Takahasi]
It's possible store in the dbus path data. Using the function "dbus_connection_get_object_path_data(DBusConnection, path, user data)" it's possible retrieve the data associated to one device. I will try propose someting soon.
Regards,
Claudio
Quoted 9 lines
Regards
Marcel
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
Quoted 3 lines
for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D103432&bid=3D230486&dat=
=3D121642
Quoted 5 lines
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Hi Marcel,
Here is patch to get/set the discoverable timeout. Currently, there isn't verification for a valid value range. Do you think that it is required?
Should we define a minimum and a maximum value?
I will send the next part(timer) soon.
Regards,
Claudio.
Quoted 71 lines · Claudio Takahasi
Hi Marcel,
Quoted 19 lines · Marcel Holtmann
Hi Claudio,
Quoted 17 lines
Here is the first proposal to support the discoverable timeout.
Current behaviour:
* it's using SIGALARM. We can try integrate in the main loop in the future..
* the scan mode is changed automatically to connectable mode after 3 min
* multiple local adapters are handled: there are separated timers.
* scan mode changes requested by other applications(hciconfig and other dbus clients) are monitored too.Some points to things about:
*bluez_timeout_addconsider the function handler and the user data to compare if it's necessary update or add new timer. Is this approach acceptable?
* Is it necessary handle race condition when updating the timeout array?
* 8 positions to timeout handler are enough?Quoted 4 lines
Quoted 1 line
Any comments?
maybe you wanna separate the {Set|Get}DiscoverableTimeout code, because this is obviously correct and would apply right away.
[Claudio Takahasi]
Ok. I will split into two patches.Quoted 8 lines
Using an array of 8 handles is actually not enough. Even if no sane person would ever attach more than 8 dongles, but I might do ;)
However you need at least to support
HCI_MAX_DEVfromhci.hand this is currently 16 adapters. Remember that the kernel will still accept more than 16 device, but the userspace simply can't handle them (except you recompile the Bluetooth library).[Claudio Takahasi]
ok. I will fix it.Quoted 4 lines
Do we have a function to iterate over the registered device paths and retrieve their
hci_dbus_datastructures? If yes, then I would prefer to include everything fromtimeout_settingsthere and use it.[Claudio Takahasi]
It's possible store in the dbus path data. Using the function "dbus_connection_get_object_path_data(DBusConnection, path, user data)" it's possible retrieve the data associated to one device. I will try propose someting soon.Regards,
ClaudioQuoted 7 lines
Regards
Marcel
Quoted 10 lines
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Quoted 5 lines
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
hcid/dbus.h +7 -3
@@ -65,7 +65,8 @@struct hci_dbus_data {uint16_t dev_id;uint16_t path_id; -uint32_t path_data; +uint32_t discoverable_timeout; +uint8_t mode; };typedef int register_function_t (DBusConnection *conn,uint16_t id);
@@ -106,7 +107,7 @@#define DEV_GET_ADDRESS "GetAddress"#define DEV_GET_ALIAS "GetAlias"#define DEV_GET_COMPANY "GetCompany" -#define DEV_GET_DISCOVERABLE_TO "GetDiscoverableTimeOut" +#define DEV_GET_DISCOVERABLE_TO "GetDiscoverableTimeout"#define DEV_GET_FEATURES "GetFeatures"#define DEV_GET_MANUFACTURER "GetManufacturer"#define DEV_GET_MODE "GetMode"
@@ -117,7 +118,7 @@#define DEV_IS_DISCOVERABLE "IsDiscoverable"#define DEV_SET_ALIAS "SetAlias"#define DEV_SET_CLASS "SetClass" -#define DEV_SET_DISCOVERABLE_TO "SetDiscoverableTimeOut" +#define DEV_SET_DISCOVERABLE_TO "SetDiscoverableTimeout"#define DEV_SET_MODE "SetMode"#define DEV_SET_NAME "SetName"#define DEV_DISCOVER "Discover"
@@ -219,6 +220,9 @@#define MODE_DISCOVERABLE "discoverable"#define MODE_UNKNOWN "unknown" +#define DFT_DISCOVERABLE_TIMEOUT 180/* 3 seconds */ +#define DISCOVERABLE_TIMEOUT_OFF 0 +/* BLUEZ_DBUS_ERROR * EFailed error messages signature is : su * Where the first argument is a string(error message description),
hcid/dbus-device.c +27 -8
@@ -248,15 +248,23 @@static DBusMessage *handle_dev_get_discoverable_to_req (DBusMessage *msg,void *data) { -/*FIXME: */ -return bluez_new_failure_msg (msg,BLUEZ_EDBUS_NOT_IMPLEMENTED ); +const struct hci_dbus_data *dbus_data = data; +DBusMessage *reply =NULL ; + + reply =dbus_message_new_method_return (msg); + +dbus_message_append_args (reply, +DBUS_TYPE_UINT32 , &dbus_data->discoverable_timeout, +DBUS_TYPE_INVALID ); + +return reply; }static DBusMessage *handle_dev_get_mode_req (DBusMessage *msg,void *data) {const struct hci_dbus_data *dbus_data = data;DBusMessage *reply =NULL ; -const uint8_t hci_mode = dbus_data->path_data; +const uint8_t hci_mode = dbus_data->mode;const char *scan_mode;switch (hci_mode) {
@@ -288,7 +296,7 @@ {const struct hci_dbus_data *dbus_data = data;DBusMessage *reply =NULL ; -const uint8_t hci_mode = dbus_data->path_data; +const uint8_t hci_mode = dbus_data->mode;dbus_bool_t connectable = FALSE;if (hci_mode &SCAN_PAGE )
@@ -306,7 +314,7 @@ {const struct hci_dbus_data *dbus_data = data;DBusMessage *reply =NULL ; -const uint8_t hci_mode = dbus_data->path_data; +const uint8_t hci_mode = dbus_data->mode;dbus_bool_t discoverable = FALSE;if (hci_mode &SCAN_INQUIRY )
@@ -328,8 +336,19 @@static DBusMessage *handle_dev_set_discoverable_to_req (DBusMessage *msg,void *data) { -/*FIXME: */ -return bluez_new_failure_msg (msg,BLUEZ_EDBUS_NOT_IMPLEMENTED ); +struct hci_dbus_data *dbus_data = data; +DBusMessage *reply =NULL ; +DBusMessageIter iter; +uint32_t timeout; + +dbus_message_iter_init (msg, &iter); +dbus_message_iter_get_basic (&iter, &timeout); + + dbus_data->discoverable_timeout = timeout; + + reply =dbus_message_new_method_return (msg); + +return reply; }static DBusMessage *handle_dev_set_mode_req (DBusMessage *msg,void *data)
@@ -341,7 +360,7 @@const char * scan_mode;uint8_t hci_mode;uint8_t status =0 ; -const uint8_t current_mode = dbus_data->path_data; +const uint8_t current_mode = dbus_data->mode; dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &scan_mode,
hcid/dbus.c +4 -2
@@ -224,6 +224,8 @@ data->path_id = path_id; data->dev_id = dev_id; + data->mode =MODE_OFF ; + data->discoverable_timeout =DFT_DISCOVERABLE_TIMEOUT ;if (fallback) {if (!dbus_connection_register_fallback (connection, path, pvtable, data)) {
@@ -309,7 +311,7 @@if (!dbus_connection_get_object_path_data (connection, path, (void *) &pdata))syslog (LOG_ERR ,"Getting path data failed!" );else - pdata->path_data = rp.enable;/* Keep the current scan status */ + pdata->mode = rp.enable;/* Keep the current scan status */ message =dbus_message_new_signal (MANAGER_PATH ,MANAGER_INTERFACE ,BLUEZ_MGR_DEV_ADDED );
@@ -1096,7 +1098,7 @@ }/* update the current scan mode value */ - pdata->path_data = rp.enable; + pdata->mode = rp.enable;switch (rp.enable) {case SCAN_DISABLED :
Marcel Holtmann
maintainerHi Claudio,
Quoted 1 line
Here is patch to get/set the discoverable timeout.
the patch is applied to the CVS, but you should watch out for compiler warnings. They help you to find some bugs ;)
dbus.c: In function =E2=80=98register_dbus_path=E2=80=99:
dbus.c:227: warning: assignment makes integer from pointer without a cast
Quoted 3 lines
Currently, there isn't verification for a valid value range. Do you think that it is required?
Should we define a minimum and a maximum value?
I don't know. We will see.
Regards
Marcel
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Hi Marcel,
Here is the patch based on the registered D-Bus paths.
This patch is working fine, except for the following case:
After restart the D-Bus daemon, the paths are being registered properly. However, if you remove and after add the dongle the HCI events is not being received by the hcid anymore. This problem happens with older hcid versions too :-) I lost some hours trying to fix this weird problem.
How reproduce the error:
pre-condition: at least one dongle connected.
1. start the hcid "hcid -n"
2. restart the dbus-daemon "$/etc/init.d/dbus-1 restart"
3. remove and add the dongle. Note that the HCI removed/added device event are not received. If you run the hciconfig command you can see that the device is DOWN.
Do you have any idea of what is happening? IMHO, it seems to a problem related to main loop add/remove watches function. I will investigate more and try give you a feedback later.
I investigated how other applications are handling the D-Bus Disconnect event. All applications are exiting :-) Some linux distributions are changed the /etc/init.d/dbus-1including command to start the daemons(avahi, hald, ...). If we don't fix this bug, we can try use this approach :-)
Do you have another comments about this patch?
Regards,
Claudio.
Quoted 23 lines · Marcel Holtmann
Hi Claudio,
Quoted 1 line
Here is patch to get/set the discoverable timeout.
the patch is applied to the CVS, but you should watch out for compiler warnings. They help you to find some bugs ;)
dbus.c: In function 'register_dbus_path':
dbus.c:227: warning: assignment makes integer from pointer without a castQuoted 3 lines
Currently, there isn't verification for a valid value range. Do you think that it is required?
Should we define a minimum and a maximum value?I don't know. We will see.
Regards
Marcel
Quoted 10 lines
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
hcid/dbus.h +4 -0
@@ -62,10 +62,14 @@const char *signature; }; +typedef int (timeout_handler_func_t ) (void *data); +struct hci_dbus_data {uint16_t dev_id;uint16_t path_id;uint32_t discoverable_timeout; +uint32_t timeout_hits; +timeout_handler_func_t *timeout_handler;uint8_t mode; };
hcid/dbus.c +134 -27
241 lines not on this page · raw message
Hi Marcel,
Here is a patch to fix a small bug that skipped :)
I was not able to check this because the patch to fix the remove watch
was required. When I sent the patch(timeout03.patch) the solution for
fix the remove watch function was not ready.
This patch fix the following bug:
With the hcid running restart the dbus-daemon before the discoverable timeout expires. When the dbus-daemon is restarted the paths are registered again, thefore the dbus_data stored in the path is overwritten and the handler_timeout pointer becomes NULL. The side-effect is turn off the timer and the discoverable mode will be changed to connectable mode!
Regards,
Claudio
Quoted 69 lines · Claudio Takahasi
Hi Marcel,
Here is the patch based on the registered D-Bus paths.
This patch is working fine, except for the following case:
After restart the D-Bus daemon, the paths are being registered properly. However, if you remove and after add the dongle the HCI events is not being received by the hcid anymore. This problem happens with older hcid versions too :-) I lost some hours trying to fix this weird problem.How reproduce the error:
pre-condition: at least one dongle connected.
1. start the hcid "hcid -n"
2. restart the dbus-daemon "$/etc/init.d/dbus-1 restart"
3. remove and add the dongle. Note that the HCI removed/added device event are not received. If you run the hciconfig command you can see that the device is DOWN.
Do you have any idea of what is happening? IMHO, it seems to a problem related to main loop add/remove watches function. I will investigate more and try give you a feedback later.I investigated how other applications are handling the D-Bus Disconnect event. All applications are exiting :-) Some linux distributions are changed the
/etc/init.d/dbus-1includingcommand to start thedaemons(avahi, hald, ...). If we don't fix this bug, we can try use this approach :-)Do you have another comments about this patch?
Regards,
Claudio.Quoted 23 lines · Marcel Holtmann
Hi Claudio,
Quoted 1 line
Here is patch to get/set the discoverable timeout.
the patch is applied to the CVS, but you should watch out for compiler warnings. They help you to find some bugs ;)
dbus.c: In function 'register_dbus_path':
dbus.c:227: warning: assignment makes integer from pointer without a castQuoted 3 lines
Currently, there isn't verification for a valid value range. Do you think that it is required?
Should we define a minimum and a maximum value?I don't know. We will see.
Regards
Marcel
Quoted 10 lines
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmdlnk&kid3432&bid#0486&dat1642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Quoted 7 lines
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
hcid/dbus.c +12 -0
@@ -67,6 +67,11 @@bdaddr_t bda; }; +/* +* Timeout functions Protypes +*/ +static int discoverable_timeout_handler (void *data); +DBusConnection *get_dbus_connection (void ) {return connection;
@@ -315,6 +320,13 @@else pdata->mode = rp.enable;/* Keep the current scan status */ +/* +* Enable timeout to address dbus daemon restart, where +* register the device paths is required due connection lost. +*/ +if (pdata->mode &SCAN_INQUIRY ) + pdata->timeout_handler = &discoverable_timeout_handler; + message =dbus_message_new_signal (MANAGER_PATH ,MANAGER_INTERFACE ,BLUEZ_MGR_DEV_ADDED );if (message ==NULL ) {
Marcel Holtmann
maintainerHi Claudio,
Quoted 5 lines
Here is a patch to fix a small bug that skipped :)
I was not able to check this because the patch to fix the remove watch
was required. When I sent the patch(timeout03.patch) the solution for
fix the remove watch function was not ready.
Quoted 7 lines
This patch fix the following bug:
With the hcid running restart the dbus-daemon before the discoverable timeout expires. When the dbus-daemon is restarted the paths are registered again, thefore thedbus_datastored in the path is overwritten and thehandler_timeoutpointer becomes NULL. The side-effect is turn off the timer and the discoverable mode will be changed to connectable mode!
the patch is in the CVS now. Thanks.
Regards
Marcel
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel