summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2006-03-03 13:52:46 +0000
committerMarcel Holtmann <marcel@holtmann.org>2006-03-03 13:52:46 +0000
commit219dbd9dd6ba0af8f351149f7f253264eb721d44 (patch)
treeb1405d25d1b5e6c7fa12e91e4571ae88e33a28d6
parente4897f4192a17338c89a8abea249648c66cce5aa (diff)
More error handling cleanup
-rw-r--r--hcid/dbus-adapter.c50
-rw-r--r--hcid/dbus.h22
2 files changed, 26 insertions, 46 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c
index 9d35ced4..e25d0252 100644
--- a/hcid/dbus-adapter.c
+++ b/hcid/dbus-adapter.c
@@ -63,17 +63,6 @@ static const char *computer_minor_cls[] = {
"wearable"
};
-static char *get_peer_name(const bdaddr_t *local, const bdaddr_t *peer)
-{
- char filename[PATH_MAX + 1], addr[18];
-
- ba2str(local, addr);
- snprintf(filename, PATH_MAX, "%s/%s/names", STORAGEDIR, addr);
-
- ba2str(peer, addr);
- return textfile_get(filename, addr);
-}
-
static DBusMessage *handle_dev_get_address_req(DBusMessage *msg, void *data)
{
struct hci_dbus_data *dbus_data = data;
@@ -463,10 +452,8 @@ static DBusMessage *handle_dev_set_minor_class_req(DBusMessage *msg, void *data)
return bluez_new_failure_msg(msg, BLUEZ_EDBUS_WRONG_PARAM);
dd = hci_open_dev(dbus_data->dev_id);
- if (dd < 0) {
- syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
- return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
- }
+ if (dd < 0)
+ return error_no_such_device(msg);
if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
syslog(LOG_ERR, "Can't read class of device on hci%d: %s(%d)",
@@ -520,10 +507,8 @@ static DBusMessage *handle_dev_get_service_classes_req(DBusMessage *msg, void *d
int dd, i;
dd = hci_open_dev(dbus_data->dev_id);
- if (dd < 0) {
- syslog(LOG_ERR, "HCI device open failed: hci%d", dbus_data->dev_id);
- return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
- }
+ if (dd < 0)
+ return error_no_such_device(msg);
if (hci_read_class_of_dev(dd, cls, 1000) < 0) {
syslog(LOG_ERR, "Can't read class of device on hci%d: %s(%d)",
@@ -689,24 +674,25 @@ done:
static DBusMessage *handle_dev_get_remote_name_req(DBusMessage *msg, void *data)
{
+ char filename[PATH_MAX + 1], addr[18];
struct hci_dbus_data *dbus_data = data;
DBusMessage *reply = NULL;
const char *str_bdaddr;
char *name;
- bdaddr_t bdaddr;
- struct hci_dev_info di;
+ int err;
dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &str_bdaddr,
DBUS_TYPE_INVALID);
- str2ba(str_bdaddr, &bdaddr);
+ err = get_device_address(dbus_data->dev_id, addr, sizeof(addr));
+ if (err < 0)
+ return error_generic(msg, -err);
- if (hci_devinfo(dbus_data->dev_id, &di) < 0) {
- syslog(LOG_ERR, "Can't get device info");
- return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
- }
- name = get_peer_name(&di.bdaddr, &bdaddr);
+ snprintf(filename, PATH_MAX, "%s/%s/names", STORAGEDIR, addr);
+
+ name = textfile_get(filename, str_bdaddr);
+
if (!name)
return bluez_new_failure_msg(msg, BLUEZ_EDBUS_RECORD_NOT_FOUND);
@@ -903,7 +889,7 @@ static DBusMessage *handle_dev_create_bonding_req(DBusMessage *msg, void *data)
cr->type = ACL_LINK;
if (ioctl(dd, HCIGETCONNINFO, (unsigned long) cr) < 0) {
- reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
goto done;
}
@@ -922,7 +908,7 @@ static DBusMessage *handle_dev_create_bonding_req(DBusMessage *msg, void *data)
if (hci_send_req(dd, &rq, 100) < 0) {
syslog(LOG_ERR, "Unable to send authentication request: %s (%d)",
strerror(errno), errno);
- reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
goto done;
}
@@ -1174,7 +1160,7 @@ static DBusMessage *handle_dev_discover_req(DBusMessage *msg, void *data)
if (hci_send_req(dd, &rq, 100) < 0) {
syslog(LOG_ERR, "Unable to start inquiry: %s (%d)",
strerror(errno), errno);
- reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
goto failed;
}
@@ -1207,13 +1193,13 @@ static DBusMessage *handle_dev_discover_cancel_req(DBusMessage *msg, void *data)
if (hci_send_req(dd, &rq, 100) < 0) {
syslog(LOG_ERR, "Sending cancel inquiry failed: %s (%d)",
strerror(errno), errno);
- reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
+ reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET | errno);
goto failed;
}
if (status) {
syslog(LOG_ERR, "Cancel inquiry failed with status 0x%02x", status);
- reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET + status);
+ reply = bluez_new_failure_msg(msg, BLUEZ_EBT_OFFSET | status);
goto failed;
}
diff --git a/hcid/dbus.h b/hcid/dbus.h
index 1e255e46..5bcc0f65 100644
--- a/hcid/dbus.h
+++ b/hcid/dbus.h
@@ -252,19 +252,13 @@ DBusMessage *error_no_such_device(DBusMessage *msg);
#define BLUEZ_EFUTURE_OFFSET (0x00040000)
/* D-Bus error code, class BLUEZ_EDBUS_OFFSET */
-#define BLUEZ_EDBUS_UNKNOWN_METHOD (0x01 + BLUEZ_EDBUS_OFFSET)
-#define BLUEZ_EDBUS_WRONG_SIGNATURE (0x02 + BLUEZ_EDBUS_OFFSET)
-#define BLUEZ_EDBUS_WRONG_PARAM (0x03 + BLUEZ_EDBUS_OFFSET)
-#define BLUEZ_EDBUS_RECORD_NOT_FOUND (0x04 + BLUEZ_EDBUS_OFFSET)
-#define BLUEZ_EDBUS_NO_MEM (0x05 + BLUEZ_EDBUS_OFFSET)
-#define BLUEZ_EDBUS_CONN_NOT_FOUND (0x06 + BLUEZ_EDBUS_OFFSET)
-#define BLUEZ_EDBUS_UNKNOWN_PATH (0x07 + BLUEZ_EDBUS_OFFSET)
-#define BLUEZ_EDBUS_NOT_IMPLEMENTED (0x08 + BLUEZ_EDBUS_OFFSET)
-
-/* D-Bus error code, class BLUEZ_ESYSTEM_OFFSET */
-#define BLUEZ_ESYSTEM_ENODEV (ENODEV + BLUEZ_ESYSTEM_OFFSET)
-
-/* BLUEZ_DBUS_ERR_NO_MEMORY */
-#define BLUEZ_DBUS_ERR_NO_MEMORY_STR "No memory"
+#define BLUEZ_EDBUS_UNKNOWN_METHOD (0x01 | BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_SIGNATURE (0x02 | BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_WRONG_PARAM (0x03 | BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_RECORD_NOT_FOUND (0x04 | BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NO_MEM (0x05 | BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_CONN_NOT_FOUND (0x06 | BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_UNKNOWN_PATH (0x07 | BLUEZ_EDBUS_OFFSET)
+#define BLUEZ_EDBUS_NOT_IMPLEMENTED (0x08 | BLUEZ_EDBUS_OFFSET)
#endif /* __H_BLUEZ_DBUS_H__ */