2011-02-18 22:29:19

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 00/14] Store UUID-128 on host order

It must NOT be included in the next release until proper testing.

Any good soul wants to test it if I am not breaking SDP?

The following patches convert the internal UUID128 values representation
to host order. Currently, SDP functions use host order to store UUID-16
/UUID32 and network order to store UUID-128 values. The reason is to
keep the consistency and re-use the UUID functions for ATT protocol
which uses little endian.

Changes from the first RFC:
- Changes sdptool
- Changes SDP XML parsing function
- Changes attribute example

Claudio Takahasi (14):
Move 64 and 128 bits byte order functions to bluetooth.h
Use host byte order when converting UUID16/32 to UUID128
Add att_get_u128
Convert UUID128 value to host order when extracting SDP data
Convert to network order before use it on sdp_uuid128_to_uuid
Convert from host to network order before to print UUID128 values
Convert from network to host order on bt_string2uuid function
Change UUID128 host order on SDP PDU generation function
Replace UUID128 values from char array to uint128_t on sdptool
Create UUID128 on host order on sdptool
Change SDP XML parser to create UUID128 values on host order
Convert from little endian to host order when parsing EIR data
Add att_put_u128
Change Attribute example to create UUID128 on host order

attrib/att.c | 16 ++++--
attrib/att.h | 17 ++++++
attrib/example.c | 24 +++++---
attrib/gatt.c | 14 +++--
attrib/gatttool.c | 6 ++-
attrib/interactive.c | 1 +
health/hdp_manager.c | 1 +
health/mcap_sync.c | 17 ------
lib/bluetooth.h | 41 ++++++++++++++
lib/sdp.c | 108 ++++++++++++++-----------------------
lib/sdp.h | 4 --
src/event.c | 6 +--
src/glib-helper.c | 31 ++++++-----
src/sdp-xml.c | 74 +++++++++++--------------
test/hciemu.c | 16 ------
tools/sdptool.c | 145 ++++++++++++++++++++++++++++++-------------------
16 files changed, 280 insertions(+), 241 deletions(-)

--
1.7.4.1



2011-02-22 17:27:50

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 13/14] Add att_put_u128

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> ATT protocol uses little endian byte order, before to add a UUID128
> value in the PDU it needs to converted from host order to little endian.
> ---
> ?attrib/att.c | ? ?4 ++--
> ?attrib/att.h | ? ?7 +++++++
> ?2 files changed, 9 insertions(+), 2 deletions(-)

Similarly, this part of the original code is still buggy and we need a
ntoh128() call before att_put_u128().

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-22 17:24:16

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 03/14] Add att_get_u128

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> Function to convert 128-bits values from little endian to host
> order. Different than SDP, ATT uses little endian format.
> ---
> ?attrib/att.c ? ? ?| ? 12 ++++++++----
> ?attrib/att.h ? ? ?| ? 10 ++++++++++
> ?attrib/gatt.c ? ? | ? 13 ++++++++-----
> ?attrib/gatttool.c | ? ?6 ++++--
> ?4 files changed, 30 insertions(+), 11 deletions(-)

This patch could be refactored by adding a hton128() call before
calling sdp_uuid128_create(). This way we fix the valid bug where we
are not passing big-endian ordered bytes to sdp_uuid28_create(). What
do you think?

At least the att_get_u128() function is still valid and needs to be
applied IMHO.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-22 17:16:08

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 01/14] Move 64 and 128 bits byte order functions to bluetooth.h

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> ---
> ?attrib/example.c ? ? | ? ?1 +
> ?attrib/gatt.c ? ? ? ?| ? ?1 +
> ?attrib/interactive.c | ? ?1 +
> ?health/hdp_manager.c | ? ?1 +
> ?health/mcap_sync.c ? | ? 17 -----------------
> ?lib/bluetooth.h ? ? ?| ? 41 +++++++++++++++++++++++++++++++++++++++++
> ?lib/sdp.c ? ? ? ? ? ?| ? 43 -------------------------------------------
> ?lib/sdp.h ? ? ? ? ? ?| ? ?4 ----
> ?src/sdp-xml.c ? ? ? ?| ? ?1 +
> ?test/hciemu.c ? ? ? ?| ? 16 ----------------
> ?10 files changed, 46 insertions(+), 80 deletions(-)

Can we have this patch applied upstream? It seems a good refactoring
because removes duplicated code.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-21 18:37:50

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order

Hi,

On Mon, Feb 21, 2011 at 6:54 PM, Johan Hedberg <[email protected]> wr=
ote:
> Hi Luiz,
>
> On Mon, Feb 21, 2011, Luiz Augusto von Dentz wrote:
>> > Just throwing my own bits on this: I think making the internal
>> > representation for uuid_t consistent is important to avoid bugs when
>> > handling the different UUID types.
>> >
>> > currently uuid_t stores 16/32-bit uuids and 128-bit uuid differently.
>>
>> The problem is not the internal representation, but things like this:
>>
>> - =A0 =A0 =A0 sdp_uuid128_create(&svclass_uuid, SYNCMLC_UUID);
>> + =A0 =A0 =A0 ntoh128(SYNCMLC_UUID, &h128);
>> + =A0 =A0 =A0 sdp_uuid128_create(&svclass_uuid, &h128);
>>
>> This means the API has changed, it now takes host order where it used
>> to be network order. We could have a new function e.g.
>> sdp_uuid128h_create to handle such cases and not break existing
>> applications using this API.
>
> In this particular case the prefix sdp_ already implies that this is for
> SDP and shouldn't be used in other code. I think what makes sense (and
> Marcel supported it in IRC) is to a new bt_uuid_t struct and bt_uuid_*
> helper functions which internally store everything in host byte order.
> Then in the first phase we can make the ATT code use the new API and
> later in a second phase start converting existing SDP code to use it.

Sound good to me.



--=20
Luiz Augusto von Dentz
Computer Engineer

2011-02-21 16:54:31

by Johan Hedberg

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order

Hi Luiz,

On Mon, Feb 21, 2011, Luiz Augusto von Dentz wrote:
> > Just throwing my own bits on this: I think making the internal
> > representation for uuid_t consistent is important to avoid bugs when
> > handling the different UUID types.
> >
> > currently uuid_t stores 16/32-bit uuids and 128-bit uuid differently.
>
> The problem is not the internal representation, but things like this:
>
> - sdp_uuid128_create(&svclass_uuid, SYNCMLC_UUID);
> + ntoh128(SYNCMLC_UUID, &h128);
> + sdp_uuid128_create(&svclass_uuid, &h128);
>
> This means the API has changed, it now takes host order where it used
> to be network order. We could have a new function e.g.
> sdp_uuid128h_create to handle such cases and not break existing
> applications using this API.

In this particular case the prefix sdp_ already implies that this is for
SDP and shouldn't be used in other code. I think what makes sense (and
Marcel supported it in IRC) is to a new bt_uuid_t struct and bt_uuid_*
helper functions which internally store everything in host byte order.
Then in the first phase we can make the ATT code use the new API and
later in a second phase start converting existing SDP code to use it.

Johan

2011-02-21 13:52:58

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order

Hi,

On Mon, Feb 21, 2011 at 3:43 PM, Anderson Lizardo
<[email protected]> wrote:
> Hi,
>
> On Mon, Feb 21, 2011 at 10:14 AM, Claudio Takahasi
> <[email protected]> wrote:
>> On Sat, Feb 19, 2011 at 6:07 PM, Luiz Augusto von Dentz
>>> IMO it would be easier to have specific functions for uuid128 that can
>>> take data in host order, so that we don't break existing API. Note
>>> that the internal representation could be changed to host order, that
>>> is fine, but then you convert the existing function to do the
>>> conversion internally without breaking compatibility.
>>
>> Yes, it is easier. It will be necessary to add a function to convert
>> from little endian to big endian for ATT when the data is received.
>> I am not changing the API, it changes only the internal
>> representation(to host order) of the UUID128 values.
>
> Just throwing my own bits on this: I think making the internal
> representation for uuid_t consistent is important to avoid bugs when
> handling the different UUID types.
>
> currently uuid_t stores 16/32-bit uuids and 128-bit uuid differently.

The problem is not the internal representation, but things like this:

- sdp_uuid128_create(&svclass_uuid, SYNCMLC_UUID);
+ ntoh128(SYNCMLC_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);

This means the API has changed, it now takes host order where it used
to be network order. We could have a new function e.g.
sdp_uuid128h_create to handle such cases and not break existing
applications using this API.

--
Luiz Augusto von Dentz
Computer Engineer

2011-02-21 13:43:53

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order

Hi,

On Mon, Feb 21, 2011 at 10:14 AM, Claudio Takahasi
<[email protected]> wrote:
> On Sat, Feb 19, 2011 at 6:07 PM, Luiz Augusto von Dentz
>> IMO it would be easier to have specific functions for uuid128 that can
>> take data in host order, so that we don't break existing API. Note
>> that the internal representation could be changed to host order, that
>> is fine, but then you convert the existing function to do the
>> conversion internally without breaking compatibility.
>
> Yes, it is easier. It will be necessary to add a function to convert
> from little endian to big endian for ATT when the data is received.
> I am not changing the API, it changes only the internal
> representation(to host order) of the UUID128 values.

Just throwing my own bits on this: I think making the internal
representation for uuid_t consistent is important to avoid bugs when
handling the different UUID types.

currently uuid_t stores 16/32-bit uuids and 128-bit uuid differently.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-21 13:14:46

by Claudio Takahasi

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order

Hi Luiz,

On Sat, Feb 19, 2011 at 6:07 PM, Luiz Augusto von Dentz
<[email protected]> wrote:
> Hi Claudio,
>
> On Sat, Feb 19, 2011 at 12:29 AM, Claudio Takahasi
> <[email protected]> wrote:
>> It must NOT be included in the next release until proper testing.
>>
>> Any good soul wants to test it if I am not breaking SDP?
>>
>> The following patches convert the internal UUID128 values representation
>> to host order. Currently, SDP functions use host order to store UUID-16
>> /UUID32 and network order to store UUID-128 values. The reason is to
>> keep the consistency and re-use the UUID functions for ATT protocol
>> which uses little endian.
>>
>> Changes from the first RFC:
>> =C2=A0- Changes sdptool
>> =C2=A0- Changes SDP XML parsing function
>> =C2=A0- Changes attribute example
>>
>> Claudio Takahasi (14):
>> =C2=A0Move 64 and 128 bits byte order functions to bluetooth.h
>> =C2=A0Use host byte order when converting UUID16/32 to UUID128
>> =C2=A0Add att_get_u128
>> =C2=A0Convert UUID128 value to host order when extracting SDP data
>> =C2=A0Convert to network order before use it on sdp_uuid128_to_uuid
>> =C2=A0Convert from host to network order before to print UUID128 values
>> =C2=A0Convert from network to host order on bt_string2uuid function
>> =C2=A0Change UUID128 host order on SDP PDU generation function
>> =C2=A0Replace UUID128 values from char array to uint128_t on sdptool
>> =C2=A0Create UUID128 on host order on sdptool
>> =C2=A0Change SDP XML parser to create UUID128 values on host order
>> =C2=A0Convert from little endian to host order when parsing EIR data
>> =C2=A0Add att_put_u128
>> =C2=A0Change Attribute example to create UUID128 on host order
>>
>> =C2=A0attrib/att.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 16 ++++--
>> =C2=A0attrib/att.h =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 17 ++++++
>> =C2=A0attrib/example.c =C2=A0 =C2=A0 | =C2=A0 24 +++++---
>> =C2=A0attrib/gatt.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 14 +++--
>> =C2=A0attrib/gatttool.c =C2=A0 =C2=A0| =C2=A0 =C2=A06 ++-
>> =C2=A0attrib/interactive.c | =C2=A0 =C2=A01 +
>> =C2=A0health/hdp_manager.c | =C2=A0 =C2=A01 +
>> =C2=A0health/mcap_sync.c =C2=A0 | =C2=A0 17 ------
>> =C2=A0lib/bluetooth.h =C2=A0 =C2=A0 =C2=A0| =C2=A0 41 ++++++++++++++
>> =C2=A0lib/sdp.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0108 +++=
+++++++++++-----------------------
>> =C2=A0lib/sdp.h =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A0=
4 --
>> =C2=A0src/event.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 =C2=A06 +--
>> =C2=A0src/glib-helper.c =C2=A0 =C2=A0| =C2=A0 31 ++++++-----
>> =C2=A0src/sdp-xml.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 74 +++++++++++--=
------------
>> =C2=A0test/hciemu.c =C2=A0 =C2=A0 =C2=A0 =C2=A0| =C2=A0 16 ------
>> =C2=A0tools/sdptool.c =C2=A0 =C2=A0 =C2=A0| =C2=A0145 ++++++++++++++++++=
++++++++++++-------------------
>> =C2=A016 files changed, 280 insertions(+), 241 deletions(-)
>>
>> --
>> 1.7.4.1
>
> IMO it would be easier to have specific functions for uuid128 that can
> take data in host order, so that we don't break existing API. Note
> that the internal representation could be changed to host order, that
> is fine, but then you convert the existing function to do the
> conversion internally without breaking compatibility.
>
> --
> Luiz Augusto von Dentz
> Computer Engineer
>

Yes, it is easier. It will be necessary to add a function to convert
from little endian to big endian for ATT when the data is received.
I am not changing the API, it changes only the internal
representation(to host order) of the UUID128 values.


We got "blessing" from Marcel to proceed with this change, but I can
implement the easier solution ;-)

Marcel/Johan: comments?

BR,
Claudio

2011-02-19 18:07:38

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order

Hi Claudio,

On Sat, Feb 19, 2011 at 12:29 AM, Claudio Takahasi
<[email protected]> wrote:
> It must NOT be included in the next release until proper testing.
>
> Any good soul wants to test it if I am not breaking SDP?
>
> The following patches convert the internal UUID128 values representation
> to host order. Currently, SDP functions use host order to store UUID-16
> /UUID32 and network order to store UUID-128 values. The reason is to
> keep the consistency and re-use the UUID functions for ATT protocol
> which uses little endian.
>
> Changes from the first RFC:
> ?- Changes sdptool
> ?- Changes SDP XML parsing function
> ?- Changes attribute example
>
> Claudio Takahasi (14):
> ?Move 64 and 128 bits byte order functions to bluetooth.h
> ?Use host byte order when converting UUID16/32 to UUID128
> ?Add att_get_u128
> ?Convert UUID128 value to host order when extracting SDP data
> ?Convert to network order before use it on sdp_uuid128_to_uuid
> ?Convert from host to network order before to print UUID128 values
> ?Convert from network to host order on bt_string2uuid function
> ?Change UUID128 host order on SDP PDU generation function
> ?Replace UUID128 values from char array to uint128_t on sdptool
> ?Create UUID128 on host order on sdptool
> ?Change SDP XML parser to create UUID128 values on host order
> ?Convert from little endian to host order when parsing EIR data
> ?Add att_put_u128
> ?Change Attribute example to create UUID128 on host order
>
> ?attrib/att.c ? ? ? ? | ? 16 ++++--
> ?attrib/att.h ? ? ? ? | ? 17 ++++++
> ?attrib/example.c ? ? | ? 24 +++++---
> ?attrib/gatt.c ? ? ? ?| ? 14 +++--
> ?attrib/gatttool.c ? ?| ? ?6 ++-
> ?attrib/interactive.c | ? ?1 +
> ?health/hdp_manager.c | ? ?1 +
> ?health/mcap_sync.c ? | ? 17 ------
> ?lib/bluetooth.h ? ? ?| ? 41 ++++++++++++++
> ?lib/sdp.c ? ? ? ? ? ?| ?108 ++++++++++++++-----------------------
> ?lib/sdp.h ? ? ? ? ? ?| ? ?4 --
> ?src/event.c ? ? ? ? ?| ? ?6 +--
> ?src/glib-helper.c ? ?| ? 31 ++++++-----
> ?src/sdp-xml.c ? ? ? ?| ? 74 +++++++++++--------------
> ?test/hciemu.c ? ? ? ?| ? 16 ------
> ?tools/sdptool.c ? ? ?| ?145 ++++++++++++++++++++++++++++++-------------------
> ?16 files changed, 280 insertions(+), 241 deletions(-)
>
> --
> 1.7.4.1

IMO it would be easier to have specific functions for uuid128 that can
take data in host order, so that we don't break existing API. Note
that the internal representation could be changed to host order, that
is fine, but then you convert the existing function to do the
conversion internally without breaking compatibility.

--
Luiz Augusto von Dentz
Computer Engineer

2011-02-19 01:29:34

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order

Hi all,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> It must NOT be included in the next release until proper testing.
>
> Any good soul wants to test it if I am not breaking SDP?

I did my own review (just by looking at source code, no actual
testing). We'd appreciate if more people can review and/or test these
patches. One idea would be to test on big endian systems, and compare
hcidump logs with/without these patches.

Note that it is not just a refactoring; It actually fixes endianness
issues with GATT.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-19 01:24:51

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 14/14] Change Attribute example to create UUID128 on host order

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> ---
> ?attrib/example.c | ? 23 ++++++++++++++---------
> ?1 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/attrib/example.c b/attrib/example.c
> index f5fcf1b..6e39a68 100644
> --- a/attrib/example.c
> +++ b/attrib/example.c
> @@ -60,6 +60,14 @@
> ?#define FMT_KILOGRAM_UUID ? ? ? ? ? ? ?0xA010
> ?#define FMT_HANGING_UUID ? ? ? ? ? ? ? 0xA011
>
> +#define CHAR_WEIGHT_UUID (&(uint128_t) {{ \
> + ? ? ? ? ? ? ? ? ? ? ? 0x80, 0x88, 0xF2, 0x18, 0x90, 0x2C, 0x45, 0x0B, \
> + ? ? ? ? ? ? ? ? ? ? ? 0xB6, 0xC4, 0x62, 0x89, 0x1E, 0x8C, 0x25, 0xE9 }})
> +
> +#define PRIM_WEIGHT_UUID (&(uint128_t) {{ \
> + ? ? ? ? ? ? ? ? ? ? ? 0x4F, 0x0A, 0xC0, 0x96, 0x35, 0xD4, 0x49, 0x11, \
> + ? ? ? ? ? ? ? ? ? ? ? 0x96, 0x31, 0xDE, 0xA8, 0xDC, 0x74, 0xEE, 0xFE }})
> +
> ?static int register_attributes(void)
> ?{
> ? ? ? ?const char *desc_out_temp = "Outside Temperature";
> @@ -69,14 +77,9 @@ static int register_attributes(void)
> ? ? ? ?const char *manufacturer_name2 = "ACME Weighing Scales";
> ? ? ? ?const char *serial1 = "237495-3282-A";
> ? ? ? ?const char *serial2 = "11267-2327A00239";
> - ? ? ? const unsigned char char_weight_uuid[] = { 0x80, 0x88, 0xF2, 0x18, 0x90,
> - ? ? ? ? ? ? ? 0x2C, 0x45, 0x0B, 0xB6, 0xC4, 0x62, 0x89, 0x1E, 0x8C, 0x25,
> - ? ? ? ? ? ? ? 0xE9 };
> - ? ? ? const unsigned char prim_weight_uuid[] = { 0x4F, 0x0A, 0xC0, 0x96, 0x35,
> - ? ? ? ? ? ? ? 0xD4, 0x49, 0x11, 0x96, 0x31, 0xDE, 0xA8, 0xDC, 0x74, 0xEE,
> - ? ? ? ? ? ? ? 0xFE };
> ? ? ? ?uint8_t atval[256];
> ? ? ? ?uuid_t uuid;
> + ? ? ? uint128_t h128;
> ? ? ? ?int len;
>
> ? ? ? ?/* Battery state service: primary service definition */
> @@ -260,7 +263,8 @@ static int register_attributes(void)
>
> ? ? ? ?/* Weight service: primary service definition */
> ? ? ? ?sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
> - ? ? ? memcpy(atval, prim_weight_uuid, 16);
> + ? ? ? ntoh128(PRIM_WEIGHT_UUID, &h128);
> + ? ? ? att_put_u128(h128, atval);
> ? ? ? ?attrib_db_add(0x0680, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 16);
>
> ? ? ? ?/* Weight: include */
> @@ -274,11 +278,12 @@ static int register_attributes(void)
> ? ? ? ?sdp_uuid16_create(&uuid, GATT_CHARAC_UUID);
> ? ? ? ?atval[0] = ATT_CHAR_PROPER_READ;
> ? ? ? ?att_put_u16(0x0683, &atval[1]);
> - ? ? ? memcpy(&atval[3], char_weight_uuid, 16);

You missed a "ntoh128(CHAR_WEIGHT_UUID, &h128);" right here.

> + ? ? ? att_put_u128(h128, &atval[3]);
> ? ? ? ?attrib_db_add(0x0682, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 19);
>
> ? ? ? ?/* Weight: characteristic value */
> - ? ? ? sdp_uuid128_create(&uuid, char_weight_uuid);
> + ? ? ? ntoh128(CHAR_WEIGHT_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&uuid, &h128);
> ? ? ? ?atval[0] = 0x82;
> ? ? ? ?atval[1] = 0x55;
> ? ? ? ?atval[2] = 0x00;
> --
> 1.7.4.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at ?http://vger.kernel.org/majordomo-info.html
>


Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-19 00:57:30

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 10/14] Create UUID128 on host order on sdptool

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> Converts from network to host order UUID128 values before to call
> sdp_uuid128_create function. Internally, SDP library now stores the
> UUID128 values on host order.
> ---
> ?tools/sdptool.c | ? 36 +++++++++++++++++++++++++++---------
> ?1 files changed, 27 insertions(+), 9 deletions(-)
>
> diff --git a/tools/sdptool.c b/tools/sdptool.c
> index ae56ebf..55e5dab 100644
> --- a/tools/sdptool.c
> +++ b/tools/sdptool.c
> @@ -3022,6 +3022,7 @@ static int add_sr1(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?sdp_record_t record;
> ? ? ? ?sdp_list_t *root, *svclass;
> ? ? ? ?uuid_t root_uuid, svclass_uuid;
> + ? ? ? uint128_t h128;
>
> ? ? ? ?memset(&record, 0, sizeof(record));
> ? ? ? ?record.handle = si->handle;
> @@ -3030,7 +3031,8 @@ static int add_sr1(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?root = sdp_list_append(NULL, &root_uuid);
> ? ? ? ?sdp_set_browse_groups(&record, root);
>
> - ? ? ? sdp_uuid128_create(&svclass_uuid, SR1_UUID);
> + ? ? ? ntoh128(SR1_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&svclass_uuid, &h128);
> ? ? ? ?svclass = sdp_list_append(NULL, &svclass_uuid);
> ? ? ? ?sdp_set_service_classes(&record, svclass);
>
> @@ -3061,6 +3063,7 @@ static int add_syncml(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?sdp_list_t *root, *svclass, *proto;
> ? ? ? ?uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid;
> ? ? ? ?uint8_t channel = si->channel ? si->channel: 15;
> + ? ? ? uint128_t h128;
>
> ? ? ? ?memset(&record, 0, sizeof(record));
> ? ? ? ?record.handle = si->handle;
> @@ -3069,7 +3072,8 @@ static int add_syncml(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?root = sdp_list_append(NULL, &root_uuid);
> ? ? ? ?sdp_set_browse_groups(&record, root);
>
> - ? ? ? sdp_uuid128_create(&svclass_uuid, SYNCMLC_UUID);
> + ? ? ? ntoh128(SYNCMLC_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&svclass_uuid, &h128);
> ? ? ? ?svclass = sdp_list_append(NULL, &svclass_uuid);
> ? ? ? ?sdp_set_service_classes(&record, svclass);
>
> @@ -3107,6 +3111,7 @@ static int add_activesync(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?sdp_list_t *root, *svclass, *proto;
> ? ? ? ?uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid;
> ? ? ? ?uint8_t channel = si->channel ? si->channel: 21;
> + ? ? ? uint128_t h128;
>
> ? ? ? ?memset(&record, 0, sizeof(record));
> ? ? ? ?record.handle = si->handle;
> @@ -3124,7 +3129,8 @@ static int add_activesync(sdp_session_t *session, svc_info_t *si)
>
> ? ? ? ?sdp_set_access_protos(&record, sdp_list_append(NULL, proto));
>
> - ? ? ? sdp_uuid128_create(&svclass_uuid, ASYNC_UUID);
> + ? ? ? ntoh128(ASYNC_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&svclass_uuid, &h128);
> ? ? ? ?svclass = sdp_list_append(NULL, &svclass_uuid);
> ? ? ? ?sdp_set_service_classes(&record, svclass);
>
> @@ -3150,6 +3156,7 @@ static int add_hotsync(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?sdp_list_t *root, *svclass, *proto;
> ? ? ? ?uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid;
> ? ? ? ?uint8_t channel = si->channel ? si->channel: 22;
> + ? ? ? uint128_t h128;
>
> ? ? ? ?memset(&record, 0, sizeof(record));
> ? ? ? ?record.handle = si->handle;
> @@ -3167,7 +3174,8 @@ static int add_hotsync(sdp_session_t *session, svc_info_t *si)
>
> ? ? ? ?sdp_set_access_protos(&record, sdp_list_append(NULL, proto));
>
> - ? ? ? sdp_uuid128_create(&svclass_uuid, HOTSYNC_UUID);
> + ? ? ? ntoh128(HOTSYNC_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&svclass_uuid, &h128);
> ? ? ? ?svclass = sdp_list_append(NULL, &svclass_uuid);
> ? ? ? ?sdp_set_service_classes(&record, svclass);
>
> @@ -3192,6 +3200,7 @@ static int add_palmos(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?sdp_record_t record;
> ? ? ? ?sdp_list_t *root, *svclass;
> ? ? ? ?uuid_t root_uuid, svclass_uuid;
> + ? ? ? uint128_t h128;
>
> ? ? ? ?memset(&record, 0, sizeof(record));
> ? ? ? ?record.handle = si->handle;
> @@ -3200,7 +3209,8 @@ static int add_palmos(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?root = sdp_list_append(NULL, &root_uuid);
> ? ? ? ?sdp_set_browse_groups(&record, root);
>
> - ? ? ? sdp_uuid128_create(&svclass_uuid, PALMOS_UUID);
> + ? ? ? ntoh128(PALMOS_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&svclass_uuid, &h128);
> ? ? ? ?svclass = sdp_list_append(NULL, &svclass_uuid);
> ? ? ? ?sdp_set_service_classes(&record, svclass);
>
> @@ -3225,6 +3235,7 @@ static int add_nokiaid(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?uuid_t root_uuid, svclass_uuid;
> ? ? ? ?uint16_t verid = 0x005f;
> ? ? ? ?sdp_data_t *version = sdp_data_alloc(SDP_UINT16, &verid);
> + ? ? ? uint128_t h128;
>
> ? ? ? ?memset(&record, 0, sizeof(record));
> ? ? ? ?record.handle = si->handle;
> @@ -3233,7 +3244,8 @@ static int add_nokiaid(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?root = sdp_list_append(NULL, &root_uuid);
> ? ? ? ?sdp_set_browse_groups(&record, root);
>
> - ? ? ? sdp_uuid128_create(&svclass_uuid, NOKID_UUID);
> + ? ? ? ntoh128(NOKID_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&svclass_uuid, &h128);
> ? ? ? ?svclass = sdp_list_append(NULL, &svclass_uuid);
> ? ? ? ?sdp_set_service_classes(&record, svclass);
>
> @@ -3260,6 +3272,7 @@ static int add_pcsuite(sdp_session_t *session, svc_info_t *si)
> ? ? ? ?sdp_list_t *root, *svclass, *proto;
> ? ? ? ?uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid;
> ? ? ? ?uint8_t channel = si->channel ? si->channel: 14;
> + ? ? ? uint128_t h128;
>
> ? ? ? ?memset(&record, 0, sizeof(record));
> ? ? ? ?record.handle = si->handle;
> @@ -3277,7 +3290,8 @@ static int add_pcsuite(sdp_session_t *session, svc_info_t *si)
>
> ? ? ? ?sdp_set_access_protos(&record, sdp_list_append(NULL, proto));
>
> - ? ? ? sdp_uuid128_create(&svclass_uuid, PCSUITE_UUID);
> + ? ? ? ntoh128(PCSUITE_UUID, &h128);
> + ? ? ? sdp_uuid128_create(&svclass_uuid, &h128);
> ? ? ? ?svclass = sdp_list_append(NULL, &svclass_uuid);
> ? ? ? ?sdp_set_service_classes(&record, svclass);
>
> @@ -4004,8 +4018,12 @@ static int cmd_search(int argc, char **argv)
> ? ? ? ? ? ? ? ? ? ? ? ?uint16_t class16 = class & 0xffff;
> ? ? ? ? ? ? ? ? ? ? ? ?sdp_uuid16_create(&context.group, class16);
> ? ? ? ? ? ? ? ?}
> - ? ? ? } else
> - ? ? ? ? ? ? ? sdp_uuid128_create(&context.group, &n128);
> + ? ? ? } else {
> + ? ? ? ? ? ? ? uint128_t h128;
> +
> + ? ? ? ? ? ? ? ntoh128(n128, &h128);
> + ? ? ? ? ? ? ? sdp_uuid128_create(&context.group, &h128);
> + ? ? ? }

Just to note that on this patch it is now correct to use &h128, as
h128 is not a pointer. Only the "intermediary" patch that is
incorrect.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-19 00:53:03

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 05/14] Convert to network order before use it on sdp_uuid128_to_uuid

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> ---
> ?lib/sdp.c | ? ?7 ++++---
> ?1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/lib/sdp.c b/lib/sdp.c
> index d5f8984..3c4cd50 100644
> --- a/lib/sdp.c
> +++ b/lib/sdp.c
> @@ -2713,18 +2713,19 @@ uuid_t *sdp_uuid_to_uuid128(const uuid_t *uuid)
> ?int sdp_uuid128_to_uuid(uuid_t *uuid)
> ?{
> ? ? ? ?uint128_t *b = &bluetooth_base_uuid;
> - ? ? ? uint128_t *u = &uuid->value.uuid128;
> + ? ? ? uint128_t u;
> ? ? ? ?uint32_t data;
> ? ? ? ?unsigned int i;
>
> + ? ? ? hton128(&uuid->value.uuid128, &u);
> ? ? ? ?if (uuid->type != SDP_UUID128)
> ? ? ? ? ? ? ? ?return 1;
>
> ? ? ? ?for (i = 4; i < sizeof(b->data); i++)
> - ? ? ? ? ? ? ? if (b->data[i] != u->data[i])
> + ? ? ? ? ? ? ? if (b->data[i] != u.data[i])
> ? ? ? ? ? ? ? ? ? ? ? ?return 0;
>
> - ? ? ? memcpy(&data, u->data, 4);
> + ? ? ? memcpy(&data, u.data, 4);
> ? ? ? ?data = htonl(data);
> ? ? ? ?if (data <= 0xffff) {
> ? ? ? ? ? ? ? ?uuid->type = SDP_UUID16;

As we discussed off-line, there might be a bug on the original code.
Using htonl() (instead of ntohl()) on data that comes from a 128-bit
UUID looks suspicious.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-19 00:50:19

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 09/14] Replace UUID128 values from char array to uint128_t on sdptool

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> @@ -3992,7 +4005,7 @@ static int cmd_search(int argc, char **argv)
> ? ? ? ? ? ? ? ? ? ? ? ?sdp_uuid16_create(&context.group, class16);
> ? ? ? ? ? ? ? ?}
> ? ? ? ?} else
> - ? ? ? ? ? ? ? sdp_uuid128_create(&context.group, uuid);
> + ? ? ? ? ? ? ? sdp_uuid128_create(&context.group, &n128);

I think you meant "n128" instead of "&n128" here.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-18 23:51:51

by Elvis Pfutzenreuter

[permalink] [raw]
Subject: Re: [RFC v2 00/14] Store UUID-128 on host order


On Feb 18, 2011, at 8:29 PM, Claudio Takahasi wrote:

> It must NOT be included in the next release until proper testing.
>
> Any good soul wants to test it if I am not breaking SDP?

I volunteer for that if you give me some time.

>
> The following patches convert the internal UUID128 values representation
> to host order. Currently, SDP functions use host order to store UUID-16
> /UUID32 and network order to store UUID-128 values. The reason is to
> keep the consistency and re-use the UUID functions for ATT protocol
> which uses little endian.
>
> Changes from the first RFC:
> - Changes sdptool
> - Changes SDP XML parsing function
> - Changes attribute example
>
> Claudio Takahasi (14):
> Move 64 and 128 bits byte order functions to bluetooth.h
> Use host byte order when converting UUID16/32 to UUID128
> Add att_get_u128
> Convert UUID128 value to host order when extracting SDP data
> Convert to network order before use it on sdp_uuid128_to_uuid
> Convert from host to network order before to print UUID128 values
> Convert from network to host order on bt_string2uuid function
> Change UUID128 host order on SDP PDU generation function
> Replace UUID128 values from char array to uint128_t on sdptool
> Create UUID128 on host order on sdptool
> Change SDP XML parser to create UUID128 values on host order
> Convert from little endian to host order when parsing EIR data
> Add att_put_u128
> Change Attribute example to create UUID128 on host order
>
> attrib/att.c | 16 ++++--
> attrib/att.h | 17 ++++++
> attrib/example.c | 24 +++++---
> attrib/gatt.c | 14 +++--
> attrib/gatttool.c | 6 ++-
> attrib/interactive.c | 1 +
> health/hdp_manager.c | 1 +
> health/mcap_sync.c | 17 ------
> lib/bluetooth.h | 41 ++++++++++++++
> lib/sdp.c | 108 ++++++++++++++-----------------------
> lib/sdp.h | 4 --
> src/event.c | 6 +--
> src/glib-helper.c | 31 ++++++-----
> src/sdp-xml.c | 74 +++++++++++--------------
> test/hciemu.c | 16 ------
> tools/sdptool.c | 145 ++++++++++++++++++++++++++++++-------------------
> 16 files changed, 280 insertions(+), 241 deletions(-)
>
> --
> 1.7.4.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html


2011-02-18 22:50:33

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [RFC v2 02/14] Use host byte order when converting UUID16/32 to UUID128

Hi Claudio,

On Fri, Feb 18, 2011 at 7:29 PM, Claudio Takahasi
<[email protected]> wrote:
> @@ -2646,11 +2647,16 @@ void sdp_uuid16_to_uuid128(uuid_t *uuid128, const uuid_t *uuid16)
> ? ? ? ?data1 += htons(uuid16->value.uuid16);
>
> ? ? ? ?/* set bytes 2 and 3 of the 128 bit value */
> - ? ? ? memcpy(&uuid128->value.uuid128.data[2], &data1, 2);
> + ? ? ? memcpy(&n128.data[2], &data1, 2);
> +
> + ? ? ? uuid128->type = SDP_UUID128;
> + ? ? ? ntoh128(&n128, &uuid128->value.uuid128);
> ?}

For consistency with patch 4/14, what about declaring a "uint128_t
h128" and using:

ntoh128(&n128, &h128);
sdp_uuid128_create(uuid128, &h128);

> @@ -2668,7 +2673,10 @@ void sdp_uuid32_to_uuid128(uuid_t *uuid128, const uuid_t *uuid32)
> ? ? ? ?data0 += htonl(uuid32->value.uuid32);
>
> ? ? ? ?/* set the 4 bytes of the 128 bit value */
> - ? ? ? memcpy(&uuid128->value.uuid128.data[0], &data0, 4);
> + ? ? ? memcpy(&n128.data[0], &data0, 4);
> +
> + ? ? ? uuid128->type = SDP_UUID128;
> + ? ? ? ntoh128(&n128, &uuid128->value.uuid128);
> ?}

Same here. Note this is just a suggestion for better readability, the
behavior is unchanged compared to your current patch.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

2011-02-18 22:29:30

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 11/14] Change SDP XML parser to create UUID128 values on host order

---
src/sdp-xml.c | 73 +++++++++++++++++++++++++--------------------------------
1 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index 48a3808..9c029d6 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -46,6 +46,7 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
void *data, void (*appender)(void *, const char *))
{
int i, hex;
+ uint128_t n128;
char buf[STRBUFSIZE];
char indent[MAXINDENT];
char next_indent[MAXINDENT];
@@ -116,9 +117,10 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
appender(data, indent);
appender(data, "<uint128 value=\"");

+ hton128(&value->val.uint128, &n128);
for (i = 0; i < 16; i++) {
sprintf(&buf[i * 2], "%02x",
- (unsigned char) value->val.uint128.data[i]);
+ (unsigned char) n128.data[i]);
}

appender(data, buf);
@@ -161,9 +163,10 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
appender(data, indent);
appender(data, "<int128 value=\"");

+ hton128(&value->val.uint128, &n128);
for (i = 0; i < 16; i++) {
sprintf(&buf[i * 2], "%02x",
- (unsigned char) value->val.int128.data[i]);
+ (unsigned char) n128.data[i]);
}
appender(data, buf);

@@ -190,40 +193,26 @@ static void convert_raw_data_to_xml(sdp_data_t *value, int indent_level,
appender(data, indent);
appender(data, "<uuid value=\"");

+ hton128(&value->val.uint128, &n128);
+
snprintf(buf, STRBUFSIZE - 1,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
- (unsigned char) value->val.uuid.value.
- uuid128.data[0],
- (unsigned char) value->val.uuid.value.
- uuid128.data[1],
- (unsigned char) value->val.uuid.value.
- uuid128.data[2],
- (unsigned char) value->val.uuid.value.
- uuid128.data[3],
- (unsigned char) value->val.uuid.value.
- uuid128.data[4],
- (unsigned char) value->val.uuid.value.
- uuid128.data[5],
- (unsigned char) value->val.uuid.value.
- uuid128.data[6],
- (unsigned char) value->val.uuid.value.
- uuid128.data[7],
- (unsigned char) value->val.uuid.value.
- uuid128.data[8],
- (unsigned char) value->val.uuid.value.
- uuid128.data[9],
- (unsigned char) value->val.uuid.value.
- uuid128.data[10],
- (unsigned char) value->val.uuid.value.
- uuid128.data[11],
- (unsigned char) value->val.uuid.value.
- uuid128.data[12],
- (unsigned char) value->val.uuid.value.
- uuid128.data[13],
- (unsigned char) value->val.uuid.value.
- uuid128.data[14],
- (unsigned char) value->val.uuid.value.
- uuid128.data[15]);
+ (unsigned char) n128.data[0],
+ (unsigned char) n128.data[1],
+ (unsigned char) n128.data[2],
+ (unsigned char) n128.data[3],
+ (unsigned char) n128.data[4],
+ (unsigned char) n128.data[5],
+ (unsigned char) n128.data[6],
+ (unsigned char) n128.data[7],
+ (unsigned char) n128.data[8],
+ (unsigned char) n128.data[9],
+ (unsigned char) n128.data[10],
+ (unsigned char) n128.data[11],
+ (unsigned char) n128.data[12],
+ (unsigned char) n128.data[13],
+ (unsigned char) n128.data[14],
+ (unsigned char) n128.data[15]);

appender(data, buf);
appender(data, "\" />\n");
@@ -417,12 +406,12 @@ void convert_sdp_record_to_xml(sdp_record_t *rec,

static sdp_data_t *sdp_xml_parse_uuid128(const char *data)
{
- uint128_t val;
+ uint128_t n128, h128;
unsigned int i, j;

char buf[3];

- memset(&val, 0, sizeof(val));
+ memset(&n128, 0, sizeof(n128));

buf[2] = '\0';

@@ -435,11 +424,12 @@ static sdp_data_t *sdp_xml_parse_uuid128(const char *data)
buf[0] = data[i];
buf[1] = data[i + 1];

- val.data[j++] = strtoul(buf, 0, 16);
+ n128.data[j++] = strtoul(buf, 0, 16);
i += 2;
}

- return sdp_data_alloc(SDP_UUID128, &val);
+ ntoh128(&n128, &h128);
+ return sdp_data_alloc(SDP_UUID128, &h128);
}

sdp_data_t *sdp_xml_parse_uuid(const char *data, sdp_record_t *record)
@@ -603,7 +593,7 @@ sdp_data_t *sdp_xml_parse_int(const char * data, uint8_t dtd)
case SDP_INT128:
case SDP_UINT128:
{
- uint128_t val;
+ uint128_t n128, h128;
int i = 0;
char buf[3];

@@ -613,10 +603,11 @@ sdp_data_t *sdp_xml_parse_int(const char * data, uint8_t dtd)
buf[0] = data[i];
buf[1] = data[i + 1];

- val.data[i >> 1] = strtoul(buf, 0, 16);
+ n128.data[i >> 1] = strtoul(buf, 0, 16);
}

- ret = sdp_data_alloc(dtd, &val);
+ ntoh128(&n128, &h128);
+ ret = sdp_data_alloc(dtd, &h128);
break;
}

--
1.7.4.1


2011-02-18 22:29:33

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 14/14] Change Attribute example to create UUID128 on host order

---
attrib/example.c | 23 ++++++++++++++---------
1 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/attrib/example.c b/attrib/example.c
index f5fcf1b..6e39a68 100644
--- a/attrib/example.c
+++ b/attrib/example.c
@@ -60,6 +60,14 @@
#define FMT_KILOGRAM_UUID 0xA010
#define FMT_HANGING_UUID 0xA011

+#define CHAR_WEIGHT_UUID (&(uint128_t) {{ \
+ 0x80, 0x88, 0xF2, 0x18, 0x90, 0x2C, 0x45, 0x0B, \
+ 0xB6, 0xC4, 0x62, 0x89, 0x1E, 0x8C, 0x25, 0xE9 }})
+
+#define PRIM_WEIGHT_UUID (&(uint128_t) {{ \
+ 0x4F, 0x0A, 0xC0, 0x96, 0x35, 0xD4, 0x49, 0x11, \
+ 0x96, 0x31, 0xDE, 0xA8, 0xDC, 0x74, 0xEE, 0xFE }})
+
static int register_attributes(void)
{
const char *desc_out_temp = "Outside Temperature";
@@ -69,14 +77,9 @@ static int register_attributes(void)
const char *manufacturer_name2 = "ACME Weighing Scales";
const char *serial1 = "237495-3282-A";
const char *serial2 = "11267-2327A00239";
- const unsigned char char_weight_uuid[] = { 0x80, 0x88, 0xF2, 0x18, 0x90,
- 0x2C, 0x45, 0x0B, 0xB6, 0xC4, 0x62, 0x89, 0x1E, 0x8C, 0x25,
- 0xE9 };
- const unsigned char prim_weight_uuid[] = { 0x4F, 0x0A, 0xC0, 0x96, 0x35,
- 0xD4, 0x49, 0x11, 0x96, 0x31, 0xDE, 0xA8, 0xDC, 0x74, 0xEE,
- 0xFE };
uint8_t atval[256];
uuid_t uuid;
+ uint128_t h128;
int len;

/* Battery state service: primary service definition */
@@ -260,7 +263,8 @@ static int register_attributes(void)

/* Weight service: primary service definition */
sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- memcpy(atval, prim_weight_uuid, 16);
+ ntoh128(PRIM_WEIGHT_UUID, &h128);
+ att_put_u128(h128, atval);
attrib_db_add(0x0680, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 16);

/* Weight: include */
@@ -274,11 +278,12 @@ static int register_attributes(void)
sdp_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
att_put_u16(0x0683, &atval[1]);
- memcpy(&atval[3], char_weight_uuid, 16);
+ att_put_u128(h128, &atval[3]);
attrib_db_add(0x0682, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 19);

/* Weight: characteristic value */
- sdp_uuid128_create(&uuid, char_weight_uuid);
+ ntoh128(CHAR_WEIGHT_UUID, &h128);
+ sdp_uuid128_create(&uuid, &h128);
atval[0] = 0x82;
atval[1] = 0x55;
atval[2] = 0x00;
--
1.7.4.1


2011-02-18 22:29:32

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 13/14] Add att_put_u128

ATT protocol uses little endian byte order, before to add a UUID128
value in the PDU it needs to converted from host order to little endian.
---
attrib/att.c | 4 ++--
attrib/att.h | 7 +++++++
2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index 78ee254..d5374fc 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -115,7 +115,7 @@ uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, uuid_t *uuid,
if (uuid->type == SDP_UUID16)
att_put_u16(uuid->value.uuid16, &pdu[5]);
else
- memcpy(&pdu[5], &uuid->value.uuid128, length);
+ att_put_u128(uuid->value.uuid128, &pdu[5]);

return min_len + length;
}
@@ -345,7 +345,7 @@ uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, uuid_t *uuid,
if (uuid->type == SDP_UUID16)
att_put_u16(uuid->value.uuid16, &pdu[5]);
else
- memcpy(&pdu[5], &uuid->value.uuid128, length);
+ att_put_u128(uuid->value.uuid128, &pdu[5]);

return min_len + length;
}
diff --git a/attrib/att.h b/attrib/att.h
index 49788eb..c7766c8 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -195,6 +195,13 @@ static inline void att_put_u32(uint32_t src, void *dst)
bt_put_unaligned(htobl(src), (uint32_t *) dst);
}

+static inline void att_put_u128(uint128_t src, void *dst)
+{
+ uint128_t *d128 = dst;
+
+ htob128(&src, d128);
+}
+
void att_data_list_free(struct att_data_list *list);

const char *att_ecode2str(uint8_t status);
--
1.7.4.1


2011-02-18 22:29:31

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 12/14] Convert from little endian to host order when parsing EIR data

EIR data uses little endian format, UUID128 values needs to be
converted to host order before to use it on SDP library functions.
---
src/event.c | 6 +-----
1 files changed, 1 insertions(+), 5 deletions(-)

diff --git a/src/event.c b/src/event.c
index 12dbca2..87e96dd 100644
--- a/src/event.c
+++ b/src/event.c
@@ -361,11 +361,7 @@ static int parse_eir_data(struct eir_data *eir, uint8_t *eir_data,

service.type = SDP_UUID128;
for (i = uuid32_count + uuid16_count; i < total; i++) {
- int k;
-
- for (k = 0; k < 16; k++)
- service.value.uuid128.data[k] = uuid128[16 - k - 1];
-
+ btoh128((uint128_t *) uuid128, &service.value.uuid128);
uuid_str = bt_uuid2string(&service);
eir->services = g_slist_append(eir->services, uuid_str);
uuid128 += 16;
--
1.7.4.1


2011-02-18 22:29:29

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 10/14] Create UUID128 on host order on sdptool

Converts from network to host order UUID128 values before to call
sdp_uuid128_create function. Internally, SDP library now stores the
UUID128 values on host order.
---
tools/sdptool.c | 36 +++++++++++++++++++++++++++---------
1 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/tools/sdptool.c b/tools/sdptool.c
index ae56ebf..55e5dab 100644
--- a/tools/sdptool.c
+++ b/tools/sdptool.c
@@ -3022,6 +3022,7 @@ static int add_sr1(sdp_session_t *session, svc_info_t *si)
sdp_record_t record;
sdp_list_t *root, *svclass;
uuid_t root_uuid, svclass_uuid;
+ uint128_t h128;

memset(&record, 0, sizeof(record));
record.handle = si->handle;
@@ -3030,7 +3031,8 @@ static int add_sr1(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, SR1_UUID);
+ ntoh128(SR1_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3061,6 +3063,7 @@ static int add_syncml(sdp_session_t *session, svc_info_t *si)
sdp_list_t *root, *svclass, *proto;
uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid, obex_uuid;
uint8_t channel = si->channel ? si->channel: 15;
+ uint128_t h128;

memset(&record, 0, sizeof(record));
record.handle = si->handle;
@@ -3069,7 +3072,8 @@ static int add_syncml(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, SYNCMLC_UUID);
+ ntoh128(SYNCMLC_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3107,6 +3111,7 @@ static int add_activesync(sdp_session_t *session, svc_info_t *si)
sdp_list_t *root, *svclass, *proto;
uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid;
uint8_t channel = si->channel ? si->channel: 21;
+ uint128_t h128;

memset(&record, 0, sizeof(record));
record.handle = si->handle;
@@ -3124,7 +3129,8 @@ static int add_activesync(sdp_session_t *session, svc_info_t *si)

sdp_set_access_protos(&record, sdp_list_append(NULL, proto));

- sdp_uuid128_create(&svclass_uuid, ASYNC_UUID);
+ ntoh128(ASYNC_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3150,6 +3156,7 @@ static int add_hotsync(sdp_session_t *session, svc_info_t *si)
sdp_list_t *root, *svclass, *proto;
uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid;
uint8_t channel = si->channel ? si->channel: 22;
+ uint128_t h128;

memset(&record, 0, sizeof(record));
record.handle = si->handle;
@@ -3167,7 +3174,8 @@ static int add_hotsync(sdp_session_t *session, svc_info_t *si)

sdp_set_access_protos(&record, sdp_list_append(NULL, proto));

- sdp_uuid128_create(&svclass_uuid, HOTSYNC_UUID);
+ ntoh128(HOTSYNC_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3192,6 +3200,7 @@ static int add_palmos(sdp_session_t *session, svc_info_t *si)
sdp_record_t record;
sdp_list_t *root, *svclass;
uuid_t root_uuid, svclass_uuid;
+ uint128_t h128;

memset(&record, 0, sizeof(record));
record.handle = si->handle;
@@ -3200,7 +3209,8 @@ static int add_palmos(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, PALMOS_UUID);
+ ntoh128(PALMOS_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3225,6 +3235,7 @@ static int add_nokiaid(sdp_session_t *session, svc_info_t *si)
uuid_t root_uuid, svclass_uuid;
uint16_t verid = 0x005f;
sdp_data_t *version = sdp_data_alloc(SDP_UINT16, &verid);
+ uint128_t h128;

memset(&record, 0, sizeof(record));
record.handle = si->handle;
@@ -3233,7 +3244,8 @@ static int add_nokiaid(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, NOKID_UUID);
+ ntoh128(NOKID_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3260,6 +3272,7 @@ static int add_pcsuite(sdp_session_t *session, svc_info_t *si)
sdp_list_t *root, *svclass, *proto;
uuid_t root_uuid, svclass_uuid, l2cap_uuid, rfcomm_uuid;
uint8_t channel = si->channel ? si->channel: 14;
+ uint128_t h128;

memset(&record, 0, sizeof(record));
record.handle = si->handle;
@@ -3277,7 +3290,8 @@ static int add_pcsuite(sdp_session_t *session, svc_info_t *si)

sdp_set_access_protos(&record, sdp_list_append(NULL, proto));

- sdp_uuid128_create(&svclass_uuid, PCSUITE_UUID);
+ ntoh128(PCSUITE_UUID, &h128);
+ sdp_uuid128_create(&svclass_uuid, &h128);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -4004,8 +4018,12 @@ static int cmd_search(int argc, char **argv)
uint16_t class16 = class & 0xffff;
sdp_uuid16_create(&context.group, class16);
}
- } else
- sdp_uuid128_create(&context.group, &n128);
+ } else {
+ uint128_t h128;
+
+ ntoh128(n128, &h128);
+ sdp_uuid128_create(&context.group, &h128);
+ }

if (has_addr)
return do_search(&bdaddr, &context);
--
1.7.4.1


2011-02-18 22:29:28

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 09/14] Replace UUID128 values from char array to uint128_t on sdptool

This patch doesn't change the UUID128 endianness on sdptool, it is only
the initial patch to convert from network to host order on sdptool.
---
tools/sdptool.c | 111 ++++++++++++++++++++++++++++++------------------------
1 files changed, 62 insertions(+), 49 deletions(-)

diff --git a/tools/sdptool.c b/tools/sdptool.c
index 341e258..ae56ebf 100644
--- a/tools/sdptool.c
+++ b/tools/sdptool.c
@@ -3013,8 +3013,9 @@ static int add_udi_te(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char sr1_uuid[] = { 0xbc, 0x19, 0x9c, 0x24, 0x95, 0x8b, 0x4c, 0xc0,
- 0xa2, 0xcb, 0xfd, 0x8a, 0x30, 0xbf, 0x32, 0x06 };
+#define SR1_UUID (&(uint128_t) {{ \
+ 0xbc, 0x19, 0x9c, 0x24, 0x95, 0x8b, 0x4c, 0xc0, \
+ 0xa2, 0xcb, 0xfd, 0x8a, 0x30, 0xbf, 0x32, 0x06 }})

static int add_sr1(sdp_session_t *session, svc_info_t *si)
{
@@ -3029,7 +3030,7 @@ static int add_sr1(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, (void *) sr1_uuid);
+ sdp_uuid128_create(&svclass_uuid, SR1_UUID);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3045,11 +3046,14 @@ static int add_sr1(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char syncmls_uuid[] = { 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x02 };
+#define SYNCMLS_UUID (&(uint128_t) {{ \
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x10, 0x00, \
+ 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x02 }})

-static unsigned char syncmlc_uuid[] = { 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x02 };
+
+#define SYNCMLC_UUID (&(uint128_t) {{ \
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x10, 0x00, \
+ 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x02 }})

static int add_syncml(sdp_session_t *session, svc_info_t *si)
{
@@ -3065,7 +3069,7 @@ static int add_syncml(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, (void *) syncmlc_uuid);
+ sdp_uuid128_create(&svclass_uuid, SYNCMLC_UUID);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3093,8 +3097,9 @@ static int add_syncml(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char async_uuid[] = { 0x03, 0x50, 0x27, 0x8F, 0x3D, 0xCA, 0x4E, 0x62,
- 0x83, 0x1D, 0xA4, 0x11, 0x65, 0xFF, 0x90, 0x6C };
+#define ASYNC_UUID (&(uint128_t) {{ \
+ 0x03, 0x50, 0x27, 0x8F, 0x3D, 0xCA, 0x4E, 0x62, \
+ 0x83, 0x1D, 0xA4, 0x11, 0x65, 0xFF, 0x90, 0x6C }})

static int add_activesync(sdp_session_t *session, svc_info_t *si)
{
@@ -3119,7 +3124,7 @@ static int add_activesync(sdp_session_t *session, svc_info_t *si)

sdp_set_access_protos(&record, sdp_list_append(NULL, proto));

- sdp_uuid128_create(&svclass_uuid, (void *) async_uuid);
+ sdp_uuid128_create(&svclass_uuid, ASYNC_UUID);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3135,8 +3140,9 @@ static int add_activesync(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char hotsync_uuid[] = { 0xD8, 0x0C, 0xF9, 0xEA, 0x13, 0x4C, 0x11, 0xD5,
- 0x83, 0xCE, 0x00, 0x30, 0x65, 0x7C, 0x54, 0x3C };
+#define HOTSYNC_UUID (&(uint128_t) {{ \
+ 0xD8, 0x0C, 0xF9, 0xEA, 0x13, 0x4C, 0x11, 0xD5, \
+ 0x83, 0xCE, 0x00, 0x30, 0x65, 0x7C, 0x54, 0x3C }})

static int add_hotsync(sdp_session_t *session, svc_info_t *si)
{
@@ -3161,7 +3167,7 @@ static int add_hotsync(sdp_session_t *session, svc_info_t *si)

sdp_set_access_protos(&record, sdp_list_append(NULL, proto));

- sdp_uuid128_create(&svclass_uuid, (void *) hotsync_uuid);
+ sdp_uuid128_create(&svclass_uuid, HOTSYNC_UUID);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3177,8 +3183,9 @@ static int add_hotsync(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char palmos_uuid[] = { 0xF5, 0xBE, 0xB6, 0x51, 0x41, 0x71, 0x40, 0x51,
- 0xAC, 0xF5, 0x6C, 0xA7, 0x20, 0x22, 0x42, 0xF0 };
+#define PALMOS_UUID (&(uint128_t) {{ \
+ 0xF5, 0xBE, 0xB6, 0x51, 0x41, 0x71, 0x40, 0x51, \
+ 0xAC, 0xF5, 0x6C, 0xA7, 0x20, 0x22, 0x42, 0xF0 }})

static int add_palmos(sdp_session_t *session, svc_info_t *si)
{
@@ -3193,7 +3200,7 @@ static int add_palmos(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, (void *) palmos_uuid);
+ sdp_uuid128_create(&svclass_uuid, PALMOS_UUID);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3207,8 +3214,9 @@ static int add_palmos(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char nokid_uuid[] = { 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 };
+#define NOKID_UUID (&(uint128_t) {{ \
+ 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x10, 0x00, \
+ 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 }})

static int add_nokiaid(sdp_session_t *session, svc_info_t *si)
{
@@ -3225,7 +3233,7 @@ static int add_nokiaid(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_uuid128_create(&svclass_uuid, (void *) nokid_uuid);
+ sdp_uuid128_create(&svclass_uuid, NOKID_UUID);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3242,8 +3250,9 @@ static int add_nokiaid(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char pcsuite_uuid[] = { 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 };
+#define PCSUITE_UUID (&(uint128_t) {{ \
+ 0x00, 0x00, 0x50, 0x02, 0x00, 0x00, 0x10, 0x00, \
+ 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 }})

static int add_pcsuite(sdp_session_t *session, svc_info_t *si)
{
@@ -3268,7 +3277,7 @@ static int add_pcsuite(sdp_session_t *session, svc_info_t *si)

sdp_set_access_protos(&record, sdp_list_append(NULL, proto));

- sdp_uuid128_create(&svclass_uuid, (void *) pcsuite_uuid);
+ sdp_uuid128_create(&svclass_uuid, PCSUITE_UUID);
svclass = sdp_list_append(NULL, &svclass_uuid);
sdp_set_service_classes(&record, svclass);

@@ -3284,17 +3293,21 @@ static int add_pcsuite(sdp_session_t *session, svc_info_t *si)
return 0;
}

-static unsigned char nftp_uuid[] = { 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 };
+#define NFTP_UUID (&(uint128_t) {{ \
+ 0x00, 0x00, 0x50, 0x05, 0x00, 0x00, 0x10, 0x00, \
+ 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 }})

-static unsigned char nsyncml_uuid[] = { 0x00, 0x00, 0x56, 0x01, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 };
+#define NSYNCML_UUID (&(uint128_t) {{ \
+ 0x00, 0x00, 0x56, 0x01, 0x00, 0x00, 0x10, 0x00, \
+ 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 }})

-static unsigned char ngage_uuid[] = { 0x00, 0x00, 0x13, 0x01, 0x00, 0x00, 0x10, 0x00,
- 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 };
+#define NGAGE_UUID (&(uint128_t) {{ \
+ 0x00, 0x00, 0x13, 0x01, 0x00, 0x00, 0x10, 0x00, \
+ 0x80, 0x00, 0x00, 0x02, 0xEE, 0x00, 0x00, 0x01 }})

-static unsigned char apple_uuid[] = { 0xf0, 0x72, 0x2e, 0x20, 0x0f, 0x8b, 0x4e, 0x90,
- 0x8c, 0xc2, 0x1b, 0x46, 0xf5, 0xf2, 0xef, 0xe2 };
+#define APPLE_UUID (&(uint128_t) {{ \
+ 0xf0, 0x72, 0x2e, 0x20, 0x0f, 0x8b, 0x4e, 0x90, \
+ 0x8c, 0xc2, 0x1b, 0x46, 0xf5, 0xf2, 0xef, 0xe2 }})

static int add_apple(sdp_session_t *session, svc_info_t *si)
{
@@ -3312,7 +3325,7 @@ static int add_apple(sdp_session_t *session, svc_info_t *si)
root = sdp_list_append(NULL, &root_uuid);
sdp_set_browse_groups(&record, root);

- sdp_attr_add_new(&record, 0x0780, SDP_UUID128, (void *) apple_uuid);
+ sdp_attr_add_new(&record, 0x0780, SDP_UUID128, (void *) APPLE_UUID);
sdp_attr_add_new(&record, 0x0781, SDP_TEXT_STR8, (void *) "Macmini");
sdp_attr_add_new(&record, 0x0782, SDP_TEXT_STR8, (void *) "PowerMac10,1");
sdp_attr_add_new(&record, 0x0783, SDP_UINT32, (void *) &attr783);
@@ -3497,7 +3510,7 @@ struct {
char *name;
uint32_t class;
int (*add)(sdp_session_t *sess, svc_info_t *si);
- unsigned char *uuid;
+ const uint128_t *uuid128;
} service[] = {
{ "DID", PNP_INFO_SVCLASS_ID, NULL, },

@@ -3537,18 +3550,18 @@ struct {

{ "SEMCHLA", 0x8e771301, add_semchla },

- { "SR1", 0, add_sr1, sr1_uuid },
- { "SYNCML", 0, add_syncml, syncmlc_uuid },
- { "SYNCMLSERV", 0, NULL, syncmls_uuid },
- { "ACTIVESYNC", 0, add_activesync, async_uuid },
- { "HOTSYNC", 0, add_hotsync, hotsync_uuid },
- { "PALMOS", 0, add_palmos, palmos_uuid },
- { "NOKID", 0, add_nokiaid, nokid_uuid },
- { "PCSUITE", 0, add_pcsuite, pcsuite_uuid },
- { "NFTP", 0, NULL, nftp_uuid },
- { "NSYNCML", 0, NULL, nsyncml_uuid },
- { "NGAGE", 0, NULL, ngage_uuid },
- { "APPLE", 0, add_apple, apple_uuid },
+ { "SR1", 0, add_sr1, SR1_UUID },
+ { "SYNCML", 0, add_syncml, SYNCMLC_UUID },
+ { "SYNCMLSERV", 0, NULL, SYNCMLS_UUID },
+ { "ACTIVESYNC", 0, add_activesync, ASYNC_UUID },
+ { "HOTSYNC", 0, add_hotsync, HOTSYNC_UUID },
+ { "PALMOS", 0, add_palmos, PALMOS_UUID },
+ { "NOKID", 0, add_nokiaid, NOKID_UUID },
+ { "PCSUITE", 0, add_pcsuite, PCSUITE_UUID },
+ { "NFTP", 0, NULL, NFTP_UUID },
+ { "NSYNCML", 0, NULL, NSYNCML_UUID },
+ { "NGAGE", 0, NULL, NGAGE_UUID },
+ { "APPLE", 0, add_apple, APPLE_UUID },

{ "ISYNC", APPLE_AGENT_SVCLASS_ID, add_isync, },
{ "GATT", GENERIC_ATTRIB_SVCLASS_ID, add_gatt, },
@@ -3921,7 +3934,7 @@ static const char *search_help =
static int cmd_search(int argc, char **argv)
{
struct search_context context;
- unsigned char *uuid = NULL;
+ const uint128_t *n128 = NULL;
uint32_t class = 0;
bdaddr_t bdaddr;
int has_addr = 0;
@@ -3975,10 +3988,10 @@ static int cmd_search(int argc, char **argv)
for (i = 0; service[i].name; i++)
if (strcasecmp(context.svc, service[i].name) == 0) {
class = service[i].class;
- uuid = service[i].uuid;
+ n128 = service[i].uuid128;
break;
}
- if (!class && !uuid) {
+ if (!class && !n128) {
printf("Unknown service %s\n", context.svc);
return -1;
}
@@ -3992,7 +4005,7 @@ static int cmd_search(int argc, char **argv)
sdp_uuid16_create(&context.group, class16);
}
} else
- sdp_uuid128_create(&context.group, uuid);
+ sdp_uuid128_create(&context.group, &n128);

if (has_addr)
return do_search(&bdaddr, &context);
--
1.7.4.1


2011-02-18 22:29:27

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 08/14] Change UUID128 host order on SDP PDU generation function

Converts from host to network order UUID128 values when generating
the SDP pdu. Before to send through the network, SDP 128 values
need to be converted to network order.
---
lib/sdp.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)

diff --git a/lib/sdp.c b/lib/sdp.c
index 75154e9..2846585 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -897,7 +897,8 @@ int sdp_gen_pdu(sdp_buf_t *buf, sdp_data_t *d)
src = (unsigned char *) &u32;
break;
case SDP_UUID128:
- src = (unsigned char *) &d->val.uuid.value.uuid128;
+ hton128(&d->val.uuid.value.uuid128, &u128);
+ src = (unsigned char *) &u128;
break;
default:
break;
--
1.7.4.1


2011-02-18 22:29:26

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 07/14] Convert from network to host order on bt_string2uuid function

UUID128 string values are given in network order and needs to be
converted to host order to keep the consistency.
---
src/glib-helper.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/glib-helper.c b/src/glib-helper.c
index 2b7e1b3..84f3380 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -515,7 +515,7 @@ int bt_string2uuid(uuid_t *uuid, const char *string)
if (is_uuid128(string) &&
sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
&data0, &data1, &data2, &data3, &data4, &data5) == 6) {
- uint8_t val[16];
+ uint128_t n128, h128;

data0 = g_htonl(data0);
data1 = g_htons(data1);
@@ -524,14 +524,15 @@ int bt_string2uuid(uuid_t *uuid, const char *string)
data4 = g_htonl(data4);
data5 = g_htons(data5);

- memcpy(&val[0], &data0, 4);
- memcpy(&val[4], &data1, 2);
- memcpy(&val[6], &data2, 2);
- memcpy(&val[8], &data3, 2);
- memcpy(&val[10], &data4, 4);
- memcpy(&val[14], &data5, 2);
+ memcpy(&n128.data[0], &data0, 4);
+ memcpy(&n128.data[4], &data1, 2);
+ memcpy(&n128.data[6], &data2, 2);
+ memcpy(&n128.data[8], &data3, 2);
+ memcpy(&n128.data[10], &data4, 4);
+ memcpy(&n128.data[14], &data5, 2);

- sdp_uuid128_create(uuid, val);
+ ntoh128(&n128, &h128);
+ sdp_uuid128_create(uuid, &h128);

return 0;
} else {
--
1.7.4.1


2011-02-18 22:29:25

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 06/14] Convert from host to network order before to print UUID128 values

UUID128 values are now stored on host order and need to be converted
to network order to be displayed properly.
---
lib/sdp.c | 30 +++++++++++++++++-------------
src/glib-helper.c | 14 ++++++++------
tools/sdptool.c | 16 +++++++++-------
3 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/lib/sdp.c b/lib/sdp.c
index 3c4cd50..75154e9 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -285,13 +285,15 @@ int sdp_uuid2strn(const uuid_t *uuid, char *str, size_t n)
unsigned short data3;
unsigned int data4;
unsigned short data5;
+ uint128_t n128;

- memcpy(&data0, &uuid->value.uuid128.data[0], 4);
- memcpy(&data1, &uuid->value.uuid128.data[4], 2);
- memcpy(&data2, &uuid->value.uuid128.data[6], 2);
- memcpy(&data3, &uuid->value.uuid128.data[8], 2);
- memcpy(&data4, &uuid->value.uuid128.data[10], 4);
- memcpy(&data5, &uuid->value.uuid128.data[14], 2);
+ hton128(&uuid->value.uuid128, &n128);
+ memcpy(&data0, &n128.data[0], 4);
+ memcpy(&data1, &n128.data[4], 2);
+ memcpy(&data2, &n128.data[6], 2);
+ memcpy(&data3, &n128.data[8], 2);
+ memcpy(&data4, &n128.data[10], 4);
+ memcpy(&data5, &n128.data[14], 2);

snprintf(str, n, "%.8x-%.4x-%.4x-%.4x-%.8x%.4x",
ntohl(data0), ntohs(data1),
@@ -333,13 +335,15 @@ void sdp_uuid_print(const uuid_t *uuid)
unsigned short data3;
unsigned int data4;
unsigned short data5;
-
- memcpy(&data0, &uuid->value.uuid128.data[0], 4);
- memcpy(&data1, &uuid->value.uuid128.data[4], 2);
- memcpy(&data2, &uuid->value.uuid128.data[6], 2);
- memcpy(&data3, &uuid->value.uuid128.data[8], 2);
- memcpy(&data4, &uuid->value.uuid128.data[10], 4);
- memcpy(&data5, &uuid->value.uuid128.data[14], 2);
+ uint128_t n128;
+
+ hton128(&uuid->value.uuid128, &n128);
+ memcpy(&data0, &n128.data[0], 4);
+ memcpy(&data1, &n128.data[4], 2);
+ memcpy(&data2, &n128.data[6], 2);
+ memcpy(&data3, &n128.data[8], 2);
+ memcpy(&data4, &n128.data[10], 4);
+ memcpy(&data5, &n128.data[14], 2);

SDPDBG(" uint128_t : 0x%.8x-", ntohl(data0));
SDPDBG("%.4x-", ntohs(data1));
diff --git a/src/glib-helper.c b/src/glib-helper.c
index 22c14e7..2b7e1b3 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -372,6 +372,7 @@ char *bt_uuid2string(uuid_t *uuid)
{
gchar *str;
uuid_t uuid128;
+ uint128_t n128;
unsigned int data0;
unsigned short data1;
unsigned short data2;
@@ -397,12 +398,13 @@ char *bt_uuid2string(uuid_t *uuid)
return NULL;
}

- memcpy(&data0, &uuid128.value.uuid128.data[0], 4);
- memcpy(&data1, &uuid128.value.uuid128.data[4], 2);
- memcpy(&data2, &uuid128.value.uuid128.data[6], 2);
- memcpy(&data3, &uuid128.value.uuid128.data[8], 2);
- memcpy(&data4, &uuid128.value.uuid128.data[10], 4);
- memcpy(&data5, &uuid128.value.uuid128.data[14], 2);
+ hton128(&uuid128.value.uuid128, &n128);
+ memcpy(&data0, &n128.data[0], 4);
+ memcpy(&data1, &n128.data[4], 2);
+ memcpy(&data2, &n128.data[6], 2);
+ memcpy(&data3, &n128.data[8], 2);
+ memcpy(&data4, &n128.data[10], 4);
+ memcpy(&data5, &n128.data[14], 2);

str = g_try_malloc0(MAX_LEN_UUID_STR);
if (!str)
diff --git a/tools/sdptool.c b/tools/sdptool.c
index 140a46a..341e258 100644
--- a/tools/sdptool.c
+++ b/tools/sdptool.c
@@ -389,13 +389,15 @@ static void sdp_uuid_printf(uuid_t *uuid, struct attrib_context *context, int in
unsigned short data3;
unsigned int data4;
unsigned short data5;
-
- memcpy(&data0, &uuid->value.uuid128.data[0], 4);
- memcpy(&data1, &uuid->value.uuid128.data[4], 2);
- memcpy(&data2, &uuid->value.uuid128.data[6], 2);
- memcpy(&data3, &uuid->value.uuid128.data[8], 2);
- memcpy(&data4, &uuid->value.uuid128.data[10], 4);
- memcpy(&data5, &uuid->value.uuid128.data[14], 2);
+ uint128_t n128;
+
+ hton128(&uuid->value.uuid128, &n128);
+ memcpy(&data0, &n128.data[0], 4);
+ memcpy(&data1, &n128.data[4], 2);
+ memcpy(&data2, &n128.data[6], 2);
+ memcpy(&data3, &n128.data[8], 2);
+ memcpy(&data4, &n128.data[10], 4);
+ memcpy(&data5, &n128.data[14], 2);

printf("%.*sUUID128 : 0x%.8x-%.4x-%.4x-%.4x-%.8x-%.4x\n",
indent, indent_spaces,
--
1.7.4.1


2011-02-18 22:29:24

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 05/14] Convert to network order before use it on sdp_uuid128_to_uuid

---
lib/sdp.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/lib/sdp.c b/lib/sdp.c
index d5f8984..3c4cd50 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -2713,18 +2713,19 @@ uuid_t *sdp_uuid_to_uuid128(const uuid_t *uuid)
int sdp_uuid128_to_uuid(uuid_t *uuid)
{
uint128_t *b = &bluetooth_base_uuid;
- uint128_t *u = &uuid->value.uuid128;
+ uint128_t u;
uint32_t data;
unsigned int i;

+ hton128(&uuid->value.uuid128, &u);
if (uuid->type != SDP_UUID128)
return 1;

for (i = 4; i < sizeof(b->data); i++)
- if (b->data[i] != u->data[i])
+ if (b->data[i] != u.data[i])
return 0;

- memcpy(&data, u->data, 4);
+ memcpy(&data, u.data, 4);
data = htonl(data);
if (data <= 0xffff) {
uuid->type = SDP_UUID16;
--
1.7.4.1


2011-02-18 22:29:23

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 04/14] Convert UUID128 value to host order when extracting SDP data

---
lib/sdp.c | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/lib/sdp.c b/lib/sdp.c
index af50a16..d5f8984 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -1031,11 +1031,16 @@ int sdp_uuid_extract(const uint8_t *p, int bufsize, uuid_t *uuid, int *scanned)
*scanned += sizeof(uint32_t);
p += sizeof(uint32_t);
} else {
+ uint128_t n128, h128;
+
if (bufsize < (int) sizeof(uint128_t)) {
SDPERR("Not enough room for 128-bit UUID");
return -1;
}
- sdp_uuid128_create(uuid, p);
+
+ memcpy(&n128, p, sizeof(uint128_t));
+ ntoh128(&n128, &h128);
+ sdp_uuid128_create(uuid, &h128);
*scanned += sizeof(uint128_t);
p += sizeof(uint128_t);
}
--
1.7.4.1


2011-02-18 22:29:22

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 03/14] Add att_get_u128

Function to convert 128-bits values from little endian to host
order. Different than SDP, ATT uses little endian format.
---
attrib/att.c | 12 ++++++++----
attrib/att.h | 10 ++++++++++
attrib/gatt.c | 13 ++++++++-----
attrib/gatttool.c | 6 ++++--
4 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index 3259fca..78ee254 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -141,8 +141,10 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, int len, uint16_t *start,
*end = att_get_u16(&pdu[3]);
if (len == min_len + 2)
sdp_uuid16_create(uuid, att_get_u16(&pdu[5]));
- else
- sdp_uuid128_create(uuid, &pdu[5]);
+ else {
+ uint128_t h128 = att_get_u128(&pdu[5]);
+ sdp_uuid128_create(uuid, &h128);
+ }

return len;
}
@@ -370,8 +372,10 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, int len, uint16_t *start,

if (len == min_len + 2)
sdp_uuid16_create(uuid, att_get_u16(&pdu[5]));
- else
- sdp_uuid128_create(uuid, &pdu[5]);
+ else {
+ uint128_t h128 = att_get_u128(&pdu[5]);
+ sdp_uuid128_create(uuid, &h128);
+ }

return len;
}
diff --git a/attrib/att.h b/attrib/att.h
index 7d9afeb..49788eb 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -170,6 +170,16 @@ static inline uint32_t att_get_u32(const void *ptr)
return btohl(bt_get_unaligned(u32_ptr));
}

+static inline uint128_t att_get_u128(const void *ptr)
+{
+ const uint128_t *u128_ptr = ptr;
+ uint128_t dst;
+
+ btoh128(u128_ptr, &dst);
+
+ return dst;
+}
+
static inline void att_put_u8(uint8_t src, void *dst)
{
bt_put_unaligned(src, (uint8_t *) dst);
diff --git a/attrib/gatt.c b/attrib/gatt.c
index b99d39c..3fedcc4 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -174,9 +174,10 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
att_get_u16(&data[4]));
sdp_uuid16_to_uuid128(&u128, &u16);

- } else if (list->len == 20)
- sdp_uuid128_create(&u128, &data[4]);
- else
+ } else if (list->len == 20) {
+ uint128_t h128 = att_get_u128(&data[4]);
+ sdp_uuid128_create(&u128, &h128);
+ } else
/* Skipping invalid data */
continue;

@@ -271,8 +272,10 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
if (list->len == 7) {
sdp_uuid16_create(&u16, att_get_u16(&value[5]));
sdp_uuid16_to_uuid128(&u128, &u16);
- } else
- sdp_uuid128_create(&u128, &value[5]);
+ } else {
+ uint128_t h128 = att_get_u128(&value[5]);
+ sdp_uuid128_create(&u128, &h128);
+ }

chars = g_try_new0(struct att_char, 1);
if (!chars) {
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 7478043..643d9ec 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -452,8 +452,10 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,

if (format == 0x01)
sdp_uuid16_create(&uuid, att_get_u16(&value[2]));
- else
- sdp_uuid128_create(&uuid, &value[2]);
+ else {
+ uint128_t h128 = att_get_u128(&value[2]);
+ sdp_uuid128_create(&uuid, &h128);
+ }

sdp_uuid2strn(&uuid, uuidstr, MAX_LEN_UUID_STR);
g_print("handle = 0x%04x, uuid = %s\n", handle, uuidstr);
--
1.7.4.1


2011-02-18 22:29:21

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 02/14] Use host byte order when converting UUID16/32 to UUID128

uuid_t should store the UUID-128 values in the host byte order to
keep the consistency with UUID-16 and UUID32.
---
lib/sdp.c | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/lib/sdp.c b/lib/sdp.c
index d24d1e2..af50a16 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -2629,6 +2629,8 @@ int sdp_uuid128_cmp(const void *p1, const void *p2)
*/
void sdp_uuid16_to_uuid128(uuid_t *uuid128, const uuid_t *uuid16)
{
+ uint128_t n128;
+
/*
* We have a 16 bit value, which needs to be added to
* bytes 3 and 4 (at indices 2 and 3) of the Bluetooth base
@@ -2636,8 +2638,7 @@ void sdp_uuid16_to_uuid128(uuid_t *uuid128, const uuid_t *uuid16)
unsigned short data1;

/* allocate a 128bit UUID and init to the Bluetooth base UUID */
- uuid128->value.uuid128 = bluetooth_base_uuid;
- uuid128->type = SDP_UUID128;
+ n128 = bluetooth_base_uuid;

/* extract bytes 2 and 3 of 128bit BT base UUID */
memcpy(&data1, &bluetooth_base_uuid.data[2], 2);
@@ -2646,11 +2647,16 @@ void sdp_uuid16_to_uuid128(uuid_t *uuid128, const uuid_t *uuid16)
data1 += htons(uuid16->value.uuid16);

/* set bytes 2 and 3 of the 128 bit value */
- memcpy(&uuid128->value.uuid128.data[2], &data1, 2);
+ memcpy(&n128.data[2], &data1, 2);
+
+ uuid128->type = SDP_UUID128;
+ ntoh128(&n128, &uuid128->value.uuid128);
}

void sdp_uuid32_to_uuid128(uuid_t *uuid128, const uuid_t *uuid32)
{
+ uint128_t n128;
+
/*
* We have a 32 bit value, which needs to be added to
* bytes 1->4 (at indices 0 thru 3) of the Bluetooth base
@@ -2658,8 +2664,7 @@ void sdp_uuid32_to_uuid128(uuid_t *uuid128, const uuid_t *uuid32)
unsigned int data0;

/* allocate a 128bit UUID and init to the Bluetooth base UUID */
- uuid128->value.uuid128 = bluetooth_base_uuid;
- uuid128->type = SDP_UUID128;
+ n128 = bluetooth_base_uuid;

/* extract first 4 bytes */
memcpy(&data0, &bluetooth_base_uuid.data[0], 4);
@@ -2668,7 +2673,10 @@ void sdp_uuid32_to_uuid128(uuid_t *uuid128, const uuid_t *uuid32)
data0 += htonl(uuid32->value.uuid32);

/* set the 4 bytes of the 128 bit value */
- memcpy(&uuid128->value.uuid128.data[0], &data0, 4);
+ memcpy(&n128.data[0], &data0, 4);
+
+ uuid128->type = SDP_UUID128;
+ ntoh128(&n128, &uuid128->value.uuid128);
}

uuid_t *sdp_uuid_to_uuid128(const uuid_t *uuid)
--
1.7.4.1


2011-02-18 22:29:20

by Claudio Takahasi

[permalink] [raw]
Subject: [RFC v2 01/14] Move 64 and 128 bits byte order functions to bluetooth.h

---
attrib/example.c | 1 +
attrib/gatt.c | 1 +
attrib/interactive.c | 1 +
health/hdp_manager.c | 1 +
health/mcap_sync.c | 17 -----------------
lib/bluetooth.h | 41 +++++++++++++++++++++++++++++++++++++++++
lib/sdp.c | 43 -------------------------------------------
lib/sdp.h | 4 ----
src/sdp-xml.c | 1 +
test/hciemu.c | 16 ----------------
10 files changed, 46 insertions(+), 80 deletions(-)

diff --git a/attrib/example.c b/attrib/example.c
index 1911912..f5fcf1b 100644
--- a/attrib/example.c
+++ b/attrib/example.c
@@ -29,6 +29,7 @@

#include <arpa/inet.h>

+#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 20bb96f..b99d39c 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -24,6 +24,7 @@

#include <stdint.h>
#include <glib.h>
+#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

diff --git a/attrib/interactive.c b/attrib/interactive.c
index edc465a..f797f71 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -25,6 +25,7 @@
#include <stdio.h>
#include <glib.h>

+#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

diff --git a/health/hdp_manager.c b/health/hdp_manager.c
index 88b49fc..8ba1720 100644
--- a/health/hdp_manager.c
+++ b/health/hdp_manager.c
@@ -27,6 +27,7 @@
#include <config.h>
#endif

+#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

diff --git a/health/mcap_sync.c b/health/mcap_sync.c
index 6f90344..20311a2 100644
--- a/health/mcap_sync.c
+++ b/health/mcap_sync.c
@@ -92,23 +92,6 @@ struct sync_set_data {
gboolean role;
};

-/* Ripped from lib/sdp.c */
-
-#if __BYTE_ORDER == __BIG_ENDIAN
-#define ntoh64(x) (x)
-#else
-static inline uint64_t ntoh64(uint64_t n)
-{
- uint64_t h;
- uint64_t tmp = ntohl(n & 0x00000000ffffffff);
- h = ntohl(n >> 32);
- h |= tmp << 32;
- return h;
-}
-#endif
-
-#define hton64(x) ntoh64(x)
-
static gboolean csp_caps_initialized = FALSE;
struct csp_caps _caps;

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index bc0921e..d8f36f8 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -35,6 +35,7 @@ extern "C" {
#include <string.h>
#include <endian.h>
#include <byteswap.h>
+#include <arpa/inet.h>

#ifndef AF_BLUETOOTH
#define AF_BLUETOOTH 31
@@ -88,21 +89,61 @@ enum {
BT_CLOSED
};

+typedef struct {
+ uint8_t data[16];
+} uint128_t;
+
/* Byte order conversions */
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define htobs(d) (d)
#define htobl(d) (d)
#define btohs(d) (d)
#define btohl(d) (d)
+static inline uint64_t ntoh64(uint64_t n)
+{
+ uint64_t h;
+ uint64_t tmp = ntohl(n & 0x00000000ffffffff);
+ h = ntohl(n >> 32);
+ h |= tmp << 32;
+ return h;
+}
+
+static inline void ntoh128(const uint128_t *src, uint128_t *dst)
+{
+ int i;
+ for (i = 0; i < 16; i++)
+ dst->data[15 - i] = src->data[i];
+}
+
+static inline void btoh128(const uint128_t *src, uint128_t *dst)
+{
+ memcpy(dst, src, sizeof(uint128_t));
+}
#elif __BYTE_ORDER == __BIG_ENDIAN
#define htobs(d) bswap_16(d)
#define htobl(d) bswap_32(d)
#define btohs(d) bswap_16(d)
#define btohl(d) bswap_32(d)
+#define ntoh64(x) (x)
+static inline void ntoh128(const uint128_t *src, uint128_t *dst)
+{
+ memcpy(dst, src, sizeof(uint128_t));
+}
+
+static inline void btoh128(const uint128_t *src, uint128_t *dst)
+{
+ int i;
+ for (i = 0; i < 16; i++)
+ dst->data[15 - i] = src->data[i];
+}
#else
#error "Unknown byte order"
#endif

+#define hton64(x) ntoh64(x)
+#define hton128(x, y) ntoh128(x, y)
+#define htob128(x, y) btoh128(x, y)
+
/* Bluetooth unaligned access */
#define bt_get_unaligned(ptr) \
({ \
diff --git a/lib/sdp.c b/lib/sdp.c
index e782aec..d24d1e2 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -60,49 +60,6 @@
#define SDPDBG(fmt...)
#endif

-#if __BYTE_ORDER == __BIG_ENDIAN
-#define ntoh64(x) (x)
-static inline void ntoh128(const uint128_t *src, uint128_t *dst)
-{
- memcpy(dst, src, sizeof(uint128_t));
-}
-
-static inline void btoh128(const uint128_t *src, uint128_t *dst)
-{
- int i;
- for (i = 0; i < 16; i++)
- dst->data[15 - i] = src->data[i];
-
-}
-
-#else
-static inline uint64_t ntoh64(uint64_t n)
-{
- uint64_t h;
- uint64_t tmp = ntohl(n & 0x00000000ffffffff);
- h = ntohl(n >> 32);
- h |= tmp << 32;
- return h;
-}
-
-static inline void ntoh128(const uint128_t *src, uint128_t *dst)
-{
- int i;
- for (i = 0; i < 16; i++)
- dst->data[15 - i] = src->data[i];
-}
-
-static inline void btoh128(const uint128_t *src, uint128_t *dst)
-{
- memcpy(dst, src, sizeof(uint128_t));
-}
-
-#endif
-
-#define hton64(x) ntoh64(x)
-#define hton128(x, y) ntoh128(x, y)
-#define htob128(x, y) btoh128(x, y)
-
#define BASE_UUID "00000000-0000-1000-8000-00805F9B34FB"

static uint128_t bluetooth_base_uuid = {
diff --git a/lib/sdp.h b/lib/sdp.h
index e901b2a..4e0396a 100644
--- a/lib/sdp.h
+++ b/lib/sdp.h
@@ -421,10 +421,6 @@ typedef struct {
* Should the type of any of these change, you need only make a change here.
*/
typedef struct {
- uint8_t data[16];
-} uint128_t;
-
-typedef struct {
uint8_t type;
union {
uint16_t uuid16;
diff --git a/src/sdp-xml.c b/src/sdp-xml.c
index 3aa9df0..48a3808 100644
--- a/src/sdp-xml.c
+++ b/src/sdp-xml.c
@@ -33,6 +33,7 @@
#include <limits.h>
#include <stdlib.h>

+#include <bluetooth/bluetooth.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

diff --git a/test/hciemu.c b/test/hciemu.c
index 5227766..757a75c 100644
--- a/test/hciemu.c
+++ b/test/hciemu.c
@@ -52,22 +52,6 @@

#include <glib.h>

-#if __BYTE_ORDER == __LITTLE_ENDIAN
-static inline uint64_t ntoh64(uint64_t n)
-{
- uint64_t h;
- uint64_t tmp = ntohl(n & 0x00000000ffffffff);
- h = ntohl(n >> 32);
- h |= tmp << 32;
- return h;
-}
-#elif __BYTE_ORDER == __BIG_ENDIAN
-#define ntoh64(x) (x)
-#else
-#error "Unknown byte order"
-#endif
-#define hton64(x) ntoh64(x)
-
#define GHCI_DEV "/dev/ghci"

#define VHCI_DEV "/dev/vhci"
--
1.7.4.1