diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-03-14 18:53:37 +0000 |
---|---|---|
committer | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2006-03-14 18:53:37 +0000 |
commit | 15553064885d4ff312ebc4fe2fe3e39e85f94ef2 (patch) | |
tree | 978f0ca6f2dfdb64839ecb599391d1d6e6cbd9a6 /hcid | |
parent | 55dc9d47e12b483f6495ae6eaeeb2a7be2a2f02a (diff) |
Fixed cancel discovery: checking the discover state to cancel the inquiry or remote name request procedure
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-adapter.c | 41 | ||||
-rw-r--r-- | hcid/dbus.c | 18 | ||||
-rw-r--r-- | hcid/dbus.h | 9 |
3 files changed, 52 insertions, 16 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index 0aff95bf..d3a6e613 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -1179,9 +1179,9 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D method = dbus_message_get_member(msg); if (strcmp("DiscoverDevicesWithoutNameResolving", method) == 0) - dbus_data->resolve_name = 0; + dbus_data->discover_state = DISCOVER_RUNNING; else - dbus_data->resolve_name = 1; + dbus_data->discover_state = DISCOVER_RUNNING_WITH_NAMES; dd = hci_open_dev(dbus_data->dev_id); if (dd < 0) @@ -1206,6 +1206,7 @@ static DBusHandlerResult handle_dev_discover_devices_req(DBusConnection *conn, D if (hci_send_req(dd, &rq, 100) < 0) { error("Unable to start inquiry: %s (%d)", strerror(errno), errno); + dbus_data->discover_state = DISCOVER_OFF; hci_close_dev(dd); return error_failed(conn, msg, errno); } @@ -1224,9 +1225,11 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D { DBusMessage *reply = NULL; const char *requestor_name; + bdaddr_t *addr; struct hci_request rq; + remote_name_req_cancel_cp cp; struct hci_dbus_data *dbus_data = data; - uint8_t status; + uint8_t status = 0x00; int dd = -1; requestor_name = dbus_message_get_sender(msg); @@ -1244,14 +1247,38 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D return error_no_such_adapter(conn, msg); memset(&rq, 0, sizeof(rq)); + memset(&cp, 0, sizeof(cp)); rq.ogf = OGF_LINK_CTL; - rq.ocf = OCF_INQUIRY_CANCEL; rq.rparam = &status; rq.rlen = sizeof(status); + switch (dbus_data->discover_state) { + case DISCOVER_OFF: + /* FIXME: */ + break; + case RESOLVING_NAMES: + /* get the first element */ + addr = (bdaddr_t *) (dbus_data->discovered_devices)->data; + + memcpy(&cp.bdaddr, addr, sizeof(bdaddr_t)); + + rq.ocf = OCF_REMOTE_NAME_REQ_CANCEL; + rq.cparam = &cp; + rq.clen = REMOTE_NAME_REQ_CANCEL_CP_SIZE; + rq.event = EVT_CMD_STATUS; + break; + case DISCOVER_RUNNING: + case DISCOVER_RUNNING_WITH_NAMES: + rq.ocf = OCF_INQUIRY_CANCEL; + break; + } + + slist_free(dbus_data->discovered_devices); + dbus_data->discovered_devices = NULL; + if (hci_send_req(dd, &rq, 100) < 0) { - error("Sending cancel inquiry failed: %s (%d)", - strerror(errno), errno); + error("Sending command failed: %s (%d)", + strerror(errno), errno); hci_close_dev(dd); return error_failed(conn, msg, errno); } @@ -1259,7 +1286,7 @@ static DBusHandlerResult handle_dev_cancel_discovery_req(DBusConnection *conn, D hci_close_dev(dd); if (status) { - error("Cancel inquiry failed with status 0x%02x", status); + error("Cancel failed with status 0x%02x", status); return error_failed(conn, msg, status); } diff --git a/hcid/dbus.c b/hcid/dbus.c index 18ed1386..2b7ba72b 100644 --- a/hcid/dbus.c +++ b/hcid/dbus.c @@ -573,9 +573,15 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) snprintf(path, sizeof(path), "%s/hci%d", ADAPTER_PATH, id); if (dbus_connection_get_object_path_data(connection, path, (void *) &pdata)) { - if (pdata->resolve_name) + if (pdata->discover_state == DISCOVER_RUNNING_WITH_NAMES) { + /* start name resolving */ + pdata->discover_state = RESOLVING_NAMES; + if (!remote_name_resolve(pdata)) - goto failed; /* skip, send discovery complete after resolve all remote names */ + goto failed; /* skip, sending the first name to resolve */ + else + pdata->discover_state = DISCOVER_OFF; /* no names to resolve */ + } if (pdata->requestor_name) { free(pdata->requestor_name); @@ -704,12 +710,8 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, i goto failed; } - if (!pdata->resolve_name) - goto failed; /* skip - it is a normal request */ - else + if (pdata->discover_state == DISCOVER_RUNNING_WITH_NAMES) remote_name_add(&pdata->discovered_devices, peer); - - goto failed; } failed: @@ -803,7 +805,7 @@ request_next: free(pdata->requestor_name); pdata->requestor_name = NULL; - pdata->resolve_name = 0; + pdata->discover_state = DISCOVER_OFF; failed: if (message) diff --git a/hcid/dbus.h b/hcid/dbus.h index beb9accc..3be9741d 100644 --- a/hcid/dbus.h +++ b/hcid/dbus.h @@ -70,6 +70,13 @@ struct service_data { typedef int (timeout_handler_func_t) (void *data); +typedef enum { + DISCOVER_OFF, + DISCOVER_RUNNING, + DISCOVER_RUNNING_WITH_NAMES, + RESOLVING_NAMES +} discover_state_t; + struct hci_dbus_data { uint16_t dev_id; uint16_t path_id; @@ -77,7 +84,7 @@ struct hci_dbus_data { uint32_t timeout_hits; timeout_handler_func_t *timeout_handler; uint8_t mode; /* scan mode */ - int resolve_name; /* send name on discover process */ + discover_state_t discover_state; struct slist *discovered_devices; char *requestor_name; /* requestor unique name */ struct slist *passkey_agents; |