static DBusMessage *find_adapter(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; struct adapter *adapter; char *path; struct hci_dev_info di; const char *pattern; int dev_id; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID)) return NULL; /* hci_devid() would make sense to use here, except it is restricted to devices which are up */ if (!strncmp(pattern, "hci", 3) && strlen(pattern) >= 4) dev_id = atoi(pattern + 3); else dev_id = find_by_address(pattern); if (dev_id < 0) return no_such_adapter(msg); if (hci_devinfo(dev_id, &di) < 0) return no_such_adapter(msg); if (hci_test_bit(HCI_RAW, &di.flags)) return no_such_adapter(msg); adapter = manager_find_adapter_by_id(dev_id); if (!adapter) return no_such_adapter(msg); reply = dbus_message_new_method_return(msg); if (!reply) return NULL; path = adapter->path + ADAPTER_PATH_INDEX; dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); return reply; }
static DBusMessage *old_find_adapter(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; char path[MAX_PATH_LENGTH], *path_ptr = path; struct hci_dev_info di; const char *pattern; int dev_id; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID)) return invalid_args(msg); /* hci_devid() would make sense to use here, except it is restricted to devices which are up */ if (!strncmp(pattern, "hci", 3) && strlen(pattern) >= 4) dev_id = atoi(pattern + 3); else dev_id = find_by_address(pattern); if (dev_id < 0) return no_such_adapter(msg); if (hci_devinfo(dev_id, &di) < 0) return no_such_adapter(msg); if (hci_test_bit(HCI_RAW, &di.flags)) return no_such_adapter(msg); reply = dbus_message_new_method_return(msg); if (!reply) return NULL; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, dev_id); dbus_message_append_args(reply, DBUS_TYPE_STRING, &path_ptr, DBUS_TYPE_INVALID); return reply; }
static DBusMessage *find_adapter(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; struct btd_adapter *adapter; const char *pattern; int dev_id; const gchar *path; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID)) return NULL; /* hci_devid() would make sense to use here, except it is restricted to devices which are up */ if (!strcmp(pattern, "any") || !strcmp(pattern, "00:00:00:00:00:00")) { path = adapter_any_get_path(); if (path != NULL) goto done; return no_such_adapter(msg); } else if (!strncmp(pattern, "hci", 3) && strlen(pattern) >= 4) { dev_id = atoi(pattern + 3); adapter = manager_find_adapter_by_id(dev_id); } else adapter = manager_find_adapter_by_address(pattern); if (!adapter) return no_such_adapter(msg); path = adapter_get_path(adapter); done: reply = dbus_message_new_method_return(msg); if (!reply) return NULL; dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); return reply; }
static DBusMessage *default_adapter(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; struct adapter *adapter; char *path; adapter = manager_find_adapter_by_id(default_adapter_id); if (!adapter) return no_such_adapter(msg); reply = dbus_message_new_method_return(msg); if (!reply) return NULL; path = adapter->path + ADAPTER_PATH_INDEX; dbus_message_append_args(reply, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); return reply; }
static DBusMessage *old_default_adapter(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessage *reply; char path[MAX_PATH_LENGTH], *path_ptr = path; if (!dbus_message_has_signature(msg, DBUS_TYPE_INVALID_AS_STRING)) return invalid_args(msg); if (default_adapter_id < 0) return no_such_adapter(msg); reply = dbus_message_new_method_return(msg); if (!reply) return NULL; snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, default_adapter_id); dbus_message_append_args(reply, DBUS_TYPE_STRING, &path_ptr, DBUS_TYPE_INVALID); return reply; }