Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Nov 2007 11:20:32 +0000
From:      Iain Hibbert <plunky@rya-online.net>
To:        <freebsd-bluetooth@freebsd.org>
Subject:   Re: sdp - SearchService of UUID
Message-ID:  <E1Ip02Y-00022q-5R@smtpbarns01>

index | next in thread | raw e-mail

[-- Attachment #1 --]
> so, provider_match_uuid() should probably accept the list of all uuids
> from the search pattern (we can limit it to 12 as spec says we should
> not expect more) and match all uuids from search pattern against 
> uuids in provider's service record.

Probably something like the attached functions? I will test it later..

> (hmm... i wonder if linux-bluez sdp has the same problem).

Does not seem so

[-- Attachment #2 --]
/*
 * Match provider by uuid
 */

int
provider_match_uuid(provider_p provider, uint128_t *uuid, int count)
{
	uint128_t puuid;
	int i;

	while (count > 0) {
		if (memcmp(uuid, &uuid_public_browse_group, sizeof(*uuid)) == 0)
			return 1;

		for (i = 0 ; ; i++) {
			if (i == provider->profile->ucount)
				return 0;

			memcpy(&puuid, &uuid_base, sizeof(puuid));
			puuid.b[2] = provider->profile->uuid[i] >> 8;
			puuid.b[3] = provider->profile->uuid[i];

			if (memcmp(uuid, &puuid, sizeof(*uuid)) == 0)
				break;
		}

		count--;
		uuid++;
	}

	return 1;
}

[-- Attachment #3 --]
/*
 * Extract ServiceSearchPattern from request to uuid array; return count
 */
int
server_get_service_search_pattern(uint8_t const **buf, uint8_t const *end, uint128_t *uuid)
{
	uint8_t const *req = *buf;
	uint32_t type, ssplen;
	int count;

	if (req + 1 < end)
		return 0;

	SDP_GET8(type, req);

	ssplen = 0;
	switch (type) {
	case SDP_DATA_SEQ8:
		if (req + 1 > end)
			return 0;

		SDP_GET8(ssplen, req);
		break;

	case SDP_DATA_SEQ16:
		if (req + 2 > end)
			return 0;

		SDP_GET16(ssplen, req);
		break;

	case SDP_DATA_SEQ32:
		if (req + 4 > end)
			return 0;

		SDP_GET32(ssplen, req);
		break;

	default:
		return 0;
	}

	if (req + ssplen > end)
		return 0;

	for (count = 0; ssplen > 0 && count < 12 ; count++) {
		SDP_GET8(type, req);
		ssplen--;

		switch (type) {
		case SDP_DATA_UUID16:
			if (ssplen < 2)
				return 0;

			memcpy(uuid, &uuid_base, sizeof(*uuid));
			uuid->b[2] = *req++;
			uuid->b[3] = *req++;
			ssplen -= 2;
			break;

		case SDP_DATA_UUID32:
			if (ssplen < 4)
				return 0;

			memcpy(uuid, &uuid_base, sizeof(*uuid));
			uuid->b[0] = *req++;
			uuid->b[1] = *req++;
			uuid->b[2] = *req++;
			uuid->b[3] = *req++;
			ssplen -= 4;
			break;

		case SDP_DATA_UUID128:
			if (ssplen < 16)
				return 0;

			memcpy(uuid, req, 16);
			req += 16;
			ssplen -= 16;
			break;

		default:
			return 0;
			/* NOT REACHED */
		}
	}

	*buf = req;
	return count;
}
help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?E1Ip02Y-00022q-5R>