summaryrefslogtreecommitdiffstats
path: root/hcid/main.c
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2006-08-22 13:26:49 +0000
committerJohan Hedberg <johan.hedberg@nokia.com>2006-08-22 13:26:49 +0000
commitca6e6c5a32dda535b9f76f9b0f8433f71f977efa (patch)
tree92274f035893c55964255567da63a36c7ebd1629 /hcid/main.c
parent19d00ec64821c58447e1bb1110cadb2b0d43092c (diff)
fix adding and setting up devices
Diffstat (limited to 'hcid/main.c')
-rw-r--r--hcid/main.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/hcid/main.c b/hcid/main.c
index be71c3ad..b15634fe 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -276,6 +276,8 @@ static void configure_device(int hdev)
if (hci_test_bit(HCI_RAW, &di.flags))
exit(0);
+ memset(&dr, 0, sizeof(dr));
+
dr.dev_id = hdev;
device_opts = get_device_opts(s, hdev);
@@ -447,6 +449,24 @@ static void init_device(int hdev)
exit(0);
}
+static void device_devreg_setup(int dev_id)
+{
+ if (hcid.auto_init)
+ init_device(dev_id);
+ hcid_dbus_register_device(dev_id);
+}
+
+static void device_devup_setup(int dev_id)
+{
+ add_device(dev_id);
+ if (hcid.auto_init)
+ configure_device(dev_id);
+ if (hcid.security)
+ start_security_manager(dev_id);
+ start_device(dev_id);
+ hcid_dbus_start_device(dev_id);
+}
+
static void init_all_devices(int ctl)
{
struct hci_dev_list_req *dl;
@@ -471,21 +491,12 @@ static void init_all_devices(int ctl)
}
for (i = 0; i < dl->dev_num; i++, dr++) {
- if (hcid.auto_init)
- init_device(dr->dev_id);
-
- add_device(dr->dev_id);
-
- if (hcid.auto_init && hci_test_bit(HCI_UP, &dr->dev_opt))
- configure_device(dr->dev_id);
-
- if (hcid.security && hci_test_bit(HCI_UP, &dr->dev_opt))
- start_security_manager(dr->dev_id);
-
- start_device(dr->dev_id);
-
- hcid_dbus_register_device(dr->dev_id);
- hcid_dbus_start_device(dr->dev_id);
+ info("HCI dev %d registered", dr->dev_id);
+ device_devreg_setup(dr->dev_id);
+ if (hci_test_bit(HCI_UP, &dr->dev_opt)) {
+ info("HCI dev %d already up", dr->dev_id);
+ device_devup_setup(dr->dev_id);
+ }
}
free(dl);
@@ -525,10 +536,7 @@ static inline void device_event(GIOChannel *chan, evt_stack_internal *si)
switch (sd->event) {
case HCI_DEV_REG:
info("HCI dev %d registered", sd->dev_id);
- if (hcid.auto_init)
- init_device(sd->dev_id);
- add_device(sd->dev_id);
- hcid_dbus_register_device(sd->dev_id);
+ device_devreg_setup(sd->dev_id);
break;
case HCI_DEV_UNREG:
@@ -539,12 +547,7 @@ static inline void device_event(GIOChannel *chan, evt_stack_internal *si)
case HCI_DEV_UP:
info("HCI dev %d up", sd->dev_id);
- if (hcid.auto_init)
- configure_device(sd->dev_id);
- if (hcid.security)
- start_security_manager(sd->dev_id);
- start_device(sd->dev_id);
- hcid_dbus_start_device(sd->dev_id);
+ device_devup_setup(sd->dev_id);
break;
case HCI_DEV_DOWN:
@@ -712,13 +715,13 @@ int main(int argc, char *argv[])
/* Create event loop */
event_loop = g_main_new(FALSE);
- /* Initialize already connected devices */
- init_all_devices(hcid.sock);
-
ctl_io = g_io_channel_unix_new(hcid.sock);
g_io_add_watch(ctl_io, G_IO_IN, io_stack_event, NULL);
+ /* Initialize already connected devices */
+ init_all_devices(hcid.sock);
+
if (sdp)
start_sdp_server();