summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@nokia.com>2008-09-23 23:22:31 -0700
committerJohan Hedberg <johan.hedberg@nokia.com>2008-09-23 23:22:31 -0700
commitee33a0705e529b66d9e8fc85381bc2efa0e43457 (patch)
treea9828b69b5b52df7cbabba04647a648105457f00 /src
parent175702e7b18701999d34e9fd3067098dbd6fa0f0 (diff)
Use a common timeout for hci commands
Diffstat (limited to 'src')
-rw-r--r--src/adapter.c42
-rw-r--r--src/dbus-hci.c25
-rw-r--r--src/hcid.h3
3 files changed, 39 insertions, 31 deletions
diff --git a/src/adapter.c b/src/adapter.c
index 94171eb7..0f21f2a1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -353,7 +353,8 @@ int pending_remote_name_cancel(struct btd_adapter *adapter)
dev = l->data;
- if (hci_read_remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) {
+ if (hci_read_remote_name_cancel(dd, &dev->bdaddr,
+ HCI_REQ_TIMEOUT) < 0) {
error("Remote name cancel failed: %s(%d)", strerror(errno), errno);
err = -errno;
}
@@ -560,7 +561,7 @@ static DBusMessage *set_mode(DBusConnection *conn, DBusMessage *msg,
rq.rlen = sizeof(status);
rq.event = EVT_CMD_COMPLETE;
- if (hci_send_req(dd, &rq, 1000) < 0) {
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Sending write scan enable command failed: %s (%d)",
strerror(errno), errno);
@@ -839,7 +840,8 @@ static void update_ext_inquiry_response(int dd, struct hci_dev *dev)
if (dev->ssp_mode > 0)
create_ext_inquiry_response((char *) dev->name, data);
- if (hci_write_ext_inquiry_response(dd, fec, data, 2000) < 0)
+ if (hci_write_ext_inquiry_response(dd, fec, data,
+ HCI_REQ_TIMEOUT) < 0)
error("Can't write extended inquiry response: %s (%d)",
strerror(errno), errno);
}
@@ -862,7 +864,7 @@ static int adapter_set_name(struct btd_adapter *adapter, const char *name)
return -err;
}
- if (hci_write_local_name(dd, name, 5000) < 0) {
+ if (hci_write_local_name(dd, name, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't write name for hci%d: %s (%d)",
adapter->dev_id, strerror(err), err);
@@ -998,7 +1000,7 @@ static DBusMessage *remove_bonding(DBusConnection *conn, DBusMessage *msg,
}
/* Delete the link key from the Bluetooth chip */
- hci_delete_stored_link_key(dev, &dst, 0, 1000);
+ hci_delete_stored_link_key(dev, &dst, 0, HCI_REQ_TIMEOUT);
/* find the connection */
l = g_slist_find_custom(adapter->active_conn, &dst,
@@ -1007,7 +1009,8 @@ static DBusMessage *remove_bonding(DBusConnection *conn, DBusMessage *msg,
struct active_conn_info *con = l->data;
/* Send the HCI disconnect command */
if ((hci_disconnect(dev, htobs(con->handle),
- HCI_OE_USER_ENDED_CONNECTION, 500) < 0)
+ HCI_OE_USER_ENDED_CONNECTION,
+ HCI_REQ_TIMEOUT) < 0)
&& msg){
int err = errno;
error("Disconnect failed");
@@ -1199,7 +1202,7 @@ static gboolean create_bonding_conn_complete(GIOChannel *io, GIOCondition cond,
rq.rlen = EVT_CMD_STATUS_SIZE;
rq.event = EVT_CMD_STATUS;
- if (hci_send_req(dd, &rq, 500) < 0) {
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
error("Unable to send HCI request: %s (%d)",
strerror(errno), errno);
error_failed_errno(adapter->bonding->conn, adapter->bonding->msg,
@@ -1396,7 +1399,7 @@ int start_inquiry(struct btd_adapter *adapter)
rq.rlen = EVT_CMD_STATUS_SIZE;
rq.event = EVT_CMD_STATUS;
- if (hci_send_req(dd, &rq, 500) < 0) {
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Unable to start inquiry: %s (%d)",
strerror(err), err);
@@ -1447,7 +1450,7 @@ static int start_periodic_inquiry(struct btd_adapter *adapter)
rq.rlen = sizeof(status);
rq.event = EVT_CMD_COMPLETE;
- if (hci_send_req(dd, &rq, 1000) < 0) {
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Unable to start periodic inquiry: %s (%d)",
strerror(err), err);
@@ -2125,7 +2128,7 @@ static int adapter_read_bdaddr(uint16_t dev_id, bdaddr_t *bdaddr)
return -err;
}
- if (hci_read_bd_addr(dd, bdaddr, 2000) < 0) {
+ if (hci_read_bd_addr(dd, bdaddr, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't read address for hci%d: %s (%d)",
dev_id, strerror(err), err);
@@ -2180,7 +2183,7 @@ static int adapter_setup(struct btd_adapter *adapter, int dd)
if (read_local_name(&adapter->bdaddr, name) == 0) {
memcpy(dev->name, name, 248);
- hci_write_local_name(dd, name, 5000);
+ hci_write_local_name(dd, name, HCI_REQ_TIMEOUT);
}
update_ext_inquiry_response(dd, dev);
@@ -2189,7 +2192,7 @@ static int adapter_setup(struct btd_adapter *adapter, int dd)
if (inqmode < 1)
return 0;
- if (hci_write_inquiry_mode(dd, inqmode, 2000) < 0) {
+ if (hci_write_inquiry_mode(dd, inqmode, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't write inquiry mode for %s: %s (%d)",
adapter->path, strerror(err), err);
@@ -2439,7 +2442,7 @@ int adapter_start(struct btd_adapter *adapter)
return -err;
}
- if (hci_read_local_version(dd, &ver, 1000) < 0) {
+ if (hci_read_local_version(dd, &ver, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't read version info for %s: %s (%d)",
adapter->path, strerror(err), err);
@@ -2452,7 +2455,7 @@ int adapter_start(struct btd_adapter *adapter)
dev->lmp_subver = ver.lmp_subver;
dev->manufacturer = ver.manufacturer;
- if (hci_read_local_features(dd, features, 1000) < 0) {
+ if (hci_read_local_features(dd, features, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't read features for %s: %s (%d)",
adapter->path, strerror(err), err);
@@ -2462,7 +2465,7 @@ int adapter_start(struct btd_adapter *adapter)
memcpy(dev->features, features, 8);
- if (hci_read_class_of_dev(dd, dev->class, 1000) < 0) {
+ if (hci_read_class_of_dev(dd, dev->class, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't read class of adapter on %s: %s (%d)",
adapter->path, strerror(err), err);
@@ -2470,7 +2473,7 @@ int adapter_start(struct btd_adapter *adapter)
return -err;
}
- if (hci_read_local_name(dd, sizeof(name), name, 2000) < 0) {
+ if (hci_read_local_name(dd, sizeof(name), name, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't read local name on %s: %s (%d)",
adapter->path, strerror(err), err);
@@ -2484,9 +2487,10 @@ int adapter_start(struct btd_adapter *adapter)
goto setup;
if (ioctl(dd, HCIGETAUTHINFO, NULL) < 0 && errno != EINVAL)
- hci_write_simple_pairing_mode(dd, 0x01, 2000);
+ hci_write_simple_pairing_mode(dd, 0x01, HCI_REQ_TIMEOUT);
- if (hci_read_simple_pairing_mode(dd, &dev->ssp_mode, 1000) < 0) {
+ if (hci_read_simple_pairing_mode(dd, &dev->ssp_mode,
+ HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't read simple pairing mode on %s: %s (%d)",
adapter->path, strerror(err), err);
@@ -2797,7 +2801,7 @@ static gboolean discov_timeout_handler(void *data)
rq.rlen = sizeof(status);
rq.event = EVT_CMD_COMPLETE;
- if (hci_send_req(dd, &rq, 1000) < 0) {
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
error("Sending write scan enable command to hci%d failed: %s (%d)",
dev_id, strerror(errno), errno);
goto failed;
diff --git a/src/dbus-hci.c b/src/dbus-hci.c
index 44700127..007f0936 100644
--- a/src/dbus-hci.c
+++ b/src/dbus-hci.c
@@ -656,7 +656,7 @@ static int found_device_req_name(struct btd_adapter *adapter)
bacpy(&cp.bdaddr, &dev->bdaddr);
cp.pscan_rep_mode = 0x02;
- if (hci_send_req(dd, &rq, 500) < 0)
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0)
error("Unable to send the HCI remote name request: %s (%d)",
strerror(errno), errno);
@@ -1160,7 +1160,7 @@ int set_limited_discoverable(int dd, const uint8_t *cls, gboolean limited)
* 1: giac
* 2: giac + liac
*/
- if (hci_write_current_iac_lap(dd, num, lap, 1000) < 0) {
+ if (hci_write_current_iac_lap(dd, num, lap, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't write current IAC LAP: %s(%d)",
strerror(err), err);
@@ -1179,7 +1179,7 @@ int set_limited_discoverable(int dd, const uint8_t *cls, gboolean limited)
dev_class = (cls[2] << 16) | ((cls[1] & 0xdf) << 8) | cls[0];
}
- if (hci_write_class_of_dev(dd, dev_class, 1000) < 0) {
+ if (hci_write_class_of_dev(dd, dev_class, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't write class of device: %s (%d)",
strerror(err), err);
@@ -1199,7 +1199,7 @@ int set_service_classes(int dd, const uint8_t *cls, uint8_t value)
dev_class = (value << 16) | (cls[1] << 8) | cls[0];
- if (hci_write_class_of_dev(dd, dev_class, 1000) < 0) {
+ if (hci_write_class_of_dev(dd, dev_class, HCI_REQ_TIMEOUT) < 0) {
err = errno;
error("Can't write class of device: %s (%d)",
strerror(err), err);
@@ -1239,7 +1239,7 @@ void hcid_dbus_setname_complete(bdaddr_t *local)
rq.rlen = READ_LOCAL_NAME_RP_SIZE;
rq.event = EVT_CMD_COMPLETE;
- if (hci_send_req(dd, &rq, 1000) < 0) {
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
error("Sending getting name command failed: %s (%d)",
strerror(errno), errno);
rp.name[0] = '\0';
@@ -1285,7 +1285,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local)
rq.rlen = READ_SCAN_ENABLE_RP_SIZE;
rq.event = EVT_CMD_COMPLETE;
- if (hci_send_req(dd, &rq, 1000) < 0) {
+ if (hci_send_req(dd, &rq, HCI_REQ_TIMEOUT) < 0) {
error("Sending read scan enable command failed: %s (%d)",
strerror(errno), errno);
goto failed;
@@ -1328,7 +1328,7 @@ void hcid_dbus_write_class_complete(bdaddr_t *local)
return;
}
- if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
+ if (hci_read_class_of_dev(dd, cls, HCI_REQ_TIMEOUT) < 0) {
error("Can't read class of device on hci%d: %s (%d)",
dev_id, strerror(errno), errno);
hci_close_dev(dd);
@@ -1364,7 +1364,8 @@ void hcid_dbus_write_simple_pairing_mode_complete(bdaddr_t *local)
return;
}
- if (hci_read_simple_pairing_mode(dd, &mode, 1000) < 0) {
+ if (hci_read_simple_pairing_mode(dd, &mode,
+ HCI_REQ_TIMEOUT) < 0) {
error("Can't read class of adapter on %s: %s(%d)",
path, strerror(errno), errno);
hci_close_dev(dd);
@@ -1533,13 +1534,13 @@ int cancel_discovery(struct btd_adapter *adapter)
dev = adapter_search_found_devices(adapter, &match);
if (dev) {
- if (remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) {
+ if (remote_name_cancel(dd, &dev->bdaddr, HCI_REQ_TIMEOUT) < 0) {
error("Read remote name cancel failed: %s, (%d)",
strerror(errno), errno);
err = -errno;
}
} else {
- if (inquiry_cancel(dd, 1000) < 0) {
+ if (inquiry_cancel(dd, HCI_REQ_TIMEOUT) < 0) {
error("Inquiry cancel failed:%s (%d)",
strerror(errno), errno);
err = -errno;
@@ -1591,7 +1592,7 @@ int cancel_periodic_discovery(struct btd_adapter *adapter)
dev = adapter_search_found_devices(adapter, &match);
if (dev) {
- if (remote_name_cancel(dd, &dev->bdaddr, 1000) < 0) {
+ if (remote_name_cancel(dd, &dev->bdaddr, HCI_REQ_TIMEOUT) < 0) {
error("Read remote name cancel failed: %s, (%d)",
strerror(errno), errno);
err = -errno;
@@ -1600,7 +1601,7 @@ int cancel_periodic_discovery(struct btd_adapter *adapter)
/* ovewrite err if necessary: stop periodic inquiry has higher
* priority */
- if (periodic_inquiry_exit(dd, 1000) < 0) {
+ if (periodic_inquiry_exit(dd, HCI_REQ_TIMEOUT) < 0) {
error("Periodic Inquiry exit failed:%s (%d)",
strerror(errno), errno);
err = -errno;
diff --git a/src/hcid.h b/src/hcid.h
index 687481c3..fc8b446f 100644
--- a/src/hcid.h
+++ b/src/hcid.h
@@ -45,6 +45,9 @@
#define HCID_OFFMODE_DEVDOWN 0
#define HCID_OFFMODE_NOSCAN 1
+/* Timeout for hci_send_req (milliseconds) */
+#define HCI_REQ_TIMEOUT 5000
+
struct main_opts {
char host_name[40];
unsigned long flags;