diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-08-15 14:55:55 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-08-15 14:55:55 +0000 |
commit | a23442be507d9384175898a28fb72c35f790fbd1 (patch) | |
tree | 3dd4230b91278f28cba1a69fe23ce663c15e462b | |
parent | af123a9010de988e3dc9b2f2a67f3a140e309c3f (diff) |
load/set the default options after HCI_DEV_UP
-rw-r--r-- | hcid/dbus-adapter.c | 8 | ||||
-rw-r--r-- | hcid/dbus-error.c | 6 | ||||
-rw-r--r-- | hcid/dbus.c | 143 | ||||
-rw-r--r-- | hcid/dbus.h | 2 | ||||
-rw-r--r-- | hcid/hcid.h | 2 | ||||
-rw-r--r-- | hcid/main.c | 7 |
6 files changed, 102 insertions, 66 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index bec28be2..02cc85c9 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -2382,6 +2382,7 @@ static struct service_data dev_services[] = { DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void *data) { + const struct hci_dbus_data *pdata = data; const char *iface, *name; iface = dbus_message_get_interface(msg); @@ -2390,7 +2391,12 @@ DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void * if (!strcmp(DBUS_INTERFACE_INTROSPECTABLE, iface) && !strcmp("Introspect", name)) { return simple_introspect(conn, msg, data); - } else if (!strcmp(ADAPTER_INTERFACE, iface)) { + } + + if (!pdata->up) + return error_not_ready(conn, msg); + else + if (!strcmp(ADAPTER_INTERFACE, iface)) { service_handler_func_t handler; handler = find_service_handler(dev_services, msg); diff --git a/hcid/dbus-error.c b/hcid/dbus-error.c index 8b75efeb..079cedf6 100644 --- a/hcid/dbus-error.c +++ b/hcid/dbus-error.c @@ -41,6 +41,12 @@ DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err) dbus_message_new_error(msg, ERROR_INTERFACE ".Failed", str)); } +DBusHandlerResult error_not_ready(DBusConnection *conn, DBusMessage *msg) +{ + return send_reply_and_unref(conn, + dbus_message_new_error(msg, ERROR_INTERFACE ".NotReady", "Adapter is not ready")); +} + DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg) { return send_reply_and_unref(conn, diff --git a/hcid/dbus.c b/hcid/dbus.c index 3a6c8e53..9fd5e3b6 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -361,9 +361,6 @@ static int register_dbus_path(const char *path, uint16_t dev_id, memset(data, 0, sizeof(struct hci_dbus_data)); data->dev_id = dev_id; - data->mode = SCAN_DISABLED; - data->discoverable_timeout = get_discoverable_timeout(dev_id); - data->discover_type = WITHOUT_NAME_RESOLVING; /* default discover type */ if (fallback) { if (!dbus_connection_register_fallback(connection, path, pvtable, data)) { @@ -432,6 +429,74 @@ int hcid_dbus_register_device(uint16_t id) char path[MAX_PATH_LENGTH]; char *pptr = path; DBusMessage *message = NULL; + + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); + + if (register_dbus_path(path, id, &obj_dev_vtable, FALSE) < 0) + return -1; + + /* + * Send the adapter added signal + */ + message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, + "AdapterAdded"); + if (message == NULL) { + error("Can't allocate D-Bus message"); + dbus_connection_unregister_object_path(connection, path); + return -1; + } + + dbus_message_append_args(message, + DBUS_TYPE_STRING, &pptr, + DBUS_TYPE_INVALID); + + send_reply_and_unref(connection, message); + + return 0; +} + +int hcid_dbus_unregister_device(uint16_t id) +{ + DBusMessage *message; + char path[MAX_PATH_LENGTH]; + char *pptr = path; + int ret; + + snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); + + message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, + "AdapterRemoved"); + if (message == NULL) { + error("Can't allocate D-Bus message"); + goto failed; + } + + dbus_message_append_args(message, + DBUS_TYPE_STRING, &pptr, + DBUS_TYPE_INVALID); + + if (!dbus_connection_send(connection, message, NULL)) { + error("Can't send D-Bus added device message"); + goto failed; + } + + dbus_connection_flush(connection); + +failed: + if (message) + dbus_message_unref(message); + + ret = unregister_dbus_path(path); + + if (ret == 0 && default_dev == id) + default_dev = hci_get_route(NULL); + + return ret; +} + +int hcid_dbus_start_device(uint16_t id) +{ + char path[MAX_PATH_LENGTH]; int i, err, dd = -1, ret = -1; read_scan_enable_rp rp; struct hci_dev_info di; @@ -441,9 +506,8 @@ int hcid_dbus_register_device(uint16_t id) struct hci_conn_info *ci; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (register_dbus_path(path, id, &obj_dev_vtable, FALSE) < 0) - return -1; + /* FIXME: check dupplicated code - configure_device() */ if (hci_devinfo(id, &di) < 0) { error("Getting device info failed: hci%d", id); return -1; @@ -480,6 +544,9 @@ int hcid_dbus_register_device(uint16_t id) } pdata->mode = rp.enable; /* Keep the current scan status */ + pdata->up = 1; + pdata->discoverable_timeout = get_discoverable_timeout(id); + pdata->discover_type = WITHOUT_NAME_RESOLVING; /* default discover type */ /* * Get the adapter Bluetooth address @@ -488,28 +555,6 @@ int hcid_dbus_register_device(uint16_t id) if (err < 0) goto failed; - /* - * Send the adapter added signal - */ - message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, - "AdapterAdded"); - if (message == NULL) { - error("Can't allocate D-Bus message"); - goto failed; - } - - /*FIXME: append a friendly name instead of device path */ - dbus_message_append_args(message, - DBUS_TYPE_STRING, &pptr, - DBUS_TYPE_INVALID); - - if (!dbus_connection_send(connection, message, NULL)) { - error("Can't send D-BUS adapter added message"); - goto failed; - } - - dbus_connection_flush(connection); - /* * retrieve the active connections: address the scenario where * the are active connections before the daemon've started @@ -535,12 +580,6 @@ int hcid_dbus_register_device(uint16_t id) ret = 0; failed: - if (ret < 0) - dbus_connection_unregister_object_path(connection, path); - - if (message) - dbus_message_unref(message); - if (ret == 0 && default_dev < 0) default_dev = id; @@ -553,46 +592,24 @@ failed: return ret; } -int hcid_dbus_unregister_device(uint16_t id) +int hcid_dbus_stop_device(uint16_t id) { - DBusMessage *message; char path[MAX_PATH_LENGTH]; - char *pptr = path; - int ret; + struct hci_dbus_data* pdata; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - message = dbus_message_new_signal(BASE_PATH, MANAGER_INTERFACE, - "AdapterRemoved"); - if (message == NULL) { - error("Can't allocate D-Bus message"); - goto failed; - } - - /*FIXME: append a friendly name instead of device path */ - dbus_message_append_args(message, - DBUS_TYPE_STRING, &pptr, - DBUS_TYPE_INVALID); - - if (!dbus_connection_send(connection, message, NULL)) { - error("Can't send D-Bus added device message"); - goto failed; + if (!dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { + error("Getting %s path data failed!", path); + return -1; } - dbus_connection_flush(connection); - -failed: - if (message) - dbus_message_unref(message); - - ret = unregister_dbus_path(path); - - if (ret == 0 && default_dev == id) - default_dev = hci_get_route(NULL); + pdata->up = 0; - return ret; + return 0; } + int pending_bonding_cmp(const void *p1, const void *p2) { const bdaddr_t *peer1 = p1; diff --git a/hcid/dbus.h b/hcid/dbus.h index 5c775871..4052b9c8 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -97,6 +97,7 @@ struct active_conn_info { struct hci_dbus_data { uint16_t dev_id; + int up; char address[18]; /* adapter Bluetooth Address */ uint32_t timeout_id; /* discoverable timeout id */ uint32_t discoverable_timeout; /* discoverable time(msec) */ @@ -134,6 +135,7 @@ DBusMessage *dev_signal_factory(const int devid, const char *prop_name, const in int get_default_dev_id(void); DBusHandlerResult error_failed(DBusConnection *conn, DBusMessage *msg, int err); +DBusHandlerResult error_not_ready(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_invalid_arguments(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_unknown_method(DBusConnection *conn, DBusMessage *msg); DBusHandlerResult error_not_authorized(DBusConnection *conn, DBusMessage *msg); diff --git a/hcid/hcid.h b/hcid/hcid.h index 6f5b493e..76c80906 100644 --- a/hcid/hcid.h +++ b/hcid/hcid.h @@ -146,6 +146,8 @@ void hcid_dbus_set_experimental(); int hcid_dbus_use_experimental(); int hcid_dbus_register_device(uint16_t id); int hcid_dbus_unregister_device(uint16_t id); +int hcid_dbus_start_device(uint16_t id); +int hcid_dbus_stop_device(uint16_t id); void hcid_dbus_pending_bonding_add(bdaddr_t *sba, bdaddr_t *dba); void hcid_dbus_request_pin(int dev, bdaddr_t *sba, struct hci_conn_info *ci); diff --git a/hcid/main.c b/hcid/main.c index 6f96343e..3aea1a89 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -490,6 +490,7 @@ static void init_all_devices(int ctl) start_device(dr->dev_id); hcid_dbus_register_device(dr->dev_id); + hcid_dbus_start_device(dr->dev_id); } free(dl); @@ -532,10 +533,12 @@ static inline void device_event(GIOChannel *chan, evt_stack_internal *si) if (hcid.auto_init) init_device(sd->dev_id); add_device(sd->dev_id); + hcid_dbus_register_device(sd->dev_id); break; case HCI_DEV_UNREG: info("HCI dev %d unregistered", sd->dev_id); + hcid_dbus_unregister_device(sd->dev_id); remove_device(sd->dev_id); break; @@ -546,12 +549,12 @@ static inline void device_event(GIOChannel *chan, evt_stack_internal *si) if (hcid.security) start_security_manager(sd->dev_id); start_device(sd->dev_id); - hcid_dbus_register_device(sd->dev_id); + hcid_dbus_start_device(sd->dev_id); break; case HCI_DEV_DOWN: info("HCI dev %d down", sd->dev_id); - hcid_dbus_unregister_device(sd->dev_id); + hcid_dbus_stop_device(sd->dev_id); if (hcid.security) stop_security_manager(sd->dev_id); stop_device(sd->dev_id); |