summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hcid/dbus.c111
-rw-r--r--hcid/dbus.h57
2 files changed, 46 insertions, 122 deletions
diff --git a/hcid/dbus.c b/hcid/dbus.c
index d6b75e47..f123a993 100644
--- a/hcid/dbus.c
+++ b/hcid/dbus.c
@@ -163,24 +163,6 @@ typedef struct {
const char *str;
} bluez_error_t;
-typedef struct {
- char *str;
- unsigned int val;
-} hci_map;
-
-static hci_map dev_flags_map[] = {
- { "INIT", HCI_INIT },
- { "RUNNING", HCI_RUNNING },
- { "RAW", HCI_RAW },
- { "PSCAN", HCI_PSCAN },
- { "ISCAN", HCI_ISCAN },
- { "INQUIRY", HCI_INQUIRY },
- { "AUTH", HCI_AUTH },
- { "ENCRYPT", HCI_ENCRYPT },
- { "SECMGR", HCI_SECMGR },
- { NULL }
-};
-
static const bluez_error_t dbus_error_array[] = {
{ BLUEZ_EDBUS_UNKNOWN_METHOD, "Method not found" },
{ BLUEZ_EDBUS_WRONG_SIGNATURE, "Wrong method signature" },
@@ -979,7 +961,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, bdaddr_t *peer, uint8_t reason)
* Section reserved to D-Bus watch functions
*
*****************************************************************/
-gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
+static gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
{
DBusWatch *watch = (DBusWatch *) data;
int flags = 0;
@@ -1001,7 +983,7 @@ gboolean watch_func(GIOChannel *chan, GIOCondition cond, gpointer data)
return TRUE;
}
-dbus_bool_t add_watch(DBusWatch *watch, void *data)
+static dbus_bool_t add_watch(DBusWatch *watch, void *data)
{
GIOCondition cond = G_IO_HUP | G_IO_ERR;
GIOChannel *io;
@@ -2201,26 +2183,22 @@ static DBusMessage* handle_mgr_device_list_req(DBusMessage *msg, void *data)
{
DBusMessageIter iter;
DBusMessageIter array_iter;
- DBusMessage *reply = NULL;
+ DBusMessage *reply;
struct hci_dev_list_req *dl = NULL;
struct hci_dev_req *dr = NULL;
- int sk = -1;
- int i;
- const char array_sig[] = MGR_REPLY_DEVICE_LIST_STRUCT_SIGNATURE;
+ int i, sk = -1;
- /* Create and bind HCI socket */
sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
if (sk < 0) {
syslog(LOG_ERR, "Can't open HCI socket: %s (%d)", strerror(errno), errno);
- reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
- goto failed;
+ return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_OFFSET + errno);
}
dl = malloc(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
if (!dl) {
syslog(LOG_ERR, "Can't allocate memory");
- reply = bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
- goto failed;
+ close(sk);
+ return bluez_new_failure_msg(msg, BLUEZ_EDBUS_NO_MEM);
}
dl->dev_num = HCI_MAX_DEV;
@@ -2231,7 +2209,8 @@ static DBusMessage* handle_mgr_device_list_req(DBusMessage *msg, void *data)
goto failed;
}
- /* active bluetooth adapter found */
+ dr = dl->dev_req;
+
reply = dbus_message_new_method_return(msg);
if (reply == NULL) {
syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return");
@@ -2239,92 +2218,54 @@ static DBusMessage* handle_mgr_device_list_req(DBusMessage *msg, void *data)
}
dbus_message_iter_init_append(reply, &iter);
- dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, array_sig, &array_iter);
- dr = dl->dev_req;
+
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+ DBUS_TYPE_STRING_AS_STRING, &array_iter);
for (i = 0; i < dl->dev_num; i++, dr++) {
- char apath[MAX_PATH_LENGTH];
- char aaddr[18];
- char *paddr = aaddr;
- char *ppath = apath;
- char *ptype;
- const char *flag;
- DBusMessageIter flag_array_iter, struct_iter;
+ char path[MAX_PATH_LENGTH], *path_ptr = path;
struct hci_dev_info di;
- hci_map *mp;
- mp = dev_flags_map;
memset(&di, 0 , sizeof(struct hci_dev_info));
di.dev_id = dr->dev_id;
if (ioctl(sk, HCIGETDEVINFO, &di) < 0)
continue;
- snprintf(apath, sizeof(apath), "%s/%s", DEVICE_PATH, di.name);
-
- ba2str(&di.bdaddr, aaddr);
- ptype = hci_dtypetostr(di.type);
-
- dbus_message_iter_open_container(&array_iter,
- DBUS_TYPE_STRUCT, NULL, &struct_iter);
-
- dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &ppath);
- dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &paddr);
- dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &ptype);
-
- if (hci_test_bit(HCI_UP, &dr->dev_opt))
- flag = "UP";
- else
- flag = "DOWN";
-
- dbus_message_iter_append_basic(&struct_iter, DBUS_TYPE_STRING, &flag);
+ snprintf(path, sizeof(path), "%s/%s", DEVICE_PATH, di.name);
- dbus_message_iter_open_container(&struct_iter,
- DBUS_TYPE_ARRAY, DBUS_TYPE_STRING_AS_STRING, &flag_array_iter);
-
- while (mp->str) {
- if (hci_test_bit(mp->val, &dr->dev_opt))
- dbus_message_iter_append_basic(&flag_array_iter, DBUS_TYPE_STRING, &mp->str);
- mp++;
- }
- dbus_message_iter_close_container(&struct_iter, &flag_array_iter);
- dbus_message_iter_close_container(&array_iter, &struct_iter);
+ dbus_message_iter_append_basic(&array_iter,
+ DBUS_TYPE_STRING, &path_ptr);
}
dbus_message_iter_close_container(&iter, &array_iter);
failed:
- if (sk >= 0)
- close(sk);
+ free(dl);
- if (dl)
- free(dl);
+ close(sk);
return reply;
}
static DBusMessage* handle_mgr_default_device_req(DBusMessage *msg, void *data)
{
- char path[MAX_PATH_LENGTH];
- char *pptr = path;
- DBusMessage *reply = NULL;
+ DBusMessage *reply;
+ char path[MAX_PATH_LENGTH], *path_ptr = path;
- if (default_dev < 0) {
- reply = bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
- goto failed;
- }
+ if (default_dev < 0)
+ return bluez_new_failure_msg(msg, BLUEZ_ESYSTEM_ENODEV);
reply = dbus_message_new_method_return(msg);
- if (reply == NULL) {
+ if (!reply) {
syslog(LOG_ERR, "Out of memory while calling dbus_message_new_method_return");
- goto failed;
+ return reply;
}
snprintf(path, sizeof(path), "%s/hci%d", DEVICE_PATH, default_dev);
- dbus_message_append_args(reply,
- DBUS_TYPE_STRING, &pptr,
+
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &path_ptr,
DBUS_TYPE_INVALID);
-failed:
return reply;
}
diff --git a/hcid/dbus.h b/hcid/dbus.h
index 2e92a3bd..668302c3 100644
--- a/hcid/dbus.h
+++ b/hcid/dbus.h
@@ -67,25 +67,9 @@
#define MGR_DEVICE_LIST_SIGNATURE __END_SIG__
#define MGR_DEFAULT_DEVICE_SIGNATURE __END_SIG__
-
-/*FIXME: should it be moved to a internal header file? */
-/* DeviceList Reply: a(devname, addr, type, up/down, a(flags)) - all types strings */
-#define MGR_REPLY_DEVICE_LIST_STRUCT_SIGNATURE DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
- DBUS_TYPE_STRING_AS_STRING \
- DBUS_TYPE_STRING_AS_STRING \
- DBUS_TYPE_STRING_AS_STRING \
- DBUS_TYPE_STRING_AS_STRING \
- DBUS_TYPE_ARRAY_AS_STRING \
- DBUS_TYPE_STRING_AS_STRING \
- DBUS_STRUCT_END_CHAR_AS_STRING \
- __END_SIG__
-
#define MGR_REPLY_DEVICE_LIST_SIGNATURE DBUS_TYPE_ARRAY_AS_STRING \
- MGR_REPLY_DEVICE_LIST_STRUCT_SIGNATURE \
__END_SIG__
-
-
/*========================================================================
BlueZ D-Bus Device path definitions "/org/bluez/Device"
*========================================================================*/
@@ -125,7 +109,7 @@
/*FIXME: maybe this section can be moved to a internal header file */
/* Device service signature */
#define DEV_GET_ADDRESS_SIGNATURE __END_SIG__
-#define DEV_GET_ALIAS_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_GET_ALIAS_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
#define DEV_GET_COMPANY_SIGNATURE __END_SIG__
#define DEV_GET_DISCOVERABLE_TO_SIGNATURE __END_SIG__
@@ -136,44 +120,44 @@
#define DEV_GET_REVISION_SIGNATURE __END_SIG__
#define DEV_GET_VERSION_SIGNATURE __END_SIG__
#define DEV_IS_CONNECTABLE_SIGNATURE __END_SIG__
-#define DEV_IS_DISCOVERABLE_SIGNATURE __END_SIG__
-#define DEV_SET_ALIAS_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
- DBUS_TYPE_STRING_AS_STRING\
+#define DEV_IS_DISCOVERABLE_SIGNATURE __END_SIG__
+#define DEV_SET_ALIAS_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
+ DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_SET_CLASS_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
- DBUS_TYPE_STRING_AS_STRING\
+#define DEV_SET_CLASS_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
+ DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_SET_DISCOVERABLE_TO_SIGNATURE DBUS_TYPE_UINT32_AS_STRING\
+#define DEV_SET_DISCOVERABLE_TO_SIGNATURE DBUS_TYPE_UINT32_AS_STRING \
__END_SIG__
-#define DEV_SET_MODE_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_SET_MODE_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_SET_NAME_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_SET_NAME_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
#define DEV_DISCOVER_SIGNATURE __END_SIG__
#define DEV_DISCOVER_CACHE_SIGNATURE __END_SIG__
#define DEV_DISCOVER_CANCEL_SIGNATURE __END_SIG__
-#define DEV_DISCOVER_SERVICE_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_DISCOVER_SERVICE_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_LAST_SEEN_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_LAST_SEEN_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_LAST_USED_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_LAST_USED_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_REMOTE_ALIAS_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_REMOTE_ALIAS_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_REMOTE_NAME_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_REMOTE_NAME_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_REMOTE_VERSION_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_REMOTE_VERSION_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_CREATE_BONDING_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_CREATE_BONDING_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
#define DEV_LIST_BONDINGS_SIGNATURE __END_SIG__
-#define DEV_HAS_BONDING_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_HAS_BONDING_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_REMOVE_BONDING_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_REMOVE_BONDING_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_PIN_CODE_LENGTH_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_PIN_CODE_LENGTH_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
-#define DEV_ENCRYPTION_KEY_SIZE_SIGNATURE DBUS_TYPE_STRING_AS_STRING\
+#define DEV_ENCRYPTION_KEY_SIZE_SIGNATURE DBUS_TYPE_STRING_AS_STRING \
__END_SIG__
@@ -233,4 +217,3 @@
#define BLUEZ_DBUS_ERR_NO_MEMORY_STR "No memory"
#endif /* __H_BLUEZ_DBUS_H__ */
-