diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-08-18 18:29:40 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-08-18 18:29:40 +0000 |
commit | 3dec6f11d625a351bae0aada4160f3d2de429cdd (patch) | |
tree | d77a073813bf7f34fc18dcaea812f94cd46d41e1 | |
parent | 58887f9452b222cfb28bf8c5c11d13bd5de95efb (diff) |
Fixed SetMode when the adapter is DOWN
-rw-r--r-- | hcid/dbus-adapter.c | 68 | ||||
-rw-r--r-- | hcid/dbus-rfcomm.c | 4 | ||||
-rw-r--r-- | hcid/dbus-sdp.c | 4 | ||||
-rw-r--r-- | hcid/dbus.c | 1 | ||||
-rw-r--r-- | hcid/device.c | 2 |
5 files changed, 71 insertions, 8 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index 4b1b0a63..3c4ce652 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -406,6 +406,26 @@ static DBusHandlerResult handle_dev_set_mode_req(DBusConnection *conn, DBusMessa if (dd < 0) return error_no_such_adapter(conn, msg); + if (!dbus_data->up) { + bdaddr_t local; + + str2ba(dbus_data->address, &local); + /* The new value will be loaded when the adapter comes UP */ + write_device_mode(&local, scan_mode); + + /* Start HCI device */ + if (ioctl(dd, HCIDEVUP, dbus_data->dev_id) == 0) + goto done; /* on success */ + + if (errno != EALREADY) { + error("Can't init device hci%d: %s (%d)\n", + dbus_data->dev_id, strerror(errno), errno); + + hci_close_dev(dd); + return error_failed(conn, msg, errno); + } + } + /* Check if the new requested mode is different from the current */ if (current_mode != hci_mode) { struct hci_request rq; @@ -433,6 +453,7 @@ static DBusHandlerResult handle_dev_set_mode_req(DBusConnection *conn, DBusMessa } } +done: hci_close_dev(dd); reply = dbus_message_new_method_return(msg); @@ -468,6 +489,9 @@ static DBusHandlerResult handle_dev_set_discoverable_to_req(DBusConnection *conn uint32_t timeout; bdaddr_t bdaddr; + if (!dbus_data->up) + return error_not_ready(conn, msg); + dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_UINT32, &timeout, @@ -654,6 +678,9 @@ static DBusHandlerResult handle_dev_list_minor_classes_req(DBusConnection *conn, uint8_t major_class; int dd, size, i; + if (!dbus_data->up) + return error_not_ready(conn, msg); + if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); @@ -709,6 +736,9 @@ static DBusHandlerResult handle_dev_get_minor_class_req(DBusConnection *conn, DB uint8_t minor_class; int dd; + if (!dbus_data->up) + return error_not_ready(conn, msg); + if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); @@ -759,6 +789,9 @@ static DBusHandlerResult handle_dev_set_minor_class_req(DBusConnection *conn, DB uint32_t dev_class = 0xFFFFFFFF; int i, dd; + if (!dbus_data->up) + return error_not_ready(conn, msg); + dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &minor, @@ -841,6 +874,9 @@ static DBusHandlerResult handle_dev_get_service_classes_req(DBusConnection *conn uint8_t cls[3]; int dd, i; + if (!dbus_data->up) + return error_not_ready(conn, msg); + if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); @@ -916,6 +952,9 @@ static DBusHandlerResult handle_dev_set_name_req(DBusConnection *conn, DBusMessa char *str_ptr; int ecode; + if (!dbus_data->up) + return error_not_ready(conn, msg); + dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &str_ptr, @@ -1342,6 +1381,9 @@ static DBusHandlerResult handle_dev_get_remote_name_req(DBusConnection *conn, DB return send_reply_and_unref(conn, reply); } + if (!dbus_data->up) + return error_not_ready(conn, msg); + /* put the request name in the queue to resolve name */ str2ba(peer_addr, &peer_bdaddr); disc_device_append(&dbus_data->disc_devices, &peer_bdaddr, NAME_PENDING, RESOLVE_NAME); @@ -1605,6 +1647,9 @@ static DBusHandlerResult handle_dev_disconnect_remote_device_req(DBusConnection int dd; struct active_conn_info *dev; + if (!dbus_data->up) + return error_not_ready(conn, msg); + dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &peer_addr, @@ -1663,6 +1708,9 @@ static DBusHandlerResult handle_dev_create_bonding_req(DBusConnection *conn, DBu bdaddr_t peer_bdaddr; int dd, disconnect; + if (!dbus_data->up) + return error_not_ready(conn, msg); + dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &peer_addr, @@ -1779,6 +1827,9 @@ static DBusHandlerResult handle_dev_cancel_bonding_req(DBusConnection *conn, DBu const char *peer_addr; int dd = -1; + if (!dbus_data->up) + return error_not_ready(conn, msg); + dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &peer_addr, @@ -1882,6 +1933,9 @@ static DBusHandlerResult handle_dev_remove_bonding_req(DBusConnection *conn, DBu bdaddr_t bdaddr; int dd; + if (!dbus_data->up) + return error_not_ready(conn, msg); + dbus_error_init(&err); dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &addr_ptr, @@ -2119,6 +2173,9 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D uint32_t lap = 0x9e8b33; int dd; + if (!dbus_data->up) + return error_not_ready(conn, msg); + if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); @@ -2187,6 +2244,9 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D uint8_t status = 0x00; int dd = -1; + if (!dbus_data->up) + return error_not_ready(conn, msg); + if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return error_invalid_arguments(conn, msg); @@ -2382,7 +2442,6 @@ 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); @@ -2391,12 +2450,7 @@ DBusHandlerResult msg_func_device(DBusConnection *conn, DBusMessage *msg, void * if (!strcmp(DBUS_INTERFACE_INTROSPECTABLE, iface) && !strcmp("Introspect", name)) { return simple_introspect(conn, msg, data); - } - - if (!pdata->up) - return error_not_ready(conn, msg); - else - if (!strcmp(ADAPTER_INTERFACE, iface)) { + } else if (!strcmp(ADAPTER_INTERFACE, iface)) { service_handler_func_t handler; handler = find_service_handler(dev_services, msg); diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c index a7d7cbc1..f5c5708a 100644 --- a/hcid/dbus-rfcomm.c +++ b/hcid/dbus-rfcomm.c @@ -700,6 +700,7 @@ static struct service_data rfcomm_services[] = { DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, void *data) { + const struct hci_dbus_data *pdata = data; service_handler_func_t handler; if (!hcid_dbus_use_experimental()) @@ -710,6 +711,9 @@ DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; } + if (!pdata->up) + return error_not_ready(conn, msg); + /* Initialize the RFCOMM control socket if has not yet been done */ if (rfcomm_ctl < 0) { rfcomm_ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM); diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c index fe3ad04a..edf220a9 100644 --- a/hcid/dbus-sdp.c +++ b/hcid/dbus-sdp.c @@ -1111,11 +1111,15 @@ static struct service_data sdp_services[] = { DBusHandlerResult handle_sdp_method(DBusConnection *conn, DBusMessage *msg, void *data) { + const struct hci_dbus_data *pdata = data; service_handler_func_t handler; if (!hcid_dbus_use_experimental()) return error_unknown_method(conn, msg); + if (!pdata->up) + return error_not_ready(conn, msg); + handler = find_service_handler(sdp_services, msg); if (handler) diff --git a/hcid/dbus.c b/hcid/dbus.c index 9ef99428..5288290a 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -665,6 +665,7 @@ int hcid_dbus_stop_device(uint16_t id) pdata->up = 0; pdata->discover_state = STATE_IDLE; + pdata->mode = SCAN_DISABLED; return 0; } diff --git a/hcid/device.c b/hcid/device.c index a9ea8fc6..5c3518dd 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -432,7 +432,7 @@ int set_device_name(uint16_t dev_id, const char *name) } if (hci_write_local_name(dd, name, 5000) < 0) { - error("Can't read name for hci%d: %s (%d)", + error("Can't write name for hci%d: %s (%d)", dev_id, strerror(errno), errno); return -errno; } |