static bool device_is_discoverable(struct btd_adapter *adapter,
					struct eir_data *eir, const char *addr,
					uint8_t bdaddr_type)
{
	GSList *l;
	bool discoverable;

	if (bdaddr_type == BDADDR_BREDR || adapter->filtered_discovery)
		discoverable = true;
	else
		discoverable = eir->flags & (EIR_LIM_DISC | EIR_GEN_DISC);

	/*
	 * Mark as not discoverable if no client has requested discovery and
	 * report has not set any discoverable flags.
	 */
	if (!adapter->discovery_list && !discoverable)
		return false;

	/* Do a prefix match for both address and name if pattern is set */
	for (l = adapter->discovery_list; l; l = g_slist_next(l)) {
		struct discovery_client *client = l->data;
		struct discovery_filter *filter = client->discovery_filter;
		size_t pattern_len;

		if (!filter || !filter->pattern)
			continue;

		/* Reset discoverable if a client has a pattern filter */
		discoverable = false;

		pattern_len = strlen(filter->pattern);
		if (!pattern_len)
			return true;

		if (!strncmp(filter->pattern, addr, pattern_len))
			return true;

		if (eir->name && !strncmp(filter->pattern, eir->name,
							pattern_len))
			return true;
	}

	return discoverable;
}
static bool device_is_discoverable(struct btd_adapter *adapter,
					struct eir_data *eir, const char *addr,
					uint8_t bdaddr_type)
{
	GSList *l;
	bool discoverable;

	if (bdaddr_type == BDADDR_BREDR || adapter->filtered_discovery)
		discoverable = true;
	else
		discoverable = eir->flags & (EIR_LIM_DISC | EIR_GEN_DISC);

	 
	if (!adapter->discovery_list && !discoverable)
		return false;

	 
	for (l = adapter->discovery_list; l; l = g_slist_next(l)) {
		struct discovery_client *client = l->data;
		struct discovery_filter *filter = client->discovery_filter;
		size_t pattern_len;

		if (!filter || !filter->pattern)
			continue;

		 
		discoverable = false;

		pattern_len = strlen(filter->pattern);
		if (!pattern_len)
			return true;

		if (!strncmp(filter->pattern, addr, pattern_len))
			return true;

		if (eir->name && !strncmp(filter->pattern, eir->name,
							pattern_len))
			return true;
	}

	return discoverable;
}