Re: [PATCH 1/5 v2] Add new UUID utility functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Johan/Brian,

On Fri, Mar 11, 2011 at 2:30 PM, Elvis PfÃtzenreuter <epx@xxxxxxxxxxx> wrote:
> From: Claudio Takahasi <claudio.takahasi@xxxxxxxxxxxxx>
>
> New UUID functions will store the UUIDs values on host order. Added
> functions to create, compare and convert UUIDs.
> ---
> ÂMakefile.am | Â Â6 +-
> Âlib/uuid.c Â| Â126 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> Âlib/uuid.h Â| Â 61 ++++++++++++++++++++++++++++
> Â3 files changed, 190 insertions(+), 3 deletions(-)
> Âcreate mode 100644 lib/uuid.c
> Âcreate mode 100644 lib/uuid.h
>
> diff --git a/Makefile.am b/Makefile.am
> index 49c45c1..804ba9d 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -43,8 +43,8 @@ plugin_LTLIBRARIES =
>
>
> Âlib_headers = lib/bluetooth.h lib/hci.h lib/hci_lib.h lib/mgmt.h \
> - Â Â Â Â Â Â Â Â Â Â Â lib/sco.h lib/l2cap.h lib/sdp.h lib/sdp_lib.h \
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â lib/rfcomm.h lib/bnep.h lib/cmtp.h lib/hidp.h
> + Â Â Â Â Â Â Â lib/sco.h lib/l2cap.h lib/sdp.h lib/sdp_lib.h lib/uuid.h \
> + Â Â Â Â Â Â Â Â Â Â Â lib/rfcomm.h lib/bnep.h lib/cmtp.h lib/hidp.h
> Âlocal_headers = $(foreach file,$(lib_headers), lib/bluetooth/$(notdir $(file)))
>
> Âinclude_HEADERS += $(lib_headers)
> @@ -52,7 +52,7 @@ include_HEADERS += $(lib_headers)
> Âlib_LTLIBRARIES += lib/libbluetooth.la
>
> Âlib_libbluetooth_la_SOURCES = $(lib_headers) \
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â lib/bluetooth.c lib/hci.c lib/sdp.c
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â lib/bluetooth.c lib/hci.c lib/sdp.c lib/uuid.c
> Âlib_libbluetooth_la_LDFLAGS = -version-info 13:5:10
> Âlib_libbluetooth_la_DEPENDENCIES = $(local_headers)
>
> diff --git a/lib/uuid.c b/lib/uuid.c
> new file mode 100644
> index 0000000..66ab544
> --- /dev/null
> +++ b/lib/uuid.c
> @@ -0,0 +1,126 @@
> +/*
> + *
> + * ÂBlueZ - Bluetooth protocol stack for Linux
> + *
> + * ÂCopyright (C) 2011 ÂNokia Corporation
> + * ÂCopyright (C) 2011 ÂMarcel Holtmann <marcel@xxxxxxxxxxxx>
> + *
> + *
> + * ÂThis program is free software; you can redistribute it and/or modify
> + * Âit under the terms of the GNU General Public License as published by
> + * Âthe Free Software Foundation; either version 2 of the License, or
> + * Â(at your option) any later version.
> + *
> + * ÂThis program is distributed in the hope that it will be useful,
> + * Âbut WITHOUT ANY WARRANTY; without even the implied warranty of
> + * ÂMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the
> + * ÂGNU General Public License for more details.
> + *
> + * ÂYou should have received a copy of the GNU General Public License
> + * Âalong with this program; if not, write to the Free Software
> + * ÂFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA Â02110-1301 ÂUSA
> + *
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <string.h>
> +
> +#include "uuid.h"
> +
> +#if __BYTE_ORDER == __BIG_ENDIAN
> +static uint128_t bluetooth_base_uuid = {
> + Â Â Â .data = { Â Â Â 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
> + Â Â Â Â Â Â Â Â Â Â Â 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB }
> +};
> +
> +#define BASE_UUID16_OFFSET Â Â 2
> +#define BASE_UUID32_OFFSET Â Â 0
> +
> +#else
> +static uint128_t bluetooth_base_uuid = {
> + Â Â Â .data = { Â Â Â 0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80,
> + Â Â Â Â Â Â Â Â Â Â Â 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
> +};
> +
> +#define BASE_UUID16_OFFSET Â Â 12
> +#define BASE_UUID32_OFFSET Â Â BASE_UUID16_OFFSET
> +
> +#endif
> +
> +static void bt_uuid16_to_uuid128(const bt_uuid_t *uuid16, bt_uuid_t *uuid128)
> +{
> + Â Â Â uuid128->value.u128 = bluetooth_base_uuid;
> + Â Â Â uuid128->type = BT_UUID128;
> +
> + Â Â Â memcpy(&uuid128->value.u128.data[BASE_UUID16_OFFSET],
> + Â Â Â Â Â Â Â Â Â Â Â &uuid16->value.u16, sizeof(uuid16->value.u16));

Are you fine with memcpy or it is better to use assignments(as
proposed by Brian)?

> +}
> +
> +static void bt_uuid32_to_uuid128(const bt_uuid_t *uuid32, bt_uuid_t *uuid128)
> +{
> + Â Â Â uuid128->value.u128 = bluetooth_base_uuid;
> + Â Â Â uuid128->type = BT_UUID128;
> +
> + Â Â Â memcpy(&uuid128->value.u128.data[BASE_UUID32_OFFSET],
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &uuid32->value.u32, sizeof(uuid32->value.u32));

Same comment here.

> +}
> +
> +static void bt_uuid2uuid128(const bt_uuid_t *uuid, bt_uuid_t *uuid128)

I will rename it to bt_uuid_to_uuid128 to follow the same name
standard of the other functions.

BR,
Claudio

> +{
> + Â Â Â switch (uuid->type) {
> + Â Â Â case BT_UUID128:
> + Â Â Â Â Â Â Â memcpy(uuid128, uuid, sizeof(bt_uuid_t));
> + Â Â Â Â Â Â Â break;
> + Â Â Â case BT_UUID32:
> + Â Â Â Â Â Â Â bt_uuid32_to_uuid128(uuid, uuid128);
> + Â Â Â Â Â Â Â break;
> + Â Â Â case BT_UUID16:
> + Â Â Â Â Â Â Â bt_uuid16_to_uuid128(uuid, uuid128);
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> +}
> +
> +static int bt_uuid128_cmp(const bt_uuid_t *u1, const bt_uuid_t *u2)
> +{
> + Â Â Â return memcmp(&u1->value.u128, &u2->value.u128, sizeof(uint128_t));
> +}
> +
> +int bt_uuid16_create(bt_uuid_t *btuuid, uint16_t value)
> +{
> + Â Â Â memset(btuuid, 0, sizeof(bt_uuid_t));
> + Â Â Â btuuid->type = BT_UUID16;
> + Â Â Â btuuid->value.u16 = value;
> +
> + Â Â Â return 0;
> +}
> +
> +int bt_uuid32_create(bt_uuid_t *btuuid, uint32_t value)
> +{
> + Â Â Â memset(btuuid, 0, sizeof(bt_uuid_t));
> + Â Â Â btuuid->type = BT_UUID32;
> + Â Â Â btuuid->value.u32 = value;
> +
> + Â Â Â return 0;
> +}
> +
> +int bt_uuid128_create(bt_uuid_t *btuuid, uint128_t value)
> +{
> + Â Â Â memset(btuuid, 0, sizeof(bt_uuid_t));
> + Â Â Â btuuid->type = BT_UUID128;
> + Â Â Â btuuid->value.u128 = value;
> +
> + Â Â Â return 0;
> +}
> +
> +int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2)
> +{
> + Â Â Â bt_uuid_t u1, u2;
> +
> + Â Â Â bt_uuid2uuid128(uuid1, &u1);
> + Â Â Â bt_uuid2uuid128(uuid2, &u2);
> +
> + Â Â Â return bt_uuid128_cmp(&u1, &u2);
> +}
> diff --git a/lib/uuid.h b/lib/uuid.h
> new file mode 100644
> index 0000000..bc9ca31
> --- /dev/null
> +++ b/lib/uuid.h
> @@ -0,0 +1,61 @@
> +/*
> + *
> + * ÂBlueZ - Bluetooth protocol stack for Linux
> + *
> + * ÂCopyright (C) 2011 ÂNokia Corporation
> + * ÂCopyright (C) 2011 ÂMarcel Holtmann <marcel@xxxxxxxxxxxx>
> + *
> + *
> + * ÂThis program is free software; you can redistribute it and/or modify
> + * Âit under the terms of the GNU General Public License as published by
> + * Âthe Free Software Foundation; either version 2 of the License, or
> + * Â(at your option) any later version.
> + *
> + * ÂThis program is distributed in the hope that it will be useful,
> + * Âbut WITHOUT ANY WARRANTY; without even the implied warranty of
> + * ÂMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ÂSee the
> + * ÂGNU General Public License for more details.
> + *
> + * ÂYou should have received a copy of the GNU General Public License
> + * Âalong with this program; if not, write to the Free Software
> + * ÂFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA Â02110-1301 ÂUSA
> + *
> + */
> +
> +#ifndef __BLUETOOTH_UUID_H
> +#define __BLUETOOTH_UUID_H
> +
> +#ifdef __cplusplus
> +extern "C" {
> +#endif
> +
> +#include <stdint.h>
> +
> +typedef struct {
> + Â Â Â uint8_t data[16];
> +} uint128_t;
> +
> +typedef struct {
> + Â Â Â enum {
> + Â Â Â Â Â Â Â BT_UUID16 = 16,
> + Â Â Â Â Â Â Â BT_UUID32 = 32,
> + Â Â Â Â Â Â Â BT_UUID128 = 128,
> + Â Â Â } type;
> + Â Â Â union {
> + Â Â Â Â Â Â Â uint16_t Âu16;
> + Â Â Â Â Â Â Â uint32_t Âu32;
> + Â Â Â Â Â Â Â uint128_t u128;
> + Â Â Â } value;
> +} bt_uuid_t;
> +
> +int bt_uuid16_create(bt_uuid_t *btuuid, uint16_t value);
> +int bt_uuid32_create(bt_uuid_t *btuuid, uint32_t value);
> +int bt_uuid128_create(bt_uuid_t *btuuid, uint128_t value);
> +
> +int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2);
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* __BLUETOOTH_UUID_H */
> --
> 1.7.1
>
>
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux