* [Bluez-devel] [DBUS PATCH] scan mode timeout
@ 2006-02-15 14:11 Claudio Takahasi
2006-02-15 14:20 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2006-02-15 14:11 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 892 bytes --]
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
[-- Attachment #2: timeout01.patch --]
[-- Type: text/x-patch, Size: 13745 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2006-02-14 05:37:57.000000000 -0200
+++ bluez-utils-cvs-scan-timeout/hcid/dbus.h 2006-02-15 08:45:35.000000000 -0200
@@ -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__ */
--- bluez-utils-cvs.orig/hcid/dbus-device.c 2006-02-14 05:37:57.000000000 -0200
+++ bluez-utils-cvs-scan-timeout/hcid/dbus-device.c 2006-02-14 16:08:25.000000000 -0200
@@ -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,26 @@
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);
+
+ if ((timeout < DFT_DISCOVERABLE_TIMEOUT) && (timeout != 0))
+ return bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
+
+ dbus_data->discoverable_timeout = timeout;
+
+ /* update the timeout value if timeout is running */
+ if (dbus_data->mode & SCAN_INQUIRY)
+ bluez_timeout_add(&scan_mode_timeout_handler, timeout, data);
+
+ reply = dbus_message_new_method_return(msg);
+
+ return reply;
}
static DBusMessage* handle_dev_set_mode_req(DBusMessage *msg, void *data)
@@ -341,7 +367,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,
--- bluez-utils-cvs.orig/hcid/dbus.c 2006-02-14 05:37:57.000000000 -0200
+++ bluez-utils-cvs-scan-timeout/hcid/dbus.c 2006-02-15 09:04:27.000000000 -0200
@@ -54,7 +54,7 @@
static int default_dev = -1;
#define TIMEOUT (30 * 1000) /* 30 seconds */
-#define DBUS_RECONNECT_TIMER (5 * 1000 * 1000) /* 5 sec */
+#define DBUS_RECONNECT_TIMER 5 /* 5 sec */
#define MAX_CONN_NUMBER 10
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
@@ -67,6 +67,23 @@
bdaddr_t bda;
};
+/*
+ * Structures/constants related to timer functions
+ */
+
+/*FIXME: Check the maximum value */
+#define MAX_TIMER_ARRAY_SIZE 8
+
+struct timeout_settings {
+ timeout_handler_func_t *handler;
+ void *data;
+ uint32_t interval;
+ uint32_t hits;
+};
+
+static struct timeout_settings timeout_array[MAX_TIMER_ARRAY_SIZE];
+static uint8_t index_mask = 0;
+
DBusConnection *get_dbus_connection(void)
{
return connection;
@@ -224,6 +241,8 @@
data->path_id = path_id;
data->dev_id = dev_id;
+ data->mode = 0;
+ data->discoverable_timeout = DFT_DISCOVERABLE_TIMEOUT;
if (fallback) {
if (!dbus_connection_register_fallback(connection, path, pvtable, data)) {
@@ -252,8 +271,10 @@
syslog(LOG_INFO, "[%s,%d] path:%s", __PRETTY_FUNCTION__, __LINE__, path);
- if (dbus_connection_get_object_path_data(connection, path, &data) && data)
+ if (dbus_connection_get_object_path_data(connection, path, &data) && data){
+ bluez_timeout_remove(&scan_mode_timeout_handler, data);
free(data);
+ }
if (!dbus_connection_unregister_object_path (connection, path)) {
syslog(LOG_ERR, "DBUS failed to unregister %s object", path);
@@ -309,7 +330,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);
@@ -859,19 +880,185 @@
* Section reserved to re-connection timer
*
*****************************************************************/
-static void reconnect_timer_handler(int signum)
+static void timeout_handler (int signum)
+{
+ int8_t retval;
+ int8_t i;
+ uint8_t pos;
+
+ for (i = 0; i < MAX_TIMER_ARRAY_SIZE; i++ ) {
+ pos = (0x01 << i);
+ if ( pos & index_mask) {
+ /* Check if someome changed the interval to zero - it means discoverable forever*/
+ if (timeout_array[i].interval == 0) {
+ timeout_array[i].handler = NULL;
+ timeout_array[i].interval = 0;
+ timeout_array[i].data = NULL;
+
+ /* reset the bitmask */
+ index_mask &= ~pos;
+ break;
+ }
+
+ /* Check if is time to call the function handler */
+ if ((++timeout_array[i].hits % timeout_array[i].interval ) == 0) {
+ retval = (timeout_array[i].handler)(timeout_array[i].data);
+ if (!retval) {
+ timeout_array[i].handler = NULL;
+ timeout_array[i].interval = 0;
+ timeout_array[i].data = NULL;
+ /* reset the bitmask */
+ index_mask &= ~pos;
+ }
+ }
+ }
+ }
+
+ if (!index_mask) {
+ /* stop the timer */
+ sigaction(SIGALRM, NULL, NULL);
+ setitimer(ITIMER_REAL, NULL, NULL);
+ }
+}
+
+int8_t bluez_timeout_add(timeout_handler_func_t *handler, uint32_t interval, void *data)
+{
+ struct sigaction sa;
+ struct itimerval timer;
+ int8_t i;
+ int8_t next_pos = -1;
+ uint8_t pos;
+
+ if (!index_mask) {
+
+ memset (&sa, 0, sizeof (sa));
+ sa.sa_handler = &timeout_handler;
+ sigaction(SIGALRM, &sa, NULL);
+
+ /* expire after 1 sec... */
+ timer.it_value.tv_sec = 1;
+ timer.it_value.tv_usec = 0;
+
+ /* ... and every 1 sec after that. */
+ timer.it_interval.tv_sec = 1;
+ timer.it_interval.tv_usec = 0;
+
+ setitimer(ITIMER_REAL, &timer, NULL);
+ }
+
+ /* Overwrite one position or make room for a new one */
+ for (i = 0; i< MAX_TIMER_ARRAY_SIZE; i++) {
+ pos = 1 << i;
+ /* check if the handler already belongs to the array. Check data
+ * attribure is required to support multiple local adapter.
+ */
+ if ((timeout_array[i].handler == handler) && (timeout_array[i].data == data)) {
+ /* it's necessary overwrite the timeout value */
+ next_pos = i;
+ break;
+ }
+ if (!(pos & index_mask)) {
+ /* set the next available position */
+ next_pos = i;
+ }
+ }
+
+ if ( next_pos < 0 ) {
+ /* There isn't space for more timeouts */
+ return -1;
+ }
+
+ timeout_array[next_pos].handler = handler;
+ timeout_array[next_pos].interval = interval;
+ timeout_array[next_pos].data = data;
+ timeout_array[next_pos].hits = 0;
+ index_mask |= (1 << next_pos);
+
+ return i;
+}
+
+void bluez_timeout_remove(timeout_handler_func_t *handler, void *data)
+{
+ int8_t i;
+ uint8_t pos;
+
+ if (!index_mask) {
+ return;
+ }
+
+ for (i = 0; i < MAX_TIMER_ARRAY_SIZE; i++) {
+ pos = 1 << i;
+ if ((timeout_array[i].handler == handler) && (timeout_array[i].data == data)) {
+ timeout_array[i].handler = NULL;
+ timeout_array[i].interval = 0;
+ timeout_array[i].data = NULL;
+ index_mask &= ~pos;
+ break;
+ }
+ }
+
+ if ( !index_mask ) {
+ /* cancel the timer */
+ sigaction(SIGALRM, NULL, NULL);
+ setitimer(ITIMER_REAL, NULL, NULL);
+ }
+}
+
+int8_t scan_mode_timeout_handler(void *data)
+{
+ const struct hci_dbus_data *dbus_data = data;
+ struct hci_request rq;
+ int dd = -1;
+ uint8_t hci_mode = dbus_data->mode;
+ uint8_t status = 0;
+ int8_t retval = 0;
+
+ hci_mode &= ~SCAN_INQUIRY;
+
+ dd = hci_open_dev(dbus_data->dev_id);
+ if (dd < 0) {
+ syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+ return -1;
+ }
+
+ memset(&rq, 0, sizeof(rq));
+ rq.ogf = OGF_HOST_CTL;
+ rq.ocf = OCF_WRITE_SCAN_ENABLE;
+ rq.cparam = &hci_mode;
+ rq.clen = sizeof(hci_mode);
+ rq.rparam = &status;
+ rq.rlen = sizeof(status);
+
+ if (hci_send_req(dd, &rq, 100) < 0) {
+ syslog(LOG_ERR, "Sending write scan enable command to hci%d failed: %s (%d)",
+ dbus_data->dev_id, strerror(errno), errno);
+ retval = -1;
+ goto failed;
+ }
+ if (status) {
+ syslog(LOG_ERR, "Setting scan enable failed with status 0x%02x", status);
+ retval = -1;
+ goto failed;
+ }
+
+failed:
+ if (dd >= 0)
+ close(dd);
+
+ return retval;
+
+}
+
+static int8_t system_bus_reconnect_handler(void *data)
{
struct hci_dev_list_req *dl = NULL;
struct hci_dev_req *dr;
int sk;
int i;
+ int8_t retval = 0;
if (hcid_dbus_init() == FALSE)
- return;
-
- /* stop the timer */
- sigaction(SIGALRM, NULL, NULL);
- setitimer(ITIMER_REAL, NULL, NULL);
+ return -1;
/* register the device based paths */
@@ -880,12 +1067,13 @@
if (sk < 0) {
syslog(LOG_ERR, "Can't open HCI socket: %s (%d)",
strerror(errno), errno);
- return;
+ return -1;
}
dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
if (!dl) {
syslog(LOG_ERR, "Can't allocate memory");
+ retval = -1;
goto failed;
}
@@ -895,6 +1083,7 @@
if (ioctl(sk, HCIGETDEVLIST, (void *) dl) < 0) {
syslog(LOG_INFO, "Can't get device list: %s (%d)",
strerror(errno), errno);
+ retval = -1;
goto failed;
}
@@ -910,26 +1099,8 @@
if (dl)
free(dl);
-}
-
-static void reconnect_timer_start(void)
-{
- struct sigaction sa;
- struct itimerval timer;
- memset (&sa, 0, sizeof (sa));
- sa.sa_handler = &reconnect_timer_handler;
- sigaction(SIGALRM, &sa, NULL);
-
- /* expire after X msec... */
- timer.it_value.tv_sec = 0;
- timer.it_value.tv_usec = DBUS_RECONNECT_TIMER;
-
- /* ... and every x msec after that. */
- timer.it_interval.tv_sec = 0;
- timer.it_interval.tv_usec = DBUS_RECONNECT_TIMER;
-
- setitimer(ITIMER_REAL, &timer, NULL);
+ return retval;
}
/*****************************************************************
@@ -958,7 +1129,7 @@
dbus_connection_dispatch(conn);
dbus_connection_close(conn);
dbus_connection_unref(conn);
- reconnect_timer_start();
+ bluez_timeout_add(&system_bus_reconnect_handler, DBUS_RECONNECT_TIMER, NULL);
ret = DBUS_HANDLER_RESULT_HANDLED;
} else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
if (strcmp(method, "NameOwnerChanged") == 0)
@@ -1078,8 +1249,8 @@
rq.rlen = READ_SCAN_ENABLE_RP_SIZE;
if (hci_send_req(dd, &rq, 100) < 0) {
- syslog(LOG_ERR, "Sending read scan enable command failed: %s (%d)",
- strerror(errno), errno);
+ syslog(LOG_ERR, "Sending read scan enable command to hci%d failed: %s (%d)",
+ id, strerror(errno), errno);
goto failed;
}
@@ -1096,16 +1267,21 @@
}
/* update the current scan mode value */
- pdata->path_data = rp.enable;
+ pdata->mode = rp.enable;
switch (rp.enable) {
case SCAN_DISABLED:
scan_mode = MODE_OFF;
+ bluez_timeout_remove(&scan_mode_timeout_handler, pdata);
break;
case SCAN_PAGE:
scan_mode = MODE_CONNECTABLE;
+ bluez_timeout_remove(&scan_mode_timeout_handler, pdata);
break;
case (SCAN_PAGE | SCAN_INQUIRY):
+ if (pdata->discoverable_timeout != DISCOVERABLE_TIMEOUT_OFF)
+ bluez_timeout_add(&scan_mode_timeout_handler, pdata->discoverable_timeout, pdata);
+
scan_mode = MODE_DISCOVERABLE;
break;
case SCAN_INQUIRY:
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Bluez-devel] [DBUS PATCH] scan mode timeout
2006-02-15 14:11 [Bluez-devel] [DBUS PATCH] scan mode timeout Claudio Takahasi
@ 2006-02-15 14:20 ` Marcel Holtmann
2006-02-15 16:31 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2006-02-15 14:20 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> 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?
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
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Bluez-devel] [DBUS PATCH] scan mode timeout
2006-02-15 14:20 ` Marcel Holtmann
@ 2006-02-15 16:31 ` Claudio Takahasi
2006-02-15 17:18 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2006-02-15 16:31 UTC (permalink / raw)
To: bluez-devel
Hi Marcel,
On 2/15/06, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > 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..
> > * the scan mode is changed automatically to connectable mode after 3 mi=
n
> > * 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?
>
> 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.
>
> 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).
[Claudio Takahasi]
ok. I will fix it.
>
> 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.
[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
> Regards
>
> Marcel
>
>
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=
les
> 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
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> 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
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Bluez-devel] [DBUS PATCH] scan mode timeout
2006-02-15 16:31 ` Claudio Takahasi
@ 2006-02-15 17:18 ` Claudio Takahasi
2006-02-15 17:46 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2006-02-15 17:18 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 3332 bytes --]
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.
On 2/15/06, Claudio Takahasi <cktakahasi@gmail.com> wrote:
> Hi Marcel,
>
> On 2/15/06, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Claudio,
> >
> > > 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?
> >
> > 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.
>
> >
> > 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).
> [Claudio Takahasi]
> ok. I will fix it.
> >
> > 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.
> [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
>
> > 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
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
> --
> ---------------------------------------------------------
> Claudio Takahasi
> Instituto Nokia de Tecnologia - INdT
>
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
[-- Attachment #2: timeout02.patch --]
[-- Type: text/x-patch, Size: 4717 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2006-02-14 05:37:57.000000000 -0200
+++ bluez-utils-cvs-disc-timeout/hcid/dbus.h 2006-02-15 11:59:12.000000000 -0200
@@ -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),
--- bluez-utils-cvs.orig/hcid/dbus-device.c 2006-02-14 05:37:57.000000000 -0200
+++ bluez-utils-cvs-disc-timeout/hcid/dbus-device.c 2006-02-15 12:02:43.000000000 -0200
@@ -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,
--- bluez-utils-cvs.orig/hcid/dbus.c 2006-02-14 05:37:57.000000000 -0200
+++ bluez-utils-cvs-disc-timeout/hcid/dbus.c 2006-02-15 11:43:34.000000000 -0200
@@ -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:
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Bluez-devel] [DBUS PATCH] scan mode timeout
2006-02-15 17:18 ` Claudio Takahasi
@ 2006-02-15 17:46 ` Marcel Holtmann
2006-02-16 18:41 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2006-02-15 17:46 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> 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
> 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
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Bluez-devel] [DBUS PATCH] scan mode timeout
2006-02-15 17:46 ` Marcel Holtmann
@ 2006-02-16 18:41 ` Claudio Takahasi
2006-02-17 17:48 ` Claudio Takahasi
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2006-02-16 18:41 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 2574 bytes --]
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.
On 2/15/06, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Claudio,
>
> > 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 cast
>
> > 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?cmdlnk&kid\x103432&bid#0486&dat\x121642
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
>
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
[-- Attachment #2: timeout03.patch --]
[-- Type: text/x-patch, Size: 7011 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.h 2006-02-16 09:17:41.000000000 -0200
+++ bluez-utils-cvs-timer/hcid/dbus.h 2006-02-16 13:19:09.000000000 -0200
@@ -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;
};
--- bluez-utils-cvs.orig/hcid/dbus.c 2006-02-16 09:17:41.000000000 -0200
+++ bluez-utils-cvs-timer/hcid/dbus.c 2006-02-16 13:18:50.000000000 -0200
@@ -52,9 +52,9 @@
static DBusConnection *connection;
static int default_dev = -1;
+static volatile sig_atomic_t __timeout_active = 0;
#define TIMEOUT (30 * 1000) /* 30 seconds */
-#define DBUS_RECONNECT_TIMER (5 * 1000 * 1000) /* 5 sec */
#define MAX_CONN_NUMBER 10
#define PINAGENT_SERVICE_NAME BASE_INTERFACE ".PinAgent"
@@ -224,8 +224,10 @@
data->path_id = path_id;
data->dev_id = dev_id;
- data->mode = 0x00;
+ data->mode = SCAN_DISABLED;
data->discoverable_timeout = DFT_DISCOVERABLE_TIMEOUT;
+ data->timeout_hits = 0;
+ data->timeout_handler = NULL;
if (fallback) {
if (!dbus_connection_register_fallback(connection, path, pvtable, data)) {
@@ -393,7 +395,7 @@
uint8_t *addr = (uint8_t *) &ci->bdaddr;
dbus_bool_t out = ci->out;
- if (!connection) {
+ if (!dbus_connection_get_is_connected(connection)) {
if (!hcid_dbus_init())
goto failed;
}
@@ -830,24 +832,24 @@
void hcid_dbus_exit(void)
{
char **children = NULL;
+ int i = 0;
- if (!connection)
+ if (!dbus_connection_get_is_connected(connection))
return;
/* Unregister all paths in Device path hierarchy */
if (!dbus_connection_list_registered(connection, DEVICE_PATH, &children))
goto done;
- for (; *children; children++) {
+ for (; children[i]; i++) {
char dev_path[MAX_PATH_LENGTH];
- snprintf(dev_path, sizeof(dev_path), "%s/%s", DEVICE_PATH, *children);
+ snprintf(dev_path, sizeof(dev_path), "%s/%s", DEVICE_PATH, children[i]);
unregister_dbus_path(dev_path);
}
- if (*children)
- dbus_free_string_array(children);
+ dbus_free_string_array(children);
done:
unregister_dbus_path(DEVICE_PATH);
@@ -861,7 +863,52 @@
* Section reserved to re-connection timer
*
*****************************************************************/
-static void reconnect_timer_handler(int signum)
+
+static int discoverable_timeout_handler(void *data)
+{
+ const struct hci_dbus_data *dbus_data = data;
+ struct hci_request rq;
+ int dd = -1;
+ uint8_t hci_mode = dbus_data->mode;
+ uint8_t status = 0;
+ int8_t retval = 0;
+
+ hci_mode &= ~SCAN_INQUIRY;
+
+ dd = hci_open_dev(dbus_data->dev_id);
+ if (dd < 0) {
+ syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
+ return -1;
+ }
+
+ memset(&rq, 0, sizeof(rq));
+ rq.ogf = OGF_HOST_CTL;
+ rq.ocf = OCF_WRITE_SCAN_ENABLE;
+ rq.cparam = &hci_mode;
+ rq.clen = sizeof(hci_mode);
+ rq.rparam = &status;
+ rq.rlen = sizeof(status);
+
+ if (hci_send_req(dd, &rq, 100) < 0) {
+ syslog(LOG_ERR, "Sending write scan enable command to hci%d failed: %s (%d)",
+ dbus_data->dev_id, strerror(errno), errno);
+ retval = -1;
+ goto failed;
+ }
+ if (status) {
+ syslog(LOG_ERR, "Setting scan enable failed with status 0x%02x", status);
+ retval = -1;
+ goto failed;
+ }
+
+failed:
+ if (dd >= 0)
+ close(dd);
+
+ return retval;
+}
+
+static void system_bus_reconnect(void)
{
struct hci_dev_list_req *dl = NULL;
struct hci_dev_req *dr;
@@ -871,12 +918,6 @@
if (hcid_dbus_init() == FALSE)
return;
- /* stop the timer */
- sigaction(SIGALRM, NULL, NULL);
- setitimer(ITIMER_REAL, NULL, NULL);
-
- /* register the device based paths */
-
/* Create and bind HCI socket */
sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sk < 0) {
@@ -914,22 +955,85 @@
free(dl);
}
-static void reconnect_timer_start(void)
+static void sigalarm_handler (int signum)
+{
+ struct hci_dbus_data *pdata = NULL;
+ char device_path[MAX_PATH_LENGTH];
+ char **device = NULL;
+ int active_handlers = 0;
+ int i = 0;
+
+ if (!dbus_connection_get_is_connected(connection)) {
+ /* it is not connected */
+ system_bus_reconnect();
+ return;
+ }
+
+ if (!dbus_connection_list_registered(connection, DEVICE_PATH, &device))
+ goto done;
+
+ /* check the timer for each registered path */
+ for (; device[i]; i++) {
+
+ snprintf(device_path, sizeof(device_path), "%s/%s", DEVICE_PATH, device[i]);
+
+ if (!dbus_connection_get_object_path_data(connection, device_path, (void*) &pdata)){
+ syslog(LOG_ERR, "Getting %s path data failed!", device_path);
+ continue;
+ }
+
+ if (pdata->timeout_handler == NULL)
+ continue;
+
+ if (!(pdata->mode & SCAN_INQUIRY)) {
+ pdata->timeout_hits = 0;
+ continue;
+ }
+
+ active_handlers++;
+
+ if ((++(pdata->timeout_hits) % pdata->discoverable_timeout) != 0)
+ continue;
+
+ if (!pdata->timeout_handler(pdata)) {
+ /* Remove from the timeout queue */
+ pdata->timeout_handler = NULL;
+ pdata->timeout_hits = 0;
+ active_handlers--;
+ }
+ }
+
+ dbus_free_string_array(device);
+
+done:
+ if (!active_handlers) {
+ sigaction(SIGALRM, NULL, NULL);
+ setitimer(ITIMER_REAL, NULL, NULL);
+ __timeout_active = 0;
+ }
+}
+
+static void bluez_timeout_start(void)
{
struct sigaction sa;
struct itimerval timer;
+ if (__timeout_active)
+ return;
+
+ __timeout_active = 1;
+
memset (&sa, 0, sizeof (sa));
- sa.sa_handler = &reconnect_timer_handler;
+ sa.sa_handler = &sigalarm_handler;
sigaction(SIGALRM, &sa, NULL);
- /* expire after X msec... */
- timer.it_value.tv_sec = 0;
- timer.it_value.tv_usec = DBUS_RECONNECT_TIMER;
-
- /* ... and every x msec after that. */
- timer.it_interval.tv_sec = 0;
- timer.it_interval.tv_usec = DBUS_RECONNECT_TIMER;
+ /* expire after 1 sec... */
+ timer.it_value.tv_sec = 1;
+ timer.it_value.tv_usec = 0;
+
+ /* ... and every 1 sec after that. */
+ timer.it_interval.tv_sec = 1;
+ timer.it_interval.tv_usec = 0;
setitimer(ITIMER_REAL, &timer, NULL);
}
@@ -957,10 +1061,8 @@
if ((strcmp(iface, DBUS_INTERFACE_LOCAL) == 0) &&
(strcmp(method, "Disconnected") == 0)) {
syslog(LOG_ERR, "Got disconnected from the system message bus");
- dbus_connection_dispatch(conn);
- dbus_connection_close(conn);
dbus_connection_unref(conn);
- reconnect_timer_start();
+ bluez_timeout_start();
ret = DBUS_HANDLER_RESULT_HANDLED;
} else if (strcmp(iface, DBUS_INTERFACE_DBUS) == 0) {
if (strcmp(method, "NameOwnerChanged") == 0)
@@ -1109,8 +1211,13 @@
break;
case (SCAN_PAGE | SCAN_INQUIRY):
scan_mode = MODE_DISCOVERABLE;
+ pdata->timeout_handler = &discoverable_timeout_handler;
+ bluez_timeout_start();
break;
case SCAN_INQUIRY:
+ /* Address the scenario where another app changed the scan mode */
+ pdata->timeout_handler = &discoverable_timeout_handler;
+ bluez_timeout_start();
/* ignore, this event should not be sent*/
default:
/* ignore, reserved */
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Bluez-devel] [DBUS PATCH] scan mode timeout
2006-02-16 18:41 ` Claudio Takahasi
@ 2006-02-17 17:48 ` Claudio Takahasi
2006-02-17 17:58 ` Marcel Holtmann
0 siblings, 1 reply; 8+ messages in thread
From: Claudio Takahasi @ 2006-02-17 17:48 UTC (permalink / raw)
To: bluez-devel
[-- Attachment #1: Type: text/plain, Size: 3581 bytes --]
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
On 2/16/06, Claudio Takahasi <cktakahasi@gmail.com> wrote:
> 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.
>
> On 2/15/06, Marcel Holtmann <marcel@holtmann.org> wrote:
> > Hi Claudio,
> >
> > > 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 cast
> >
> > > 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?cmdlnk&kid\x103432&bid#0486&dat\x121642
> > _______________________________________________
> > Bluez-devel mailing list
> > Bluez-devel@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/bluez-devel
> >
>
>
> --
> ---------------------------------------------------------
> Claudio Takahasi
> Instituto Nokia de Tecnologia - INdT
>
>
>
--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: timeout04.patch --]
[-- Type: text/x-patch; name="timeout04.patch", Size: 797 bytes --]
--- bluez-utils-cvs.orig/hcid/dbus.c 2006-02-17 11:31:06.000000000 -0200
+++ bluez-utils-cvs-timer/hcid/dbus.c 2006-02-17 12:43:34.000000000 -0200
@@ -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) {
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [Bluez-devel] [DBUS PATCH] scan mode timeout
2006-02-17 17:48 ` Claudio Takahasi
@ 2006-02-17 17:58 ` Marcel Holtmann
0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2006-02-17 17:58 UTC (permalink / raw)
To: bluez-devel
Hi Claudio,
> 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!
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
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-02-17 17:58 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-15 14:11 [Bluez-devel] [DBUS PATCH] scan mode timeout Claudio Takahasi
2006-02-15 14:20 ` Marcel Holtmann
2006-02-15 16:31 ` Claudio Takahasi
2006-02-15 17:18 ` Claudio Takahasi
2006-02-15 17:46 ` Marcel Holtmann
2006-02-16 18:41 ` Claudio Takahasi
2006-02-17 17:48 ` Claudio Takahasi
2006-02-17 17:58 ` Marcel Holtmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).