static void modem_register_from_proxy(GDBusProxy *proxy, const char *path) { const char *alias, *remote; DBusMessageIter iter; dbus_bool_t paired; struct ofono_modem *modem; if (g_dbus_proxy_get_property(proxy, "Paired", &iter) == FALSE) return; dbus_message_iter_get_basic(&iter, &paired); if (paired == FALSE) return; if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE) return; if (has_hfp_ag_uuid(&iter) == FALSE) return; if (g_dbus_proxy_get_property(proxy, "Alias", &iter) == FALSE) return; dbus_message_iter_get_basic(&iter, &alias); if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE) return; dbus_message_iter_get_basic(&iter, &remote); modem = modem_register(path, remote, alias); g_dbus_proxy_set_property_watch(proxy, alias_changed, modem); g_dbus_proxy_set_removed_watch(proxy, modem_removed, modem); }
static void print_service(GDBusProxy *proxy, const char *description) { DBusMessageIter iter; const char *uuid, *text; dbus_bool_t primary; if (g_dbus_proxy_get_property(proxy, "UUID", &iter) == FALSE) return; dbus_message_iter_get_basic(&iter, &uuid); if (g_dbus_proxy_get_property(proxy, "Primary", &iter) == FALSE) return; dbus_message_iter_get_basic(&iter, &primary); text = uuidstr_to_str(uuid); if (!text) text = uuid; rl_printf("%s%s%sService %s %s %s\n", description ? "[" : "", description ? : "", description ? "] " : "", g_dbus_proxy_get_path(proxy), text, primary ? "(Primary)" : "(Secondary)"); }
static bool parse_advertising_type(GDBusProxy *proxy, uint8_t *type) { DBusMessageIter iter; const char *msg_type; if (!g_dbus_proxy_get_property(proxy, "Type", &iter)) return false; if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return false; dbus_message_iter_get_basic(&iter, &msg_type); if (!g_strcmp0(msg_type, "broadcast")) { *type = AD_TYPE_BROADCAST; return true; } if (!g_strcmp0(msg_type, "peripheral")) { *type = AD_TYPE_PERIPHERAL; return true; } return false; }
static void cmd_scan(int argc, char *argv[]) { char *value; DBusMessageIter iter; if (!check_default_player()) return bt_shell_noninteractive_quit(EXIT_FAILURE); if (!g_dbus_proxy_get_property(default_player, "Shuffle", &iter)) { bt_shell_printf("Operation not supported\n"); return bt_shell_noninteractive_quit(EXIT_FAILURE); } value = g_strdup(argv[1]); if (g_dbus_proxy_set_property_basic(default_player, "Shuffle", DBUS_TYPE_STRING, &value, generic_callback, value, g_free) == FALSE) { bt_shell_printf("Failed to set scan\n"); g_free(value); return bt_shell_noninteractive_quit(EXIT_FAILURE); } bt_shell_printf("Attempting to set scan\n"); }
static const char *proxy_get_role(GDBusProxy *proxy) { DBusMessageIter iter, value; const char *pref = NULL; if (!proxy) return NULL; if (!g_dbus_proxy_get_property(proxy, "UUIDs", &iter)) return NULL; dbus_message_iter_recurse(&iter, &value); while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { const char *uuid; dbus_message_iter_get_basic(&value, &uuid); /* * If a device offers more than one role, we prefer NAP, * then GN, then PANU. */ if (!strcmp(uuid, BLUETOOTH_PAN_NAP)) return "nap"; if (!strcmp(uuid, BLUETOOTH_PAN_GN)) pref = "gn"; if (!strcmp(uuid, BLUETOOTH_PAN_PANU) && !pref) pref = "panu"; dbus_message_iter_next(&value); } return pref; }
static void cmd_show(int argc, char *argv[]) { GDBusProxy *proxy; GDBusProxy *folder; GDBusProxy *item; DBusMessageIter iter; const char *path; if (argc < 2) { if (check_default_player() == FALSE) return bt_shell_noninteractive_quit(EXIT_FAILURE); proxy = default_player; } else { proxy = g_dbus_proxy_lookup(players, NULL, argv[1], BLUEZ_MEDIA_PLAYER_INTERFACE); if (!proxy) { bt_shell_printf("Player %s not available\n", argv[1]); return bt_shell_noninteractive_quit(EXIT_FAILURE); } } bt_shell_printf("Player %s\n", g_dbus_proxy_get_path(proxy)); print_property(proxy, "Name"); print_property(proxy, "Repeat"); print_property(proxy, "Equalizer"); print_property(proxy, "Shuffle"); print_property(proxy, "Scan"); print_property(proxy, "Status"); print_property(proxy, "Position"); print_property(proxy, "Track"); folder = g_dbus_proxy_lookup(folders, NULL, g_dbus_proxy_get_path(proxy), BLUEZ_MEDIA_FOLDER_INTERFACE); if (folder == NULL) return bt_shell_noninteractive_quit(EXIT_SUCCESS); bt_shell_printf("Folder %s\n", g_dbus_proxy_get_path(proxy)); print_property(folder, "Name"); print_property(folder, "NumberOfItems"); if (!g_dbus_proxy_get_property(proxy, "Playlist", &iter)) return bt_shell_noninteractive_quit(EXIT_SUCCESS); dbus_message_iter_get_basic(&iter, &path); item = g_dbus_proxy_lookup(items, NULL, path, BLUEZ_MEDIA_ITEM_INTERFACE); if (item == NULL) return bt_shell_noninteractive_quit(EXIT_SUCCESS); bt_shell_printf("Playlist %s\n", path); print_property(item, "Name"); return bt_shell_noninteractive_quit(EXIT_SUCCESS); }
static void print_property(GDBusProxy *proxy, const char *name) { DBusMessageIter iter; if (g_dbus_proxy_get_property(proxy, name, &iter) == FALSE) return; print_iter("\t", name, &iter); }
static bool proxy_get_bool(GDBusProxy *proxy, const char *property) { DBusMessageIter iter; dbus_bool_t value; if (!g_dbus_proxy_get_property(proxy, property, &iter)) return false; dbus_message_iter_get_basic(&iter, &value); return value; }
static const char *proxy_get_string(GDBusProxy *proxy, const char *property) { DBusMessageIter iter; const char *str; if (!g_dbus_proxy_get_property(proxy, property, &iter)) return NULL; dbus_message_iter_get_basic(&iter, &str); return str; }
static connman_bool_t proxy_get_bool(GDBusProxy *proxy, const char *property) { DBusMessageIter iter; connman_bool_t value; if (g_dbus_proxy_get_property(proxy, property, &iter) == FALSE) return FALSE; dbus_message_iter_get_basic(&iter, &value); return value; }
static bool parse_advertising_service_data(GDBusProxy *proxy, struct bt_ad *data) { DBusMessageIter iter, entries; if (!g_dbus_proxy_get_property(proxy, "ServiceData", &iter)) return true; if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) return false; dbus_message_iter_recurse(&iter, &entries); bt_ad_clear_service_data(data); while (dbus_message_iter_get_arg_type(&entries) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter value, entry; const char *uuid_str; bt_uuid_t uuid; uint8_t *service_data; int len; dbus_message_iter_recurse(&entries, &entry); dbus_message_iter_get_basic(&entry, &uuid_str); if (bt_string_to_uuid(&uuid, uuid_str) < 0) goto fail; dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_ARRAY) goto fail; dbus_message_iter_recurse(&entry, &value); if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_BYTE) goto fail; dbus_message_iter_get_fixed_array(&value, &service_data, &len); DBG("Adding ServiceData for %s", uuid_str); if (!bt_ad_add_service_data(data, &uuid, service_data, len)) goto fail; dbus_message_iter_next(&entries); } return true; fail: bt_ad_clear_service_data(data); return false; }
static bool parse_advertising_manufacturer_data(GDBusProxy *proxy, struct bt_ad *data) { DBusMessageIter iter, entries; if (!g_dbus_proxy_get_property(proxy, "ManufacturerData", &iter)) return true; if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) return false; dbus_message_iter_recurse(&iter, &entries); bt_ad_clear_manufacturer_data(data); while (dbus_message_iter_get_arg_type(&entries) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter value, entry; uint16_t manuf_id; uint8_t *manuf_data; int len; dbus_message_iter_recurse(&entries, &entry); dbus_message_iter_get_basic(&entry, &manuf_id); dbus_message_iter_next(&entry); if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_ARRAY) goto fail; dbus_message_iter_recurse(&entry, &value); if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_BYTE) goto fail; dbus_message_iter_get_fixed_array(&value, &manuf_data, &len); DBG("Adding ManufacturerData for %04x", manuf_id); if (!bt_ad_add_manufacturer_data(data, manuf_id, manuf_data, len)) goto fail; dbus_message_iter_next(&entries); } return true; fail: bt_ad_clear_manufacturer_data(data); return false; }
static void print_item(GDBusProxy *proxy, const char *description) { const char *path, *name; DBusMessageIter iter; path = g_dbus_proxy_get_path(proxy); if (g_dbus_proxy_get_property(proxy, "Name", &iter)) dbus_message_iter_get_basic(&iter, &name); else name = "<unknown>"; bt_shell_printf("%s%s%sItem %s %s\n", description ? "[" : "", description ? : "", description ? "] " : "", path, name); }
static bool parse_advertising_include_tx_power(GDBusProxy *proxy, bool *included) { DBusMessageIter iter; dbus_bool_t b; if (!g_dbus_proxy_get_property(proxy, "IncludeTxPower", &iter)) return true; if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BOOLEAN) return false; dbus_message_iter_get_basic(&iter, &b); *included = b; return true; }
static void print_characteristic(GDBusProxy *proxy, const char *description) { DBusMessageIter iter; const char *uuid, *text; if (g_dbus_proxy_get_property(proxy, "UUID", &iter) == FALSE) return; dbus_message_iter_get_basic(&iter, &uuid); text = uuidstr_to_str(uuid); if (!text) text = uuid; rl_printf("%s%s%sCharacteristic %s %s\n", description ? "[" : "", description ? : "", description ? "] " : "", g_dbus_proxy_get_path(proxy), text); }
static void proxy_read_cb(struct btd_attribute *attr, btd_attr_read_result_t result, void *user_data) { DBusMessageIter iter, array; GDBusProxy *proxy; uint8_t *value; int len; /* * Remote device is trying to read the informed attribute, * "Value" should be read from the proxy. GDBusProxy tracks * properties changes automatically, it is not necessary to * get the value directly from the GATT server. */ proxy = g_hash_table_lookup(proxy_hash, attr); if (!proxy) { result(-ENOENT, NULL, 0, user_data); return; } if (!g_dbus_proxy_get_property(proxy, "Value", &iter)) { /* Unusual situation, read property will checked earlier */ result(-EPERM, NULL, 0, user_data); return; } if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) { DBG("External service inconsistent!"); result(-EPERM, NULL, 0, user_data); return; } dbus_message_iter_recurse(&iter, &array); dbus_message_iter_get_fixed_array(&array, &value, &len); DBG("attribute: %p read %d bytes", attr, len); result(0, value, len, user_data); }
static connman_bool_t proxy_get_nap(GDBusProxy *proxy) { DBusMessageIter iter, value; if (proxy == NULL) return FALSE; if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE) return FALSE; dbus_message_iter_recurse(&iter, &value); while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { const char *uuid; dbus_message_iter_get_basic(&value, &uuid); if (strcmp(uuid, BLUETOOTH_PAN_NAP) == 0) return TRUE; dbus_message_iter_next(&value); } return FALSE; }
static gboolean descriptor_is_child(GDBusProxy *characteristic) { GList *l; DBusMessageIter iter; const char *service, *path; if (!g_dbus_proxy_get_property(characteristic, "Characteristic", &iter)) return FALSE; dbus_message_iter_get_basic(&iter, &service); for (l = characteristics; l; l = g_list_next(l)) { GDBusProxy *proxy = l->data; path = g_dbus_proxy_get_path(proxy); if (!strcmp(path, service)) return TRUE; } return FALSE; }
static bool parse_advertising_solicit_uuids(GDBusProxy *proxy, struct bt_ad *data) { DBusMessageIter iter, ariter; if (!g_dbus_proxy_get_property(proxy, "SolicitUUIDs", &iter)) return true; if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) return false; dbus_message_iter_recurse(&iter, &ariter); bt_ad_clear_solicit_uuid(data); while (dbus_message_iter_get_arg_type(&ariter) == DBUS_TYPE_STRING) { const char *uuid_str; bt_uuid_t uuid; dbus_message_iter_get_basic(&ariter, &uuid_str); DBG("Adding SolicitUUID: %s", uuid_str); if (bt_string_to_uuid(&uuid, uuid_str) < 0) goto fail; if (!bt_ad_add_solicit_uuid(data, &uuid)) goto fail; dbus_message_iter_next(&ariter); } return true; fail: bt_ad_clear_solicit_uuid(data); return false; }