2014-03-20 14:42:25

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 00/62] Cleanup: Byte order

Apply after "[PATCH BlueZ v5 00/16] Add basic GATT characteristics"

This patchset contains the following changes:
* Replace att_get_* and att_put_* by util.h helpers
* Replace bt_get_* and bt_put_* by util.h helpers
* Represent 128-bit bt_uuid_t using BIG-ENDIAN format
(human-readable format)

Open issues:
* Remove bt_get_* and bt_put_* from bluetooth.h? ("lib: Remove"
patches can be ignored)
* Which 128-bit UUID bit order is being used on android? See
android/gatt.c (primary_cb function)
* Should src/shared/util.h be included by lib/ files? IMO, lib should
be "self contained"

TODO:
* Replace uint128_t by uint8_t[16]

attrib/gatt-service.c and src/attrib-server.c should be removed in the
future, there are some repeated definitions of put_uuid_le() that can
be moved to a common header file IF necessary.

Changing the 128-bit UUID representation makes bt_uuid_t similar to
uuid_t. This patchset allows replacing uuid_t in the future.

Claudio Takahasi (62):
shared: Add put_le64()
shared: Add get_le16()
shared: Add get_le32()
shared: Add get_le64()
shared: Add get_be16()
shared: Add get_be32()
shared: Add get_be64()
shared: Add put_be16()
shared: Add put_be32()
shared: Add put_be64()
Replace bt_get_le16() by get_le16()
Replace bt_get_le32() by get_le32()
Replace bt_get_le64() by get_le64()
Replace bt_get_be16() by get_be16()
Replace bt_get_be32() by get_be32()
Replace bt_get_be64() by get_be64()
Replace bt_put_be16() by put_be16()
Replace bt_put_be32() by put_be32()
Replace bt_put_be64() by get_be64()
lib: Remove bt_put_le16()
lib: Remove bt_put_le32()
lib: Remove bt_put_le64()
lib: Remove bt_get_le16()
lib: Remove bt_get_le32()
lib: Remove bt_get_le64()
lib: Remove bt_get_be16()
lib: Remove bt_get_be32()
lib: Remove bt_get_be64()
lib: Remove bt_put_be16()
lib: Remove bt_put_be32()
lib: Remove bt_put_be64()
lib: Remove ntoh128() from bt_string_to_uuid128()
lib: Remove hton128() from bt_uuid_to_string()
lib: Fix UUID 16/32-bits to 128-bit conversion
unit: Use lower-case for 128-bit UUIDs
unit: Fix 128-bit UUID format
attrib: Use LE helpers defined in src/shared/util.h
Replace att_get_u32() by get_le32()
Replace att_put_u32() by put_le32()
Replace att_put_uuid16() by put_le16()
Replace att_get_uuid16() by get_le16()
Replace att_get_u16() by get_le16()
Replace att_get_uuid128() by bswap_128()
Replace att_put_uuid() by util.h helpers
Replace att_put_u16() by put_le16()
attrib: Remove att_get_u8()
attrib: Remove att_put_u8()
attrib: Remove att_get_u32()
attrib: Remove att_put_u32()
attrib: Remove att_get_uuid16()
attrib: Remove att_get_u16()
attrib: Remove att_get_uuid128()
attrib: Remove att_get_u128()
attrib: Remove att_put_uuid()
attrib: Remove att_put_uuid128()
attrib: Remove att_put_u128()
attrib: Remove att_put_uuid16()
attrib: Remove att_put_u16()
lib: Use get_unaligned() instead of bt_get_unaligned()
tools: Use unaligned access macros from util.h
lib: Remove bt_get_unaligned()
lib: Remove bt_put_unaligned()

android/android-tester.c | 3 +-
android/avrcp-lib.c | 23 +++---
android/avrcp.c | 7 +-
android/bluetooth.c | 3 +-
attrib/att.c | 148 +++++++++++++++++++++--------------
attrib/att.h | 89 ---------------------
attrib/gatt-service.c | 24 +++---
attrib/gatt.c | 112 ++++++++++++++++----------
attrib/gattrib.c | 3 +-
attrib/gatttool.c | 18 +++--
attrib/interactive.c | 18 +++--
lib/bluetooth.h | 142 ---------------------------------
lib/sdp.c | 83 ++++++++++----------
lib/uuid.c | 40 ++++------
monitor/control.c | 2 +-
monitor/l2cap.c | 92 +++++++++++-----------
monitor/packet.c | 46 +++++------
monitor/sdp.c | 62 ++++++++-------
plugins/gatt-example.c | 73 ++++++++---------
profiles/audio/avrcp.c | 75 +++++++++---------
profiles/cyclingspeed/cyclingspeed.c | 27 ++++---
profiles/deviceinfo/deviceinfo.c | 5 +-
profiles/gatt/gas.c | 13 +--
profiles/heartrate/heartrate.c | 19 ++---
profiles/input/hog.c | 9 ++-
profiles/network/bnep.c | 9 ++-
profiles/proximity/reporter.c | 9 ++-
profiles/sap/server.c | 5 +-
profiles/scanparam/scan.c | 11 +--
profiles/thermometer/thermometer.c | 29 +++----
profiles/time/server.c | 3 +-
src/adapter.c | 4 +-
src/attrib-server.c | 42 ++++++----
src/eir.c | 8 +-
src/sdpd-request.c | 40 +++++-----
src/sdpd-service.c | 19 ++---
src/shared/util.h | 50 ++++++++++++
tools/btmgmt.c | 32 ++++----
tools/hciconfig.c | 3 +-
tools/l2test.c | 4 +-
tools/mgmt-tester.c | 3 +-
tools/parser/hci.c | 2 +-
tools/parser/l2cap.c | 24 +++---
tools/parser/parser.h | 9 +--
tools/parser/ppp.c | 2 +-
unit/test-uuid.c | 13 +--
46 files changed, 689 insertions(+), 768 deletions(-)

--
1.8.3.1



2014-03-25 11:48:33

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH BlueZ v2] tools: Use unaligned access macros from util.h

Hi Claudio,

On Tue, Mar 25, 2014, Claudio Takahasi wrote:
> ---
> tools/parser/hci.c | 1 -
> tools/parser/l2cap.c | 1 -
> tools/parser/parser.h | 7 ++++---
> tools/parser/ppp.c | 2 +-
> 4 files changed, 5 insertions(+), 6 deletions(-)

Applied. Thanks.

Johan

2014-03-25 11:38:30

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v2] tools: Use unaligned access macros from util.h

---
tools/parser/hci.c | 1 -
tools/parser/l2cap.c | 1 -
tools/parser/parser.h | 7 ++++---
tools/parser/ppp.c | 2 +-
4 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/tools/parser/hci.c b/tools/parser/hci.c
index b018e93..351f843 100644
--- a/tools/parser/hci.c
+++ b/tools/parser/hci.c
@@ -37,7 +37,6 @@
#include "lib/hci.h"
#include "lib/hci_lib.h"
#include "lib/amp.h"
-#include "src/shared/util.h"

static uint16_t manufacturer = DEFAULT_COMPID;

diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index 53dd726..a057964 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -39,7 +39,6 @@
#include "lib/hci.h"
#include "lib/a2mp.h"
#include "lib/amp.h"
-#include "src/shared/util.h"

typedef struct {
uint16_t handle;
diff --git a/tools/parser/parser.h b/tools/parser/parser.h
index c65b4b5..62b8ac5 100644
--- a/tools/parser/parser.h
+++ b/tools/parser/parser.h
@@ -30,6 +30,7 @@
#include <netinet/in.h>

#include "lib/bluetooth.h"
+#include "src/shared/util.h"

struct frame {
void *data;
@@ -173,7 +174,7 @@ static inline uint16_t get_u16(struct frame *frm)
uint16_t *u16_ptr = frm->ptr;
frm->ptr += 2;
frm->len -= 2;
- return ntohs(bt_get_unaligned(u16_ptr));
+ return get_be16(u16_ptr);
}

static inline uint32_t get_u32(struct frame *frm)
@@ -181,13 +182,13 @@ static inline uint32_t get_u32(struct frame *frm)
uint32_t *u32_ptr = frm->ptr;
frm->ptr += 4;
frm->len -= 4;
- return ntohl(bt_get_unaligned(u32_ptr));
+ return get_be32(u32_ptr);
}

static inline uint64_t get_u64(struct frame *frm)
{
uint64_t *u64_ptr = frm->ptr;
- uint64_t u64 = bt_get_unaligned(u64_ptr), tmp;
+ uint64_t u64 = get_unaligned(u64_ptr), tmp;
frm->ptr += 8;
frm->len -= 8;
tmp = ntohl(u64 & 0xffffffff);
diff --git a/tools/parser/ppp.c b/tools/parser/ppp.c
index 947ca56..256e172 100644
--- a/tools/parser/ppp.c
+++ b/tools/parser/ppp.c
@@ -103,7 +103,7 @@ static void hdlc_dump(int level, struct frame *frm)
uint8_t ctrl = get_u8(frm);
uint16_t fcs, proto;

- fcs = bt_get_unaligned((uint16_t *) (frm->ptr + frm->len - 2));
+ fcs = get_unaligned((uint16_t *) (frm->ptr + frm->len - 2));
frm->len -= 2;

p_indent(level, frm);
--
1.8.3.1


2014-03-25 11:37:23

by Claudio Takahasi

[permalink] [raw]
Subject: Re: [PATCH v1 20/22] tools: Use unaligned access macros from util.h

Hi Johan/Lizardo:

On Mon, Mar 24, 2014 at 5:42 PM, Anderson Lizardo
<[email protected]> wrote:
> Hi Johan,
>
> On Mon, Mar 24, 2014 at 4:17 PM, Johan Hedberg <[email protected]> wrote:
>> Hi Claudio,
>>
>> On Mon, Mar 24, 2014, Claudio Takahasi wrote:
>>> ---
>>> tools/parser/hci.c | 1 -
>>> tools/parser/l2cap.c | 1 -
>>> tools/parser/parser.h | 9 ++++-----
>>> tools/parser/ppp.c | 2 +-
>>> 4 files changed, 5 insertions(+), 8 deletions(-)
>>
>> I've applied all patches until this one.
>>
>> This patch has a quite severe bug in it (which to be honest makes me a
>> bit nervous of the earlier ones I applied):
>>
>>> static inline uint16_t get_u16(struct frame *frm)
>>> {
>>> - uint16_t *u16_ptr = frm->ptr;
>>> frm->ptr += 2;
>>> frm->len -= 2;
>>> - return ntohs(bt_get_unaligned(u16_ptr));
>>> + return get_be16(frm->ptr);
>>> }
>>>
>>> static inline uint32_t get_u32(struct frame *frm)
>>> {
>>> - uint32_t *u32_ptr = frm->ptr;
>>> frm->ptr += 4;
>>> frm->len -= 4;
>>> - return ntohl(bt_get_unaligned(u32_ptr));
>>> + return get_be32(frm->ptr);
>>> }
>>
>> Note that the value passed to ntohl before your patch is the pointer
>> before it is incremented. However after your patch it's the pointer
>> after it has been incremented, so you're changing the behavior of these
>> two functions.
>
> To be clear, I reviewed this code internally, and I missed this bug. I
> believe the correct change is something like:
>
> - uint32_t *u32_ptr = frm->ptr;
> + uint32_t u32 = get_be32(frm->ptr);
>
> and then "return u32" at the end. Sorry about the double mistake
> (given that both me and Claudio missed it).

It is my negligence. I will send a new patch.

Claudio.

2014-03-24 20:42:02

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [PATCH v1 20/22] tools: Use unaligned access macros from util.h

Hi Johan,

On Mon, Mar 24, 2014 at 4:17 PM, Johan Hedberg <[email protected]> wrote:
> Hi Claudio,
>
> On Mon, Mar 24, 2014, Claudio Takahasi wrote:
>> ---
>> tools/parser/hci.c | 1 -
>> tools/parser/l2cap.c | 1 -
>> tools/parser/parser.h | 9 ++++-----
>> tools/parser/ppp.c | 2 +-
>> 4 files changed, 5 insertions(+), 8 deletions(-)
>
> I've applied all patches until this one.
>
> This patch has a quite severe bug in it (which to be honest makes me a
> bit nervous of the earlier ones I applied):
>
>> static inline uint16_t get_u16(struct frame *frm)
>> {
>> - uint16_t *u16_ptr = frm->ptr;
>> frm->ptr += 2;
>> frm->len -= 2;
>> - return ntohs(bt_get_unaligned(u16_ptr));
>> + return get_be16(frm->ptr);
>> }
>>
>> static inline uint32_t get_u32(struct frame *frm)
>> {
>> - uint32_t *u32_ptr = frm->ptr;
>> frm->ptr += 4;
>> frm->len -= 4;
>> - return ntohl(bt_get_unaligned(u32_ptr));
>> + return get_be32(frm->ptr);
>> }
>
> Note that the value passed to ntohl before your patch is the pointer
> before it is incremented. However after your patch it's the pointer
> after it has been incremented, so you're changing the behavior of these
> two functions.

To be clear, I reviewed this code internally, and I missed this bug. I
believe the correct change is something like:

- uint32_t *u32_ptr = frm->ptr;
+ uint32_t u32 = get_be32(frm->ptr);

and then "return u32" at the end. Sorry about the double mistake
(given that both me and Claudio missed it).

Best Regards,
--
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil

2014-03-24 20:19:32

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v1 22/22] attrib: Minor code optimization

Hi Claudio,

On Mon, Mar 24, 2014, Claudio Takahasi wrote:
> ---
> attrib/gatt.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)

I've also applied patches 21 and 22.

Johan

2014-03-24 20:17:29

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH v1 20/22] tools: Use unaligned access macros from util.h

Hi Claudio,

On Mon, Mar 24, 2014, Claudio Takahasi wrote:
> ---
> tools/parser/hci.c | 1 -
> tools/parser/l2cap.c | 1 -
> tools/parser/parser.h | 9 ++++-----
> tools/parser/ppp.c | 2 +-
> 4 files changed, 5 insertions(+), 8 deletions(-)

I've applied all patches until this one.

This patch has a quite severe bug in it (which to be honest makes me a
bit nervous of the earlier ones I applied):

> static inline uint16_t get_u16(struct frame *frm)
> {
> - uint16_t *u16_ptr = frm->ptr;
> frm->ptr += 2;
> frm->len -= 2;
> - return ntohs(bt_get_unaligned(u16_ptr));
> + return get_be16(frm->ptr);
> }
>
> static inline uint32_t get_u32(struct frame *frm)
> {
> - uint32_t *u32_ptr = frm->ptr;
> frm->ptr += 4;
> frm->len -= 4;
> - return ntohl(bt_get_unaligned(u32_ptr));
> + return get_be32(frm->ptr);
> }

Note that the value passed to ntohl before your patch is the pointer
before it is incremented. However after your patch it's the pointer
after it has been incremented, so you're changing the behavior of these
two functions.

Johan

2014-03-24 19:25:43

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 22/22] attrib: Minor code optimization

---
attrib/gatt.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index f57d0bb..7363b4b 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -408,10 +408,8 @@ static struct gatt_included *included_from_buf(const uint8_t *buf, gsize len)

if (len == 8) {
bt_uuid_t uuid128;
- bt_uuid_t uuid16;

- bt_uuid16_create(&uuid16, get_le16(&buf[6]));
- bt_uuid_to_uuid128(&uuid16, &uuid128);
+ get_uuid128(BT_UUID16, &buf[6], &uuid128);
bt_uuid_to_string(&uuid128, incl->uuid, sizeof(incl->uuid));
}

--
1.8.3.1


2014-03-24 19:25:42

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 21/22] core: Fix creating 128-bit uuid_t based on GATT service

sdp_uuid128_create() gets the 128-bit UUID on big-endian (human-readable
format) byte order. Service declaration attributes puts the UUIDs in the
attribute value field using little endian order. This patch converts the
128-bit UUID from little-endian to big-endian before creating uuid_t.
---
src/attrib-server.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 953a3f2..114c8a1 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -318,9 +318,13 @@ static uint32_t attrib_create_sdp_new(struct gatt_server *server,

if (a->len == 2)
sdp_uuid16_create(&svc, get_le16(a->data));
- else if (a->len == 16)
- sdp_uuid128_create(&svc, a->data);
- else
+ else if (a->len == 16) {
+ uint8_t be128[16];
+
+ /* Converting from LE to BE */
+ bswap_128(a->data, be128);
+ sdp_uuid128_create(&svc, be128);
+ } else
return 0;

record = server_record_new(&svc, handle, end);
--
1.8.3.1


2014-03-24 19:25:41

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 20/22] tools: Use unaligned access macros from util.h

---
tools/parser/hci.c | 1 -
tools/parser/l2cap.c | 1 -
tools/parser/parser.h | 9 ++++-----
tools/parser/ppp.c | 2 +-
4 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/tools/parser/hci.c b/tools/parser/hci.c
index b018e93..351f843 100644
--- a/tools/parser/hci.c
+++ b/tools/parser/hci.c
@@ -37,7 +37,6 @@
#include "lib/hci.h"
#include "lib/hci_lib.h"
#include "lib/amp.h"
-#include "src/shared/util.h"

static uint16_t manufacturer = DEFAULT_COMPID;

diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index 53dd726..a057964 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -39,7 +39,6 @@
#include "lib/hci.h"
#include "lib/a2mp.h"
#include "lib/amp.h"
-#include "src/shared/util.h"

typedef struct {
uint16_t handle;
diff --git a/tools/parser/parser.h b/tools/parser/parser.h
index c65b4b5..dc49104 100644
--- a/tools/parser/parser.h
+++ b/tools/parser/parser.h
@@ -30,6 +30,7 @@
#include <netinet/in.h>

#include "lib/bluetooth.h"
+#include "src/shared/util.h"

struct frame {
void *data;
@@ -170,24 +171,22 @@ static inline uint8_t get_u8(struct frame *frm)

static inline uint16_t get_u16(struct frame *frm)
{
- uint16_t *u16_ptr = frm->ptr;
frm->ptr += 2;
frm->len -= 2;
- return ntohs(bt_get_unaligned(u16_ptr));
+ return get_be16(frm->ptr);
}

static inline uint32_t get_u32(struct frame *frm)
{
- uint32_t *u32_ptr = frm->ptr;
frm->ptr += 4;
frm->len -= 4;
- return ntohl(bt_get_unaligned(u32_ptr));
+ return get_be32(frm->ptr);
}

static inline uint64_t get_u64(struct frame *frm)
{
uint64_t *u64_ptr = frm->ptr;
- uint64_t u64 = bt_get_unaligned(u64_ptr), tmp;
+ uint64_t u64 = get_unaligned(u64_ptr), tmp;
frm->ptr += 8;
frm->len -= 8;
tmp = ntohl(u64 & 0xffffffff);
diff --git a/tools/parser/ppp.c b/tools/parser/ppp.c
index 947ca56..256e172 100644
--- a/tools/parser/ppp.c
+++ b/tools/parser/ppp.c
@@ -103,7 +103,7 @@ static void hdlc_dump(int level, struct frame *frm)
uint8_t ctrl = get_u8(frm);
uint16_t fcs, proto;

- fcs = bt_get_unaligned((uint16_t *) (frm->ptr + frm->len - 2));
+ fcs = get_unaligned((uint16_t *) (frm->ptr + frm->len - 2));
frm->len -= 2;

p_indent(level, frm);
--
1.8.3.1


2014-03-24 19:25:40

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 19/22] Replace att_put_u16() by put_le16()

---
attrib/att.c | 48 ++++++++++++------------
attrib/gatt-service.c | 2 +-
plugins/gatt-example.c | 73 ++++++++++++++++++------------------
profiles/cyclingspeed/cyclingspeed.c | 10 ++---
profiles/gatt/gas.c | 2 +-
profiles/heartrate/heartrate.c | 8 ++--
profiles/proximity/reporter.c | 7 ++--
profiles/scanparam/scan.c | 6 +--
profiles/thermometer/thermometer.c | 12 +++---
profiles/time/server.c | 3 +-
src/attrib-server.c | 26 ++++++-------
11 files changed, 100 insertions(+), 97 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index bdf7c00..8e9c06d 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -161,9 +161,9 @@ uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_BY_GROUP_REQ;
/* Starting Handle (2 octets) */
- att_put_u16(start, &pdu[1]);
+ put_le16(start, &pdu[1]);
/* Ending Handle (2 octets) */
- att_put_u16(end, &pdu[3]);
+ put_le16(end, &pdu[3]);
/* Attribute Group Type (2 or 16 octet UUID) */
put_uuid_le(uuid, &pdu[5]);

@@ -291,8 +291,8 @@ uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
vlen = len - min_len;

pdu[0] = ATT_OP_FIND_BY_TYPE_REQ;
- att_put_u16(start, &pdu[1]);
- att_put_u16(end, &pdu[3]);
+ put_le16(start, &pdu[1]);
+ put_le16(end, &pdu[3]);
put_le16(uuid->value.u16, &pdu[5]);

if (vlen > 0) {
@@ -347,8 +347,8 @@ uint16_t enc_find_by_type_resp(GSList *matches, uint8_t *pdu, size_t len)
l = l->next, offset += sizeof(uint16_t) * 2) {
struct att_range *range = l->data;

- att_put_u16(range->start, &pdu[offset]);
- att_put_u16(range->end, &pdu[offset + 2]);
+ put_le16(range->start, &pdu[offset]);
+ put_le16(range->end, &pdu[offset + 2]);
}

return offset;
@@ -406,9 +406,9 @@ uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_BY_TYPE_REQ;
/* Starting Handle (2 octets) */
- att_put_u16(start, &pdu[1]);
+ put_le16(start, &pdu[1]);
/* Ending Handle (2 octets) */
- att_put_u16(end, &pdu[3]);
+ put_le16(end, &pdu[3]);
/* Attribute Type (2 or 16 octet UUID) */
put_uuid_le(uuid, &pdu[5]);

@@ -527,7 +527,7 @@ uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, size_t vlen,
vlen = len - min_len;

pdu[0] = ATT_OP_WRITE_CMD;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);

if (vlen > 0) {
memcpy(&pdu[3], value, vlen);
@@ -573,7 +573,7 @@ uint16_t enc_write_req(uint16_t handle, const uint8_t *value, size_t vlen,
vlen = len - min_len;

pdu[0] = ATT_OP_WRITE_REQ;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);

if (vlen > 0) {
memcpy(&pdu[3], value, vlen);
@@ -637,7 +637,7 @@ uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, size_t len)
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_REQ;
/* Attribute Handle (2 octets) */
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);

return 3;
}
@@ -651,9 +651,9 @@ uint16_t enc_read_blob_req(uint16_t handle, uint16_t offset, uint8_t *pdu,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_BLOB_REQ;
/* Attribute Handle (2 octets) */
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);
/* Value Offset (2 octets) */
- att_put_u16(offset, &pdu[3]);
+ put_le16(offset, &pdu[3]);

return 5;
}
@@ -769,7 +769,7 @@ uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status,
/* Request Opcode In Error (1 octet) */
pdu[1] = opcode;
/* Attribute Handle In Error (2 octets) */
- att_put_u16(handle, &pdu[2]);
+ put_le16(handle, &pdu[2]);
/* Error Code (1 octet) */
pdu[4] = status;

@@ -785,9 +785,9 @@ uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_FIND_INFO_REQ;
/* Starting Handle (2 octets) */
- att_put_u16(start, &pdu[1]);
+ put_le16(start, &pdu[1]);
/* Ending Handle (2 octets) */
- att_put_u16(end, &pdu[3]);
+ put_le16(end, &pdu[3]);

return 5;
}
@@ -895,7 +895,7 @@ uint16_t enc_notification(uint16_t handle, uint8_t *value, size_t vlen,
return 0;

pdu[0] = ATT_OP_HANDLE_NOTIFY;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);
memcpy(&pdu[3], value, vlen);

return vlen + min_len;
@@ -913,7 +913,7 @@ uint16_t enc_indication(uint16_t handle, uint8_t *value, size_t vlen,
return 0;

pdu[0] = ATT_OP_HANDLE_IND;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);
memcpy(&pdu[3], value, vlen);

return vlen + min_len;
@@ -963,7 +963,7 @@ uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, size_t len)
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_MTU_REQ;
/* Client Rx MTU (2 octets) */
- att_put_u16(mtu, &pdu[1]);
+ put_le16(mtu, &pdu[1]);

return 3;
}
@@ -997,7 +997,7 @@ uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, size_t len)
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_MTU_RESP;
/* Server Rx MTU (2 octets) */
- att_put_u16(mtu, &pdu[1]);
+ put_le16(mtu, &pdu[1]);

return 3;
}
@@ -1037,8 +1037,8 @@ uint16_t enc_prep_write_req(uint16_t handle, uint16_t offset,
vlen = len - min_len;

pdu[0] = ATT_OP_PREP_WRITE_REQ;
- att_put_u16(handle, &pdu[1]);
- att_put_u16(offset, &pdu[3]);
+ put_le16(handle, &pdu[1]);
+ put_le16(offset, &pdu[3]);

if (vlen > 0) {
memcpy(&pdu[5], value, vlen);
@@ -1090,8 +1090,8 @@ uint16_t enc_prep_write_resp(uint16_t handle, uint16_t offset,
vlen = len - min_len;

pdu[0] = ATT_OP_PREP_WRITE_RESP;
- att_put_u16(handle, &pdu[1]);
- att_put_u16(offset, &pdu[3]);
+ put_le16(handle, &pdu[1]);
+ put_le16(offset, &pdu[3]);

if (vlen > 0) {
memcpy(&pdu[5], value, vlen);
diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index 699ac1e..d68e8b9 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -232,7 +232,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
/* characteristic declaration */
bt_uuid16_create(&bt_uuid, GATT_CHARAC_UUID);
atval[0] = info->props;
- att_put_u16(h + 1, &atval[1]);
+ put_le16(h + 1, &atval[1]);
put_uuid_le(&info->uuid, &atval[3]);
if (attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 3 + info->uuid.type / 8) == NULL)
diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index d710917..22a6925 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -33,6 +33,7 @@
#include "src/plugin.h"
#include "src/adapter.h"
#include "src/hcid.h"
+#include "src/shared/util.h"
#include "src/log.h"
#include "attrib/gattrib.h"
#include "attrib/gatt-service.h"
@@ -149,7 +150,7 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,

/* Thermometer: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(THERM_HUMIDITY_SVC_UUID, &atval[0]);
+ put_le16(THERM_HUMIDITY_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

@@ -157,18 +158,18 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,

/* Thermometer: Include */
if (manuf1[0] && manuf1[1]) {
- att_put_u16(manuf1[0], &atval[0]);
- att_put_u16(manuf1[1], &atval[2]);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]);
+ put_le16(manuf1[0], &atval[0]);
+ put_le16(manuf1[1], &atval[2]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[4]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 6);
}

/* Thermometer: Include */
if (manuf2[0] && manuf2[1]) {
- att_put_u16(manuf2[0], &atval[0]);
- att_put_u16(manuf2[1], &atval[2]);
- att_put_u16(VENDOR_SPECIFIC_SVC_UUID, &atval[4]);
+ put_le16(manuf2[0], &atval[0]);
+ put_le16(manuf2[1], &atval[2]);
+ put_le16(VENDOR_SPECIFIC_SVC_UUID, &atval[4]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 6);
}
@@ -176,8 +177,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
/* Thermometer: temperature characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(TEMPERATURE_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(TEMPERATURE_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -192,9 +193,9 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
atval[0] = 0x0E;
atval[1] = 0xFE;
- att_put_u16(FMT_CELSIUS_UUID, &atval[2]);
+ put_le16(FMT_CELSIUS_UUID, &atval[2]);
atval[4] = 0x01;
- att_put_u16(FMT_OUTSIDE_UUID, &atval[5]);
+ put_le16(FMT_OUTSIDE_UUID, &atval[5]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 7);

@@ -208,8 +209,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
/* Thermometer: relative humidity characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(RELATIVE_HUMIDITY_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(RELATIVE_HUMIDITY_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -223,9 +224,9 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
atval[0] = 0x04;
atval[1] = 0x00;
- att_put_u16(FMT_PERCENT_UUID, &atval[2]);
- att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]);
- att_put_u16(FMT_OUTSIDE_UUID, &atval[6]);
+ put_le16(FMT_PERCENT_UUID, &atval[2]);
+ put_le16(BLUETOOTH_SIG_UUID, &atval[4]);
+ put_le16(FMT_OUTSIDE_UUID, &atval[6]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 8);

@@ -270,15 +271,15 @@ static void register_manuf1_service(struct gatt_example_adapter *adapter,

/* Secondary Service: Manufacturer Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

/* Manufacturer name characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_NAME_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -292,8 +293,8 @@ static void register_manuf1_service(struct gatt_example_adapter *adapter,
/* Manufacturer serial number characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_SERIAL_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -334,15 +335,15 @@ static void register_manuf2_service(struct gatt_example_adapter *adapter,

/* Secondary Service: Manufacturer Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

/* Manufacturer name characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_NAME_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -356,8 +357,8 @@ static void register_manuf2_service(struct gatt_example_adapter *adapter,
/* Characteristic: serial number */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_SERIAL_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -395,15 +396,15 @@ static void register_vendor_service(struct gatt_example_adapter *adapter,

/* Secondary Service: Vendor Specific Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
- att_put_u16(VENDOR_SPECIFIC_SVC_UUID, &atval[0]);
+ put_le16(VENDOR_SPECIFIC_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

/* Vendor Specific Type characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(VENDOR_SPECIFIC_TYPE_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(VENDOR_SPECIFIC_TYPE_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -465,9 +466,9 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
if (vendor[0] && vendor[1]) {
/* Weight: include */
bt_uuid16_create(&uuid, GATT_INCLUDE_UUID);
- att_put_u16(vendor[0], &atval[0]);
- att_put_u16(vendor[1], &atval[2]);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]);
+ put_le16(vendor[0], &atval[0]);
+ put_le16(vendor[1], &atval[2]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[4]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 6);
}
@@ -475,7 +476,7 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
/* Weight: characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
+ put_le16(h + 1, &atval[1]);
memcpy(&atval[3], &char_weight_uuid_btorder, 16);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 19);
@@ -493,9 +494,9 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
atval[0] = 0x08;
atval[1] = 0xFD;
- att_put_u16(FMT_KILOGRAM_UUID, &atval[2]);
- att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]);
- att_put_u16(FMT_HANGING_UUID, &atval[6]);
+ put_le16(FMT_KILOGRAM_UUID, &atval[2]);
+ put_le16(BLUETOOTH_SIG_UUID, &atval[4]);
+ put_le16(FMT_HANGING_UUID, &atval[6]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 8);

diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index 63e969a..2f80bca 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -457,16 +457,16 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu,
ch->csc->measurement_ccc_handle = handle;

if (g_slist_length(ch->csc->cadapter->watchers) == 0) {
- att_put_u16(0x0000, attr_val);
+ put_le16(0x0000, attr_val);
msg = g_strdup("Disable measurement");
} else {
- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT,
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT,
attr_val);
msg = g_strdup("Enable measurement");
}

} else if (g_strcmp0(ch->uuid, SC_CONTROL_POINT_UUID) == 0) {
- att_put_u16(GATT_CLIENT_CHARAC_CFG_IND_BIT, attr_val);
+ put_le16(GATT_CLIENT_CHARAC_CFG_IND_BIT, attr_val);
msg = g_strdup("Enable SC Control Point indications");
} else {
break;
@@ -817,7 +817,7 @@ static void enable_measurement(gpointer data, gpointer user_data)
if (csc->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
msg = g_strdup("Enable measurement");

gatt_write_char(csc->attrib, handle, value, sizeof(value),
@@ -834,7 +834,7 @@ static void disable_measurement(gpointer data, gpointer user_data)
if (csc->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable measurement");

gatt_write_char(csc->attrib, handle, value, sizeof(value),
diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index 38f5e72..7a9d34e 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
@@ -233,7 +233,7 @@ static void write_ccc(GAttrib *attrib, uint16_t handle, gpointer user_data)
{
uint8_t value[2];

- att_put_u16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
gatt_write_char(attrib, handle, value, sizeof(value), ccc_written_cb,
user_data);
}
diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index 15ccdfd..1dcbdf4 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -428,10 +428,10 @@ static void discover_ccc_cb(guint8 status, const guint8 *pdu,
hr->measurement_ccc_handle = handle;

if (g_slist_length(hr->hradapter->watchers) == 0) {
- att_put_u16(0x0000, attr_val);
+ put_le16(0x0000, attr_val);
msg = g_strdup("Disable measurement");
} else {
- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, attr_val);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, attr_val);
msg = g_strdup("Enable measurement");
}

@@ -511,7 +511,7 @@ static void enable_measurement(gpointer data, gpointer user_data)
if (hr->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
msg = g_strdup("Enable measurement");

gatt_write_char(hr->attrib, handle, value, sizeof(value),
@@ -528,7 +528,7 @@ static void disable_measurement(gpointer data, gpointer user_data)
if (hr->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable measurement");

gatt_write_char(hr->attrib, handle, value, sizeof(value),
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index bda993d..5861923 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -43,6 +43,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "src/hcid.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
@@ -117,14 +118,14 @@ static void register_tx_power(struct btd_adapter *adapter)

/* Primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(TX_POWER_SVC_UUID, &atval[0]);
+ put_le16(TX_POWER_SVC_UUID, &atval[0]);
attrib_db_add(adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);

/* Power level characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_NOTIFY;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(POWER_LEVEL_CHR_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(POWER_LEVEL_CHR_UUID, &atval[3]);
attrib_db_add(adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);

/* Power level value */
diff --git a/profiles/scanparam/scan.c b/profiles/scanparam/scan.c
index d6e477e..156682f 100644
--- a/profiles/scanparam/scan.c
+++ b/profiles/scanparam/scan.c
@@ -67,8 +67,8 @@ static void write_scan_params(GAttrib *attrib, uint16_t handle)
{
uint8_t value[4];

- att_put_u16(SCAN_INTERVAL, &value[0]);
- att_put_u16(SCAN_WINDOW, &value[2]);
+ put_le16(SCAN_INTERVAL, &value[0]);
+ put_le16(SCAN_WINDOW, &value[2]);

gatt_write_cmd(attrib, handle, value, sizeof(value), NULL, NULL);
}
@@ -126,7 +126,7 @@ static void discover_descriptor_cb(guint8 status, const guint8 *pdu,
if (uuid16 != GATT_CLIENT_CHARAC_CFG_UUID)
goto done;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
gatt_write_char(scan->attrib, handle, value, sizeof(value),
ccc_written_cb, user_data);
done:
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index 5b90792..9462cc9 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -569,7 +569,7 @@ static void process_thermometer_desc(struct characteristic *ch, uint16_t uuid,
return;
}

- att_put_u16(val, atval);
+ put_le16(val, atval);
gatt_write_char(ch->t->attrib, handle, atval, sizeof(atval),
write_ccc_cb, msg);
}
@@ -790,7 +790,7 @@ static void enable_final_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
msg = g_strdup("Enable Temperature Measurement indications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -807,7 +807,7 @@ static void enable_intermediate_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
msg = g_strdup("Enable Intermediate Temperature notifications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -824,7 +824,7 @@ static void disable_final_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable Temperature Measurement indications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -841,7 +841,7 @@ static void disable_intermediate_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable Intermediate Temperature notifications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -1071,7 +1071,7 @@ static void property_set_interval(const GDBusPropertyTable *property,
return;
}

- att_put_u16(val, &atval[0]);
+ put_le16(val, &atval[0]);

interval_data = g_new0(struct tmp_interval_data, 1);
interval_data->thermometer = t;
diff --git a/profiles/time/server.c b/profiles/time/server.c
index 142d15c..31ddb06 100644
--- a/profiles/time/server.c
+++ b/profiles/time/server.c
@@ -41,6 +41,7 @@
#include "attrib/att.h"
#include "attrib/gatt.h"
#include "attrib/att-database.h"
+#include "src/shared/util.h"
#include "src/attrib-server.h"
#include "attrib/gatt-service.h"
#include "src/log.h"
@@ -90,7 +91,7 @@ static int encode_current_time(uint8_t value[10])
return -EINVAL;
}

- att_put_u16(1900 + tm.tm_year, &value[0]); /* Year */
+ put_le16(1900 + tm.tm_year, &value[0]); /* Year */
value[2] = tm.tm_mon + 1; /* Month */
value[3] = tm.tm_mday; /* Day */
value[4] = tm.tm_hour; /* Hours */
diff --git a/src/attrib-server.c b/src/attrib-server.c
index cb27315..953a3f2 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -513,8 +513,8 @@ static uint16_t read_by_group(struct gatt_channel *channel, uint16_t start,

value = (void *) adl->data[i];

- att_put_u16(cur->handle, value);
- att_put_u16(cur->end, &value[2]);
+ put_le16(cur->handle, value);
+ put_le16(cur->end, &value[2]);
/* Attribute Value */
memcpy(&value[4], cur->data, cur->len);
}
@@ -602,7 +602,7 @@ static uint16_t read_by_type(struct gatt_channel *channel, uint16_t start,

value = (void *) adl->data[i];

- att_put_u16(a->handle, value);
+ put_le16(a->handle, value);

/* Attribute Value */
memcpy(&value[2], a->data, a->len);
@@ -682,7 +682,7 @@ static uint16_t find_info(struct gatt_channel *channel, uint16_t start,

value = (void *) adl->data[i];

- att_put_u16(a->handle, value);
+ put_le16(a->handle, value);

/* Attribute Value */
put_uuid_le(&a->uuid, &value[2]);
@@ -811,7 +811,7 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle,
read_device_ccc(channel->device, handle, &cccval) == 0) {
uint8_t config[2];

- att_put_u16(cccval, config);
+ put_le16(cccval, config);
return enc_read_resp(config, sizeof(config), pdu, len);
}

@@ -852,7 +852,7 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle,
read_device_ccc(channel->device, handle, &cccval) == 0) {
uint8_t config[2];

- att_put_u16(cccval, config);
+ put_le16(cccval, config);
return enc_read_blob_resp(config, sizeof(config), offset,
pdu, len);
}
@@ -1299,7 +1299,7 @@ static gboolean register_core_services(struct gatt_server *server)

/* GAP service: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(GENERIC_ACCESS_PROFILE_ID, &atval[0]);
+ put_le16(GENERIC_ACCESS_PROFILE_ID, &atval[0]);
attrib_db_add_new(server, 0x0001, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

@@ -1307,8 +1307,8 @@ static gboolean register_core_services(struct gatt_server *server)
server->name_handle = 0x0006;
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(server->name_handle, &atval[1]);
- att_put_u16(GATT_CHARAC_DEVICE_NAME, &atval[3]);
+ put_le16(server->name_handle, &atval[1]);
+ put_le16(GATT_CHARAC_DEVICE_NAME, &atval[3]);
attrib_db_add_new(server, 0x0004, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -1321,14 +1321,14 @@ static gboolean register_core_services(struct gatt_server *server)
server->appearance_handle = 0x0008;
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(server->appearance_handle, &atval[1]);
- att_put_u16(GATT_CHARAC_APPEARANCE, &atval[3]);
+ put_le16(server->appearance_handle, &atval[1]);
+ put_le16(GATT_CHARAC_APPEARANCE, &atval[3]);
attrib_db_add_new(server, 0x0007, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

/* GAP service: device appearance attribute */
bt_uuid16_create(&uuid, GATT_CHARAC_APPEARANCE);
- att_put_u16(appearance, &atval[0]);
+ put_le16(appearance, &atval[0]);
attrib_db_add_new(server, server->appearance_handle, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 2);
server->gap_sdp_handle = attrib_create_sdp_new(server, 0x0001,
@@ -1340,7 +1340,7 @@ static gboolean register_core_services(struct gatt_server *server)

/* GATT service: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(GENERIC_ATTRIB_PROFILE_ID, &atval[0]);
+ put_le16(GENERIC_ATTRIB_PROFILE_ID, &atval[0]);
attrib_db_add_new(server, 0x0010, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

--
1.8.3.1


2014-03-24 19:25:39

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 18/22] Replace att_put_uuid() by util.h helpers

---
attrib/att.c | 13 +++++++++++--
attrib/gatt-service.c | 22 +++++++++++++---------
src/attrib-server.c | 11 ++++++++++-
3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index bd23142..bdf7c00 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -38,6 +38,15 @@
#include "lib/uuid.h"
#include "att.h"

+static inline void put_uuid_le(const bt_uuid_t *src, void *dst)
+{
+ if (src->type == BT_UUID16)
+ put_le16(src->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&src->value.u128, dst);
+}
+
const char *att_ecode2str(uint8_t status)
{
switch (status) {
@@ -156,7 +165,7 @@ uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Ending Handle (2 octets) */
att_put_u16(end, &pdu[3]);
/* Attribute Group Type (2 or 16 octet UUID) */
- att_put_uuid(*uuid, &pdu[5]);
+ put_uuid_le(uuid, &pdu[5]);

return 5 + uuid_len;
}
@@ -401,7 +410,7 @@ uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Ending Handle (2 octets) */
att_put_u16(end, &pdu[3]);
/* Attribute Type (2 or 16 octet UUID) */
- att_put_uuid(*uuid, &pdu[5]);
+ put_uuid_le(uuid, &pdu[5]);

return 5 + uuid_len;
}
diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index 227d4d4..699ac1e 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -30,6 +30,7 @@
#include <bluetooth/sdp.h>

#include "src/adapter.h"
+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
@@ -56,6 +57,15 @@ struct attrib_cb {
void *user_data;
};

+static inline void put_uuid_le(const bt_uuid_t *src, void *dst)
+{
+ if (src->type == BT_UUID16)
+ put_le16(src->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&src->value.u128, dst);
+}
+
static GSList *parse_opts(gatt_option opt1, va_list args)
{
gatt_option opt = opt1;
@@ -130,14 +140,8 @@ static struct attribute *add_service_declaration(struct btd_adapter *adapter,
uint8_t atval[16];
int len;

- if (uuid->type == BT_UUID16) {
- att_put_u16(uuid->value.u16, &atval[0]);
- len = 2;
- } else if (uuid->type == BT_UUID128) {
- att_put_u128(uuid->value.u128, &atval[0]);
- len = 16;
- } else
- return NULL;
+ put_uuid_le(uuid, &atval[0]);
+ len = bt_uuid_len(uuid);

bt_uuid16_create(&bt_uuid, svc);

@@ -229,7 +233,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
bt_uuid16_create(&bt_uuid, GATT_CHARAC_UUID);
atval[0] = info->props;
att_put_u16(h + 1, &atval[1]);
- att_put_uuid(info->uuid, &atval[3]);
+ put_uuid_le(&info->uuid, &atval[3]);
if (attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 3 + info->uuid.type / 8) == NULL)
return FALSE;
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 85e63a6..cb27315 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -102,6 +102,15 @@ static bt_uuid_t ccc_uuid = {
.value.u16 = GATT_CLIENT_CHARAC_CFG_UUID
};

+static inline void put_uuid_le(const bt_uuid_t *src, void *dst)
+{
+ if (src->type == BT_UUID16)
+ put_le16(src->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&src->value.u128, dst);
+}
+
static void attrib_free(void *data)
{
struct attribute *a = data;
@@ -676,7 +685,7 @@ static uint16_t find_info(struct gatt_channel *channel, uint16_t start,
att_put_u16(a->handle, value);

/* Attribute Value */
- att_put_uuid(a->uuid, &value[2]);
+ put_uuid_le(&a->uuid, &value[2]);
}

length = enc_find_info_resp(format, adl, pdu, len);
--
1.8.3.1


2014-03-24 19:25:38

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 17/22] Replace att_get_uuid128() by bswap_128()

GATT/ATT use little-endian byte order format for 128-bit UUID. No matter
the system byte order representation, internally the core will handle
128-bit UUID on big-endian format.
---
attrib/att.c | 38 +++++++++++++++++++++--------
attrib/gatt.c | 69 +++++++++++++++++++++++++++++++++++-----------------
attrib/gatttool.c | 9 +++++--
attrib/interactive.c | 9 +++++--
4 files changed, 89 insertions(+), 36 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index 1df6190..bd23142 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -121,6 +121,19 @@ struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len)
return list;
}

+static void get_uuid(uint8_t type, const void *val, bt_uuid_t *uuid)
+{
+ if (type == BT_UUID16)
+ bt_uuid16_create(uuid, get_le16(val));
+ else {
+ uint128_t u128;
+
+ /* Convert from 128-bit LE to BE */
+ bswap_128(val, &u128);
+ bt_uuid128_create(uuid, u128);
+ }
+}
+
uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
uint8_t *pdu, size_t len)
{
@@ -152,6 +165,7 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
uint16_t *end, bt_uuid_t *uuid)
{
const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end);
+ uint8_t type;

if (pdu == NULL)
return 0;
@@ -162,15 +176,17 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (pdu[0] != ATT_OP_READ_BY_GROUP_REQ)
return 0;

- if (len != (min_len + 2) && len != (min_len + 16))
+ if (len == (min_len + 2))
+ type = BT_UUID16;
+ else if (len == (min_len + 16))
+ type = BT_UUID128;
+ else
return 0;

*start = get_le16(&pdu[1]);
*end = get_le16(&pdu[3]);
- if (len == min_len + 2)
- bt_uuid16_create(uuid, get_le16(&pdu[5]));
- else
- *uuid = att_get_uuid128(&pdu[5]);
+
+ get_uuid(type, &pdu[5], uuid);

return len;
}
@@ -394,6 +410,7 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
uint16_t *end, bt_uuid_t *uuid)
{
const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end);
+ uint8_t type;

if (pdu == NULL)
return 0;
@@ -401,7 +418,11 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (start == NULL || end == NULL || uuid == NULL)
return 0;

- if (len != (min_len + 2) && len != (min_len + 16))
+ if (len == (min_len + 2))
+ type = BT_UUID16;
+ else if (len == (min_len + 16))
+ type = BT_UUID128;
+ else
return 0;

if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ)
@@ -410,10 +431,7 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
*start = get_le16(&pdu[1]);
*end = get_le16(&pdu[3]);

- if (len == min_len + 2)
- bt_uuid16_create(uuid, get_le16(&pdu[5]));
- else
- *uuid = att_get_uuid128(&pdu[5]);
+ get_uuid(type, &pdu[5], uuid);

return len;
}
diff --git a/attrib/gatt.c b/attrib/gatt.c
index 83692f4..f57d0bb 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -148,6 +148,22 @@ static void put_uuid_le(const bt_uuid_t *uuid, void *dst)
bswap_128(&uuid->value.u128, dst);
}

+static void get_uuid128(uint8_t type, const void *val, bt_uuid_t *uuid)
+{
+ if (type == BT_UUID16) {
+ bt_uuid_t uuid16;
+
+ bt_uuid16_create(&uuid16, get_le16(val));
+ bt_uuid_to_uuid128(&uuid16, uuid);
+ } else {
+ uint128_t u128;
+
+ /* Convert from 128-bit LE to BE */
+ bswap_128(val, &u128);
+ bt_uuid128_create(uuid, u128);
+ }
+}
+
static guint16 encode_discover_primary(uint16_t start, uint16_t end,
bt_uuid_t *uuid, uint8_t *pdu, size_t len)
{
@@ -225,6 +241,7 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
struct att_data_list *list;
unsigned int i, err;
uint16_t start, end;
+ uint8_t type;

if (status) {
err = status == ATT_ECODE_ATTR_NOT_FOUND ? 0 : status;
@@ -240,23 +257,26 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
for (i = 0, end = 0; i < list->num; i++) {
const uint8_t *data = list->data[i];
struct gatt_primary *primary;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;

start = get_le16(&data[0]);
end = get_le16(&data[2]);

- if (list->len == 6) {
- bt_uuid_t uuid16;
-
- bt_uuid16_create(&uuid16, get_le16(&data[4]));
- bt_uuid_to_uuid128(&uuid16, &uuid);
- } else if (list->len == 20) {
- uuid = att_get_uuid128(&data[4]);
- } else {
+ /*
+ * FIXME: Check before "for". Elements in the Attribute
+ * Data List have the same length (list->len).
+ */
+ if (list->len == 6)
+ type = BT_UUID16;
+ else if (list->len == 20)
+ type = BT_UUID128;
+ else {
/* Skipping invalid data */
continue;
}

+ get_uuid128(type, &data[4], &uuid128);
+
primary = g_try_new0(struct gatt_primary, 1);
if (!primary) {
att_data_list_free(list);
@@ -265,7 +285,7 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
}
primary->range.start = start;
primary->range.end = end;
- bt_uuid_to_string(&uuid, primary->uuid, sizeof(primary->uuid));
+ bt_uuid_to_string(&uuid128, primary->uuid, sizeof(primary->uuid));
dp->primaries = g_slist_append(dp->primaries, primary);
}

@@ -328,7 +348,7 @@ static void resolve_included_uuid_cb(uint8_t status, const uint8_t *pdu,
struct included_discovery *isd = query->isd;
struct gatt_included *incl = query->included;
unsigned int err = status;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;
size_t buflen;
uint8_t *buf;

@@ -341,8 +361,9 @@ static void resolve_included_uuid_cb(uint8_t status, const uint8_t *pdu,
goto done;
}

- uuid = att_get_uuid128(buf);
- bt_uuid_to_string(&uuid, incl->uuid, sizeof(incl->uuid));
+ get_uuid128(BT_UUID128, buf, &uuid128);
+
+ bt_uuid_to_string(&uuid128, incl->uuid, sizeof(incl->uuid));
isd->includes = g_slist_append(isd->includes, incl);
query->included = NULL;

@@ -503,19 +524,23 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
for (i = 0; i < list->num; i++) {
uint8_t *value = list->data[i];
struct gatt_char *chars;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;
+ uint8_t type;

last = get_le16(value);

- if (list->len == 7) {
- bt_uuid_t uuid16;
+ /*
+ * FIXME: Check before "for". Elements in the Attribute
+ * Data List have the same length (list->len).
+ */
+ if (list->len == 7)
+ type = BT_UUID16;
+ else
+ type = BT_UUID128;

- bt_uuid16_create(&uuid16, get_le16(&value[5]));
- bt_uuid_to_uuid128(&uuid16, &uuid);
- } else
- uuid = att_get_uuid128(&value[5]);
+ get_uuid128(type, &value[5], &uuid128);

- if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid))
+ if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid128))
continue;

chars = g_try_new0(struct gatt_char, 1);
@@ -527,7 +552,7 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
chars->handle = last;
chars->properties = value[2];
chars->value_handle = get_le16(&value[3]);
- bt_uuid_to_string(&uuid, chars->uuid, sizeof(chars->uuid));
+ bt_uuid_to_string(&uuid128, chars->uuid, sizeof(chars->uuid));
dc->characteristics = g_slist_append(dc->characteristics,
chars);
}
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 4eb2528..ca178ce 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -428,8 +428,13 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
- else
- uuid = att_get_uuid128(&value[2]);
+ else {
+ uint128_t u128;
+
+ /* Converts from LE to BE byte order */
+ bswap_128(&value[2], &u128);
+ bt_uuid128_create(&uuid, u128);
+ }

bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
g_print("handle = 0x%04x, uuid = %s\n", handle, uuidstr);
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 5dd47ec..4865944 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -297,8 +297,13 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
- else
- uuid = att_get_uuid128(&value[2]);
+ else {
+ uint128_t u128;
+
+ /* Converts from LE to BE byte order */
+ bswap_128(&value[2], &u128);
+ bt_uuid128_create(&uuid, u128);
+ }

bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
rl_printf("handle: 0x%04x, uuid: %s\n", handle, uuidstr);
--
1.8.3.1


2014-03-24 19:25:37

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 16/22] Replace att_get_u16() by get_le16()

---
attrib/att.c | 44 ++++++++++++++++++------------------
attrib/gatt.c | 14 ++++++------
attrib/gattrib.c | 3 ++-
attrib/gatttool.c | 6 ++---
attrib/interactive.c | 6 ++---
profiles/cyclingspeed/cyclingspeed.c | 12 +++++-----
profiles/deviceinfo/deviceinfo.c | 5 ++--
profiles/gatt/gas.c | 11 +++++----
profiles/heartrate/heartrate.c | 11 +++++----
profiles/input/hog.c | 9 ++++----
profiles/scanparam/scan.c | 5 ++--
profiles/thermometer/thermometer.c | 14 ++++++------
src/attrib-server.c | 5 ++--
13 files changed, 76 insertions(+), 69 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index b353499..1df6190 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -165,8 +165,8 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (len != (min_len + 2) && len != (min_len + 16))
return 0;

- *start = att_get_u16(&pdu[1]);
- *end = att_get_u16(&pdu[3]);
+ *start = get_le16(&pdu[1]);
+ *end = get_le16(&pdu[3]);
if (len == min_len + 2)
bt_uuid16_create(uuid, get_le16(&pdu[5]));
else
@@ -293,9 +293,9 @@ uint16_t dec_find_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
return 0;

/* First requested handle number (2 octets) */
- *start = att_get_u16(&pdu[1]);
+ *start = get_le16(&pdu[1]);
/* Last requested handle number (2 octets) */
- *end = att_get_u16(&pdu[3]);
+ *end = get_le16(&pdu[3]);
/* 16-bit UUID to find (2 octets) */
bt_uuid16_create(uuid, get_le16(&pdu[5]));

@@ -354,8 +354,8 @@ GSList *dec_find_by_type_resp(const uint8_t *pdu, size_t len)
len >= (offset + sizeof(uint16_t) * 2);
offset += sizeof(uint16_t) * 2) {
range = g_new0(struct att_range, 1);
- range->start = att_get_u16(&pdu[offset]);
- range->end = att_get_u16(&pdu[offset + 2]);
+ range->start = get_le16(&pdu[offset]);
+ range->end = get_le16(&pdu[offset + 2]);

matches = g_slist_append(matches, range);
}
@@ -407,8 +407,8 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ)
return 0;

- *start = att_get_u16(&pdu[1]);
- *end = att_get_u16(&pdu[3]);
+ *start = get_le16(&pdu[1]);
+ *end = get_le16(&pdu[3]);

if (len == min_len + 2)
bt_uuid16_create(uuid, get_le16(&pdu[5]));
@@ -527,7 +527,7 @@ uint16_t dec_write_cmd(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_WRITE_CMD)
return 0;

- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);
memcpy(value, pdu + min_len, len - min_len);
*vlen = len - min_len;

@@ -573,7 +573,7 @@ uint16_t dec_write_req(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_WRITE_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);
*vlen = len - min_len;
if (*vlen > 0)
memcpy(value, pdu + min_len, *vlen);
@@ -647,7 +647,7 @@ uint16_t dec_read_req(const uint8_t *pdu, size_t len, uint16_t *handle)
if (pdu[0] != ATT_OP_READ_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);

return min_len;
}
@@ -673,8 +673,8 @@ uint16_t dec_read_blob_req(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_READ_BLOB_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
- *offset = att_get_u16(&pdu[3]);
+ *handle = get_le16(&pdu[1]);
+ *offset = get_le16(&pdu[3]);

return min_len;
}
@@ -782,8 +782,8 @@ uint16_t dec_find_info_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (pdu[0] != ATT_OP_FIND_INFO_REQ)
return 0;

- *start = att_get_u16(&pdu[1]);
- *end = att_get_u16(&pdu[3]);
+ *start = get_le16(&pdu[1]);
+ *end = get_le16(&pdu[3]);

return min_len;
}
@@ -910,7 +910,7 @@ uint16_t dec_indication(const uint8_t *pdu, size_t len, uint16_t *handle,
dlen = MIN(len - min_len, vlen);

if (handle)
- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);

memcpy(value, &pdu[3], dlen);

@@ -957,7 +957,7 @@ uint16_t dec_mtu_req(const uint8_t *pdu, size_t len, uint16_t *mtu)
if (pdu[0] != ATT_OP_MTU_REQ)
return 0;

- *mtu = att_get_u16(&pdu[1]);
+ *mtu = get_le16(&pdu[1]);

return min_len;
}
@@ -991,7 +991,7 @@ uint16_t dec_mtu_resp(const uint8_t *pdu, size_t len, uint16_t *mtu)
if (pdu[0] != ATT_OP_MTU_RESP)
return 0;

- *mtu = att_get_u16(&pdu[1]);
+ *mtu = get_le16(&pdu[1]);

return min_len;
}
@@ -1039,8 +1039,8 @@ uint16_t dec_prep_write_req(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_PREP_WRITE_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
- *offset = att_get_u16(&pdu[3]);
+ *handle = get_le16(&pdu[1]);
+ *offset = get_le16(&pdu[3]);

*vlen = len - min_len;
if (*vlen > 0)
@@ -1092,8 +1092,8 @@ uint16_t dec_prep_write_resp(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_PREP_WRITE_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
- *offset = att_get_u16(&pdu[3]);
+ *handle = get_le16(&pdu[1]);
+ *offset = get_le16(&pdu[3]);
*vlen = len - min_len;
if (*vlen > 0)
memcpy(value, pdu + min_len, *vlen);
diff --git a/attrib/gatt.c b/attrib/gatt.c
index 0d43913..83692f4 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -242,8 +242,8 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
struct gatt_primary *primary;
bt_uuid_t uuid;

- start = att_get_u16(&data[0]);
- end = att_get_u16(&data[2]);
+ start = get_le16(&data[0]);
+ end = get_le16(&data[2]);

if (list->len == 6) {
bt_uuid_t uuid16;
@@ -381,9 +381,9 @@ static struct gatt_included *included_from_buf(const uint8_t *buf, gsize len)
{
struct gatt_included *incl = g_new0(struct gatt_included, 1);

- incl->handle = att_get_u16(&buf[0]);
- incl->range.start = att_get_u16(&buf[2]);
- incl->range.end = att_get_u16(&buf[4]);
+ incl->handle = get_le16(&buf[0]);
+ incl->range.start = get_le16(&buf[2]);
+ incl->range.end = get_le16(&buf[4]);

if (len == 8) {
bt_uuid_t uuid128;
@@ -505,7 +505,7 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
struct gatt_char *chars;
bt_uuid_t uuid;

- last = att_get_u16(value);
+ last = get_le16(value);

if (list->len == 7) {
bt_uuid_t uuid16;
@@ -526,7 +526,7 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,

chars->handle = last;
chars->properties = value[2];
- chars->value_handle = att_get_u16(&value[3]);
+ chars->value_handle = get_le16(&value[3]);
bt_uuid_to_string(&uuid, chars->uuid, sizeof(chars->uuid));
dc->characteristics = g_slist_append(dc->characteristics,
chars);
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 31450a3..912dffb 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -37,6 +37,7 @@

#include "btio/btio.h"
#include "lib/uuid.h"
+#include "src/shared/util.h"
#include "src/log.h"
#include "attrib/att.h"
#include "attrib/gattrib.h"
@@ -381,7 +382,7 @@ static bool match_event(struct event *evt, const uint8_t *pdu, gsize len)
if (len < 3)
return false;

- handle = att_get_u16(&pdu[1]);
+ handle = get_le16(&pdu[1]);

if (evt->expected == pdu[0] && evt->handle == handle)
return true;
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 10415a8..4eb2528 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -79,7 +79,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
uint16_t handle, i, olen = 0;
size_t plen;

- handle = att_get_u16(&pdu[1]);
+ handle = get_le16(&pdu[1]);

switch (pdu[0]) {
case ATT_OP_HANDLE_NOTIFY:
@@ -272,7 +272,7 @@ static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
uint8_t *value = list->data[i];
int j;

- g_print("handle: 0x%04x \t value: ", att_get_u16(value));
+ g_print("handle: 0x%04x \t value: ", get_le16(value));
value += 2;
for (j = 0; j < list->len - 2; j++, value++)
g_print("%02x ", *value);
@@ -424,7 +424,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
bt_uuid_t uuid;

value = list->data[i];
- handle = att_get_u16(value);
+ handle = get_le16(value);

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 38403dd..5dd47ec 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -114,7 +114,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
size_t plen;
GString *s;

- handle = att_get_u16(&pdu[1]);
+ handle = get_le16(&pdu[1]);

switch (pdu[0]) {
case ATT_OP_HANDLE_NOTIFY:
@@ -293,7 +293,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
bt_uuid_t uuid;

value = list->data[i];
- handle = att_get_u16(value);
+ handle = get_le16(value);

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
@@ -362,7 +362,7 @@ static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
int j;

g_string_printf(s, "handle: 0x%04x \t value: ",
- att_get_u16(value));
+ get_le16(value));
value += 2;
for (j = 0; j < list->len - 2; j++, value++)
g_string_append_printf(s, "%02x ", *value);
diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index 1222532..63e969a 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -381,7 +381,7 @@ static void read_feature_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- csc->feature = att_get_u16(value);
+ csc->feature = get_le16(value);

if ((csc->feature & MULTI_SENSOR_LOC_SUPPORT)
&& (csc->locations == NULL))
@@ -447,8 +447,8 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu,
char *msg;

value = list->data[i];
- handle = att_get_u16(value);
- uuid = att_get_u16(value + 2);
+ handle = get_le16(value);
+ uuid = get_le16(value + 2);

if (uuid != GATT_CLIENT_CHARAC_CFG_UUID)
continue;
@@ -575,7 +575,7 @@ static void process_measurement(struct csc *csc, const uint8_t *pdu,

m.has_wheel_rev = true;
m.wheel_rev = get_le32(pdu);
- m.last_wheel_time = att_get_u16(pdu + 4);
+ m.last_wheel_time = get_le16(pdu + 4);
pdu += 6;
len -= 6;
}
@@ -587,8 +587,8 @@ static void process_measurement(struct csc *csc, const uint8_t *pdu,
}

m.has_crank_rev = true;
- m.crank_rev = att_get_u16(pdu);
- m.last_crank_time = att_get_u16(pdu + 2);
+ m.crank_rev = get_le16(pdu);
+ m.last_crank_time = get_le16(pdu + 2);
pdu += 4;
len -= 4;
}
diff --git a/profiles/deviceinfo/deviceinfo.c b/profiles/deviceinfo/deviceinfo.c
index 661a5dc..208598a 100644
--- a/profiles/deviceinfo/deviceinfo.c
+++ b/profiles/deviceinfo/deviceinfo.c
@@ -35,6 +35,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "attrib/gattrib.h"
#include "src/attio.h"
#include "attrib/att.h"
@@ -96,8 +97,8 @@ static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- btd_device_set_pnpid(ch->d->dev, value[0], att_get_u16(&value[1]),
- att_get_u16(&value[3]), att_get_u16(&value[5]));
+ btd_device_set_pnpid(ch->d->dev, value[0], get_le16(&value[1]),
+ get_le16(&value[3]), get_le16(&value[5]));
}

static void process_deviceinfo_char(struct characteristic *ch)
diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index c0526e5..38f5e72 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
@@ -40,6 +40,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "attrib/att.h"
#include "attrib/gattrib.h"
#include "src/attio.h"
@@ -165,7 +166,7 @@ static void gap_appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
}

atval = list->data[0] + 2; /* skip handle value */
- app = att_get_u16(atval);
+ app = get_le16(atval);

DBG("GAP Appearance: 0x%04x", app);

@@ -188,8 +189,8 @@ static void indication_cb(const uint8_t *pdu, uint16_t len, gpointer user_data)
return;
}

- start = att_get_u16(&pdu[3]);
- end = att_get_u16(&pdu[5]);
+ start = get_le16(&pdu[3]);
+ end = get_le16(&pdu[5]);

DBG("Service Changed start: 0x%04X end: 0x%04X", start, end);

@@ -263,8 +264,8 @@ static void gatt_descriptors_cb(guint8 status, const guint8 *pdu, guint16 len,
uint8_t *value;

value = list->data[i];
- ccc = att_get_u16(value);
- uuid16 = att_get_u16(&value[2]);
+ ccc = get_le16(value);
+ uuid16 = get_le16(&value[2]);
DBG("CCC: 0x%04x UUID: 0x%04x", ccc, uuid16);
write_ccc(gas->attrib, ccc, user_data);
}
diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index 97af02e..15ccdfd 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -35,6 +35,7 @@
#include "src/dbus-common.h"
#include "src/device.h"
#include "src/profile.h"
+#include "src/shared/util.h"
#include "src/service.h"
#include "src/error.h"
#include "attrib/gattrib.h"
@@ -324,7 +325,7 @@ static void process_measurement(struct heartrate *hr, const uint8_t *pdu,
return;
}

- m.value = att_get_u16(pdu);
+ m.value = get_le16(pdu);
pdu += 2;
len -= 2;
} else {
@@ -345,7 +346,7 @@ static void process_measurement(struct heartrate *hr, const uint8_t *pdu,
}

m.has_energy = TRUE;
- m.energy = att_get_u16(pdu);
+ m.energy = get_le16(pdu);
pdu += 2;
len -= 2;
}
@@ -362,7 +363,7 @@ static void process_measurement(struct heartrate *hr, const uint8_t *pdu,
m.interval = g_new(uint16_t, m.num_interval);

for (i = 0; i < m.num_interval; pdu += 2, i++)
- m.interval[i] = att_get_u16(pdu);
+ m.interval[i] = get_le16(pdu);
}

if (flags & SENSOR_CONTACT_SUPPORT) {
@@ -418,8 +419,8 @@ static void discover_ccc_cb(guint8 status, const guint8 *pdu,
uint8_t attr_val[2];

value = list->data[i];
- handle = att_get_u16(value);
- uuid = att_get_u16(value + 2);
+ handle = get_le16(value);
+ uuid = get_le16(value + 2);

if (uuid != GATT_CLIENT_CHARAC_CFG_UUID)
continue;
diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index fd72e36..25985ec 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -47,6 +47,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"

#include "src/plugin.h"

@@ -234,8 +235,8 @@ static void discover_descriptor_cb(guint8 status, const guint8 *pdu,
uint8_t *value;

value = list->data[i];
- handle = att_get_u16(value);
- uuid16 = att_get_u16(&value[2]);
+ handle = get_le16(value);
+ uuid16 = get_le16(&value[2]);

switch (uuid16) {
case GATT_CLIENT_CHARAC_CFG_UUID:
@@ -336,7 +337,7 @@ static void external_report_reference_cb(guint8 status, const guint8 *pdu,
return;
}

- uuid16 = att_get_u16(&pdu[1]);
+ uuid16 = get_le16(&pdu[1]);
DBG("External report reference read, external report characteristic "
"UUID: 0x%04x", uuid16);
bt_uuid16_create(&uuid, uuid16);
@@ -431,7 +432,7 @@ static void info_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
return;
}

- hogdev->bcdhid = att_get_u16(&value[0]);
+ hogdev->bcdhid = get_le16(&value[0]);
hogdev->bcountrycode = value[2];
hogdev->flags = value[3];

diff --git a/profiles/scanparam/scan.c b/profiles/scanparam/scan.c
index 4fd8f53..d6e477e 100644
--- a/profiles/scanparam/scan.c
+++ b/profiles/scanparam/scan.c
@@ -36,6 +36,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "attrib/att.h"
#include "attrib/gattrib.h"
#include "attrib/gatt.h"
@@ -119,8 +120,8 @@ static void discover_descriptor_cb(guint8 status, const guint8 *pdu,
goto done;

ptr = list->data[0];
- handle = att_get_u16(ptr);
- uuid16 = att_get_u16(&ptr[2]);
+ handle = get_le16(ptr);
+ uuid16 = get_le16(&ptr[2]);

if (uuid16 != GATT_CLIENT_CHARAC_CFG_UUID)
goto done;
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index d2ea56b..5b90792 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -383,7 +383,7 @@ static void proc_measurement(struct thermometer *t, const uint8_t *pdu,
return;
}

- ts.tm_year = att_get_u16(pdu) - 1900;
+ ts.tm_year = get_le16(pdu) - 1900;
ts.tm_mon = *(pdu + 2) - 1;
ts.tm_mday = *(pdu + 3);
ts.tm_hour = *(pdu + 4);
@@ -467,7 +467,7 @@ static void interval_ind_handler(const uint8_t *pdu, uint16_t len,
return;
}

- interval = att_get_u16(pdu + 3);
+ interval = get_le16(pdu + 3);
change_property(t, "Interval", &interval);

opdu = g_attrib_get_buffer(t->attrib, &plen);
@@ -502,8 +502,8 @@ static void valid_range_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- min = att_get_u16(&value[0]);
- max = att_get_u16(&value[2]);
+ min = get_le16(&value[0]);
+ max = get_le16(&value[2]);

if (min == 0 || min > max) {
DBG("Invalid range");
@@ -600,8 +600,8 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
uint16_t handle, uuid;

value = list->data[i];
- handle = att_get_u16(value);
- uuid = att_get_u16(value + 2);
+ handle = get_le16(value);
+ uuid = get_le16(value + 2);

process_thermometer_desc(ch, uuid, handle);
}
@@ -690,7 +690,7 @@ static void read_interval_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- interval = att_get_u16(&value[0]);
+ interval = get_le16(&value[0]);
change_property(t, "Interval", &interval);
}

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 889ef20..85e63a6 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -47,6 +47,7 @@
#include "hcid.h"
#include "adapter.h"
#include "device.h"
+#include "src/shared/util.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
#include "attrib/gatt.h"
@@ -307,7 +308,7 @@ static uint32_t attrib_create_sdp_new(struct gatt_server *server,
return 0;

if (a->len == 2)
- sdp_uuid16_create(&svc, att_get_u16(a->data));
+ sdp_uuid16_create(&svc, get_le16(a->data));
else if (a->len == 16)
sdp_uuid128_create(&svc, a->data);
else
@@ -894,7 +895,7 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle,
status, pdu, len);
}
} else {
- uint16_t cccval = att_get_u16(value);
+ uint16_t cccval = get_le16(value);
char *filename;
GKeyFile *key_file;
char group[6], value[5];
--
1.8.3.1


2014-03-24 19:25:36

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 15/22] Replace att_get_uuid16() by get_le16()

---
attrib/att.c | 6 +++---
attrib/gatt.c | 11 ++++++++---
attrib/gatttool.c | 3 ++-
attrib/interactive.c | 3 ++-
4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index c408568..b353499 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -168,7 +168,7 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
*start = att_get_u16(&pdu[1]);
*end = att_get_u16(&pdu[3]);
if (len == min_len + 2)
- *uuid = att_get_uuid16(&pdu[5]);
+ bt_uuid16_create(uuid, get_le16(&pdu[5]));
else
*uuid = att_get_uuid128(&pdu[5]);

@@ -297,7 +297,7 @@ uint16_t dec_find_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
/* Last requested handle number (2 octets) */
*end = att_get_u16(&pdu[3]);
/* 16-bit UUID to find (2 octets) */
- *uuid = att_get_uuid16(&pdu[5]);
+ bt_uuid16_create(uuid, get_le16(&pdu[5]));

/* Attribute value to find */
*vlen = len - 7;
@@ -411,7 +411,7 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
*end = att_get_u16(&pdu[3]);

if (len == min_len + 2)
- *uuid = att_get_uuid16(&pdu[5]);
+ bt_uuid16_create(uuid, get_le16(&pdu[5]));
else
*uuid = att_get_uuid128(&pdu[5]);

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 9c6dee1..0d43913 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -246,7 +246,9 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
end = att_get_u16(&data[2]);

if (list->len == 6) {
- bt_uuid_t uuid16 = att_get_uuid16(&data[4]);
+ bt_uuid_t uuid16;
+
+ bt_uuid16_create(&uuid16, get_le16(&data[4]));
bt_uuid_to_uuid128(&uuid16, &uuid);
} else if (list->len == 20) {
uuid = att_get_uuid128(&data[4]);
@@ -385,8 +387,9 @@ static struct gatt_included *included_from_buf(const uint8_t *buf, gsize len)

if (len == 8) {
bt_uuid_t uuid128;
- bt_uuid_t uuid16 = att_get_uuid16(&buf[6]);
+ bt_uuid_t uuid16;

+ bt_uuid16_create(&uuid16, get_le16(&buf[6]));
bt_uuid_to_uuid128(&uuid16, &uuid128);
bt_uuid_to_string(&uuid128, incl->uuid, sizeof(incl->uuid));
}
@@ -505,7 +508,9 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
last = att_get_u16(value);

if (list->len == 7) {
- bt_uuid_t uuid16 = att_get_uuid16(&value[5]);
+ bt_uuid_t uuid16;
+
+ bt_uuid16_create(&uuid16, get_le16(&value[5]));
bt_uuid_to_uuid128(&uuid16, &uuid);
} else
uuid = att_get_uuid128(&value[5]);
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 9f2ead9..10415a8 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -35,6 +35,7 @@
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "att.h"
#include "btio/btio.h"
@@ -426,7 +427,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
handle = att_get_u16(value);

if (format == 0x01)
- uuid = att_get_uuid16(&value[2]);
+ bt_uuid16_create(&uuid, get_le16(&value[2]));
else
uuid = att_get_uuid128(&value[2]);

diff --git a/attrib/interactive.c b/attrib/interactive.c
index 70c091c..38403dd 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -38,6 +38,7 @@
#include <readline/readline.h>
#include <readline/history.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "btio/btio.h"
#include "att.h"
@@ -295,7 +296,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
handle = att_get_u16(value);

if (format == 0x01)
- uuid = att_get_uuid16(&value[2]);
+ bt_uuid16_create(&uuid, get_le16(&value[2]));
else
uuid = att_get_uuid128(&value[2]);

--
1.8.3.1


2014-03-24 19:25:34

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 13/22] Replace att_put_u32() by put_le32()

---
profiles/cyclingspeed/cyclingspeed.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index 918f237..1222532 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -1167,7 +1167,7 @@ static DBusMessage *set_cumulative_wheel_rev(DBusConnection *conn,
csc->pending_req = req;

att_val[0] = SET_CUMULATIVE_VALUE;
- att_put_u32(value, att_val + 1);
+ put_le32(value, att_val + 1);

gatt_write_char(csc->attrib, csc->controlpoint_val_handle, att_val,
sizeof(att_val), controlpoint_write_cb, req);
--
1.8.3.1


2014-03-24 19:25:35

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 14/22] Replace att_put_uuid16() by put_le16()

---
attrib/att.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/attrib/att.c b/attrib/att.c
index e28be25..c408568 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -34,6 +34,7 @@

#include <glib.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "att.h"

@@ -267,7 +268,7 @@ uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
pdu[0] = ATT_OP_FIND_BY_TYPE_REQ;
att_put_u16(start, &pdu[1]);
att_put_u16(end, &pdu[3]);
- att_put_uuid16(*uuid, &pdu[5]);
+ put_le16(uuid->value.u16, &pdu[5]);

if (vlen > 0) {
memcpy(&pdu[7], value, vlen);
--
1.8.3.1


2014-03-24 19:25:33

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 12/22] Replace att_get_u32() by get_le32()

---
profiles/cyclingspeed/cyclingspeed.c | 3 ++-
profiles/thermometer/thermometer.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index f78c224..918f237 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -36,6 +36,7 @@
#include "src/profile.h"
#include "src/service.h"
#include "src/dbus-common.h"
+#include "src/shared/util.h"
#include "src/error.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
@@ -573,7 +574,7 @@ static void process_measurement(struct csc *csc, const uint8_t *pdu,
}

m.has_wheel_rev = true;
- m.wheel_rev = att_get_u32(pdu);
+ m.wheel_rev = get_le32(pdu);
m.last_wheel_time = att_get_u16(pdu + 4);
pdu += 6;
len -= 6;
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index c9ab759..d2ea56b 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -36,6 +36,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "src/error.h"
#include "src/log.h"
#include "attrib/gattrib.h"
@@ -361,7 +362,7 @@ static void proc_measurement(struct thermometer *t, const uint8_t *pdu,
return;
}

- raw = att_get_u32(pdu);
+ raw = get_le32(pdu);
m.mant = raw & 0x00FFFFFF;
m.exp = ((int32_t) raw) >> 24;

--
1.8.3.1


2014-03-24 19:25:32

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 11/22] attrib: Use LE helpers defined in src/shared/util.h

---
attrib/gatt.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 1db34be..9c6dee1 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -32,6 +32,7 @@
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "att.h"
#include "gattrib.h"
@@ -138,6 +139,15 @@ static struct discover_char *discover_char_ref(struct discover_char *dc)
return dc;
}

+static void put_uuid_le(const bt_uuid_t *uuid, void *dst)
+{
+ if (uuid->type == BT_UUID16)
+ put_le16(uuid->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&uuid->value.u128, dst);
+}
+
static guint16 encode_discover_primary(uint16_t start, uint16_t end,
bt_uuid_t *uuid, uint8_t *pdu, size_t len)
{
@@ -150,22 +160,12 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
/* Discover all primary services */
plen = enc_read_by_grp_req(start, end, &prim, pdu, len);
} else {
- uint16_t u16;
- uint128_t u128;
- const void *value;
+ uint8_t value[16];
size_t vlen;

/* Discover primary service by service UUID */
-
- if (uuid->type == BT_UUID16) {
- u16 = htobs(uuid->value.u16);
- value = &u16;
- vlen = sizeof(u16);
- } else {
- htob128(&uuid->value.u128, &u128);
- value = &u128;
- vlen = sizeof(u128);
- }
+ put_uuid_le(uuid, value);
+ vlen = bt_uuid_len(uuid);

plen = enc_find_by_type_req(start, end, &prim, value, vlen,
pdu, len);
--
1.8.3.1


2014-03-24 19:25:31

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 10/22] unit: Fix 128-bit UUID format

No matter the system, 128-bit UUID must use big endian byte order format
(similar to human-readable format).
---
unit/test-uuid.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/unit/test-uuid.c b/unit/test-uuid.c
index 225a7b5..6c7e9d0 100644
--- a/unit/test-uuid.c
+++ b/unit/test-uuid.c
@@ -97,7 +97,6 @@ static void test_uuid(gconstpointer data)
{
const struct uuid_test_data *test_data = data;
bt_uuid_t uuid;
- uint128_t n128, u128;

g_assert(bt_string_to_uuid(&uuid, test_data->str) == 0);
g_assert(uuid.type == test_data->type);
@@ -110,9 +109,11 @@ static void test_uuid(gconstpointer data)
g_assert(uuid.value.u32 == test_data->val32);
break;
case BT_UUID128:
- memcpy(&n128, test_data->binary, 16);
- ntoh128(&n128, &u128);
- g_assert(memcmp(&uuid.value.u128, &u128, 16) == 0);
+ /*
+ * No matter the system type: 128-bit UUID should use
+ * big-endian (human readable format).
+ */
+ g_assert(memcmp(&uuid.value.u128, test_data->binary, 16) == 0);
break;
default:
return;
--
1.8.3.1


2014-03-24 19:25:29

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 08/22] lib: Remove hton128() from bt_uuid_to_string()

bt_uuid_to_string() helper should get the raw UUID value. Caller should
convert the 128-bit UUID before call this helper (if applicable).
bt_uuid_t stores 128-bit UUID using big-endian format (human-readable
format), swapping byte order is not necessary.
---
lib/uuid.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/uuid.c b/lib/uuid.c
index aa2d0cf..dbca330 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -154,10 +154,7 @@ int bt_uuid_to_string(const bt_uuid_t *uuid, char *str, size_t n)
unsigned int data4;
unsigned short data5;

- uint128_t nvalue;
- const uint8_t *data = (uint8_t *) &nvalue;
-
- hton128(&uuid->value.u128, &nvalue);
+ const uint8_t *data = (uint8_t *) &uuid->value.u128;

memcpy(&data0, &data[0], 4);
memcpy(&data1, &data[4], 2);
--
1.8.3.1


2014-03-24 19:25:30

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 09/22] lib: Fix UUID 16/32-bits to 128-bit conversion

16 and 32-bit UUIDs are always created using host order. However,
no matter the system type, 128-bit UUID must use big-endian byte
order format (similar to human-readble format).
---
lib/uuid.c | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/lib/uuid.c b/lib/uuid.c
index dbca330..5c3f986 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -32,7 +32,6 @@

#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 }
@@ -41,33 +40,36 @@ static uint128_t bluetooth_base_uuid = {
#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 *src, bt_uuid_t *dst)
{
+ uint16_t be16;
+
dst->value.u128 = bluetooth_base_uuid;
dst->type = BT_UUID128;

- memcpy(&dst->value.u128.data[BASE_UUID16_OFFSET],
- &src->value.u16, sizeof(src->value.u16));
+ /*
+ * No matter the system: 128-bit UUIDs should be stored
+ * as big-endian. 16-bit UUIDs are stored on host order.
+ */
+
+ be16 = htons(src->value.u16);
+ memcpy(&dst->value.u128.data[BASE_UUID16_OFFSET], &be16, sizeof(be16));
}

static void bt_uuid32_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
{
+ uint32_t be32;
+
dst->value.u128 = bluetooth_base_uuid;
dst->type = BT_UUID128;

- memcpy(&dst->value.u128.data[BASE_UUID32_OFFSET],
- &src->value.u32, sizeof(src->value.u32));
+ /*
+ * No matter the system: 128-bit UUIDs should be stored
+ * as big-endian. 32-bit UUIDs are stored on host order.
+ */
+
+ be32 = htonl(src->value.u32);
+ memcpy(&dst->value.u128.data[BASE_UUID32_OFFSET], &be32, sizeof(be32));
}

void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
--
1.8.3.1


2014-03-24 19:25:28

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 07/22] lib: Remove ntoh128() from bt_string_to_uuid128()

No matter the system, 128-bit UUIDs should not be converted to any byte
order when creating the UUID. Conversion to big/little endian should be
performed when transfering the data over-the-air only. bt_uuid_t should
handle 128-bit UUID on big-endian format (human-readable format).
---
lib/uuid.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/uuid.c b/lib/uuid.c
index 4363aee..aa2d0cf 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -231,8 +231,8 @@ static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string)
{
uint32_t data0, data4;
uint16_t data1, data2, data3, data5;
- uint128_t n128, u128;
- uint8_t *val = (uint8_t *) &n128;
+ uint128_t u128;
+ uint8_t *val = (uint8_t *) &u128;

if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
&data0, &data1, &data2,
@@ -253,8 +253,6 @@ static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string)
memcpy(&val[10], &data4, 4);
memcpy(&val[14], &data5, 2);

- ntoh128(&n128, &u128);
-
bt_uuid128_create(uuid, u128);

return 0;
--
1.8.3.1


2014-03-24 19:25:27

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 06/22] Replace bt_put_be64() by get_be64()

---
profiles/audio/avrcp.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 1d439ec..da2a746 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2449,7 +2449,7 @@ static void avrcp_get_item_attributes(struct avrcp *session, uint64_t uid)

pdu->pdu_id = AVRCP_GET_ITEM_ATTRIBUTES;
pdu->params[0] = 0x03;
- bt_put_be64(uid, &pdu->params[1]);
+ put_be64(uid, &pdu->params[1]);
put_be16(player->uid_counter, &pdu->params[9]);
pdu->param_len = htons(12);

@@ -2636,7 +2636,7 @@ static void avrcp_change_path(struct avrcp *session, uint8_t direction,
memset(buf, 0, sizeof(buf));
put_be16(player->uid_counter, &pdu->params[0]);
pdu->params[2] = direction;
- bt_put_be64(uid, &pdu->params[3]);
+ put_be64(uid, &pdu->params[3]);
pdu->pdu_id = AVRCP_CHANGE_PATH;
pdu->param_len = htons(11);

@@ -2738,7 +2738,7 @@ static void avrcp_play_item(struct avrcp *session, uint64_t uid)
pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;

pdu->params[0] = player->scope;
- bt_put_be64(uid, &pdu->params[1]);
+ put_be64(uid, &pdu->params[1]);
put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
@@ -2784,7 +2784,7 @@ static void avrcp_add_to_nowplaying(struct avrcp *session, uint64_t uid)
pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;

pdu->params[0] = player->scope;
- bt_put_be64(uid, &pdu->params[1]);
+ put_be64(uid, &pdu->params[1]);
put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
--
1.8.3.1


2014-03-24 19:25:26

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 05/22] Replace bt_put_be32() by put_be32()

---
android/avrcp-lib.c | 6 +++---
android/avrcp.c | 2 +-
profiles/audio/avrcp.c | 4 ++--
src/sdpd-request.c | 4 ++--
src/sdpd-service.c | 2 +-
5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 5e9bb1a..c7b8b6a 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -713,7 +713,7 @@ int avrcp_register_notification(struct avrcp *session, uint8_t event,
uint8_t params[5];

params[0] = event;
- bt_put_be32(interval, &params[1]);
+ put_be32(interval, &params[1]);

return avrcp_send_req(session, AVC_CTYPE_NOTIFY, AVC_SUBUNIT_PANEL,
AVRCP_REGISTER_NOTIFICATION,
@@ -915,8 +915,8 @@ int avrcp_get_play_status_rsp(struct avrcp *session, uint8_t transaction,
{
uint8_t pdu[9];

- bt_put_be32(position, &pdu[0]);
- bt_put_be32(duration, &pdu[4]);
+ put_be32(position, &pdu[0]);
+ put_be32(duration, &pdu[4]);
pdu[8] = status;

return avrcp_send(session, transaction, AVC_CTYPE_STABLE,
diff --git a/android/avrcp.c b/android/avrcp.c
index 4f7163d..ec98139 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -180,7 +180,7 @@ static size_t write_element_text(uint8_t id, uint8_t text_len, uint8_t *text,
uint16_t charset = 106;
size_t len = 0;

- bt_put_be32(id, pdu);
+ put_be32(id, pdu);
pdu += 4;
len += 4;

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 913d2be..1d439ec 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2283,8 +2283,8 @@ static void avrcp_list_items(struct avrcp *session, uint32_t start,

pdu->params[0] = player->scope;

- bt_put_be32(start, &pdu->params[1]);
- bt_put_be32(end, &pdu->params[5]);
+ put_be32(start, &pdu->params[1]);
+ put_be32(end, &pdu->params[5]);

pdu->params[9] = 1;

diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 600237a..3e58c22 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -212,7 +212,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
memcpy(&tmp, p, sizeof(tmp));

pElem = malloc(sizeof(uint32_t));
- bt_put_be32(tmp, pElem);
+ put_be32(tmp, pElem);
}
p += sizeof(uint32_t);
seqlen += sizeof(uint32_t);
@@ -442,7 +442,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
if (sdp_match_uuid(pattern, rec->pattern) > 0 &&
sdp_check_access(rec->handle, &req->device)) {
rsp_count++;
- bt_put_be32(rec->handle, pdata);
+ put_be32(rec->handle, pdata);
pdata += sizeof(uint32_t);
handleSize += sizeof(uint32_t);
}
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index e001c30..a90b299 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -457,7 +457,7 @@ success:
update_db_timestamp();

/* Build a rsp buffer */
- bt_put_be32(rec->handle, rsp->data);
+ put_be32(rec->handle, rsp->data);
rsp->data_size = sizeof(uint32_t);

return 0;
--
1.8.3.1


2014-03-24 19:25:25

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 04/22] Replace bt_put_be16() by put_be16()

---
android/avrcp-lib.c | 8 ++++----
android/avrcp.c | 4 ++--
profiles/audio/avrcp.c | 12 ++++++------
profiles/sap/server.c | 2 +-
src/sdpd-request.c | 20 ++++++++++----------
src/sdpd-service.c | 6 +++---
6 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 934106b..5e9bb1a 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -815,7 +815,7 @@ int avrcp_set_addressed_player(struct avrcp *session, uint16_t player_id,
{
uint8_t params[2];

- bt_put_be16(player_id, params);
+ put_be16(player_id, params);

return avrcp_send_req(session, AVC_CTYPE_CONTROL, AVC_SUBUNIT_PANEL,
AVRCP_SET_ADDRESSED_PLAYER, params,
@@ -881,7 +881,7 @@ int avrcp_get_player_attribute_text_rsp(struct avrcp *session,
len = strlen(text[i]);

ptr[0] = attrs[i];
- bt_put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
+ put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
ptr[3] = len;
memcpy(&ptr[4], text[i], len);
ptr += 4 + len;
@@ -945,7 +945,7 @@ int avrcp_get_player_values_text_rsp(struct avrcp *session,
len = strlen(text[i]);

ptr[0] = values[i];
- bt_put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
+ put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
ptr[3] = len;
memcpy(&ptr[4], text[i], len);
ptr += 4 + len;
@@ -1016,7 +1016,7 @@ int avrcp_send_passthrough(struct avrcp *session, uint32_t vendor, uint8_t op)
return avctp_send_passthrough(session->conn, op, NULL, 0);

hton24(params, vendor);
- bt_put_be16(op, &params[3]);
+ put_be16(op, &params[3]);

return avctp_send_passthrough(session->conn, AVC_VENDOR_UNIQUE, params,
sizeof(params));
diff --git a/android/avrcp.c b/android/avrcp.c
index c8b4ec0..4f7163d 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -184,11 +184,11 @@ static size_t write_element_text(uint8_t id, uint8_t text_len, uint8_t *text,
pdu += 4;
len += 4;

- bt_put_be16(charset, pdu);
+ put_be16(charset, pdu);
pdu += 2;
len += 2;

- bt_put_be16(text_len, pdu);
+ put_be16(text_len, pdu);
pdu += 2;
len += 2;

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index ebd10a9..913d2be 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2450,7 +2450,7 @@ static void avrcp_get_item_attributes(struct avrcp *session, uint64_t uid)
pdu->pdu_id = AVRCP_GET_ITEM_ATTRIBUTES;
pdu->params[0] = 0x03;
bt_put_be64(uid, &pdu->params[1]);
- bt_put_be16(player->uid_counter, &pdu->params[9]);
+ put_be16(player->uid_counter, &pdu->params[9]);
pdu->param_len = htons(12);

avctp_send_browsing_req(session->conn, buf, sizeof(buf),
@@ -2634,7 +2634,7 @@ static void avrcp_change_path(struct avrcp *session, uint8_t direction,
struct avrcp_browsing_header *pdu = (void *) buf;

memset(buf, 0, sizeof(buf));
- bt_put_be16(player->uid_counter, &pdu->params[0]);
+ put_be16(player->uid_counter, &pdu->params[0]);
pdu->params[2] = direction;
bt_put_be64(uid, &pdu->params[3]);
pdu->pdu_id = AVRCP_CHANGE_PATH;
@@ -2700,8 +2700,8 @@ static void avrcp_search(struct avrcp *session, const char *string)
stringlen = strnlen(string, sizeof(buf) - len);
len += stringlen;

- bt_put_be16(AVRCP_CHARSET_UTF8, &pdu->params[0]);
- bt_put_be16(stringlen, &pdu->params[2]);
+ put_be16(AVRCP_CHARSET_UTF8, &pdu->params[0]);
+ put_be16(stringlen, &pdu->params[2]);
memcpy(&pdu->params[4], string, stringlen);
pdu->pdu_id = AVRCP_SEARCH;
pdu->param_len = htons(len - AVRCP_BROWSING_HEADER_LENGTH);
@@ -2739,7 +2739,7 @@ static void avrcp_play_item(struct avrcp *session, uint64_t uid)

pdu->params[0] = player->scope;
bt_put_be64(uid, &pdu->params[1]);
- bt_put_be16(player->uid_counter, &pdu->params[9]);
+ put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);

@@ -2785,7 +2785,7 @@ static void avrcp_add_to_nowplaying(struct avrcp *session, uint64_t uid)

pdu->params[0] = player->scope;
bt_put_be64(uid, &pdu->params[1]);
- bt_put_be16(player->uid_counter, &pdu->params[9]);
+ put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);

diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index 6b27cfa..20c6cab 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -668,7 +668,7 @@ int sap_connect_rsp(void *sap_device, uint8_t status)
param = (struct sap_parameter *) &buf[size];
param->id = SAP_PARAM_ID_MAX_MSG_SIZE;
param->len = htons(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);
- bt_put_be16(SAP_BUF_SIZE, &param->val);
+ put_be16(SAP_BUF_SIZE, &param->val);
size += PARAMETER_SIZE(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);

/* fall */
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index a9d92a6..600237a 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -184,7 +184,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
memcpy(&tmp, p, sizeof(tmp));

pElem = malloc(sizeof(uint16_t));
- bt_put_be16(tmp, pElem);
+ put_be16(tmp, pElem);
}
p += sizeof(uint16_t);
seqlen += sizeof(uint16_t);
@@ -419,13 +419,13 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)

/* total service record count = 0 */
pTotalRecordCount = pdata;
- bt_put_be16(0, pdata);
+ put_be16(0, pdata);
pdata += sizeof(uint16_t);
buf->data_size += sizeof(uint16_t);

/* current service record count = 0 */
pCurrentRecordCount = pdata;
- bt_put_be16(0, pdata);
+ put_be16(0, pdata);
pdata += sizeof(uint16_t);
buf->data_size += sizeof(uint16_t);

@@ -451,8 +451,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
SDPDBG("Match count: %d", rsp_count);

buf->data_size += handleSize;
- bt_put_be16(rsp_count, pTotalRecordCount);
- bt_put_be16(rsp_count, pCurrentRecordCount);
+ put_be16(rsp_count, pTotalRecordCount);
+ put_be16(rsp_count, pCurrentRecordCount);

if (rsp_count > actual) {
/* cache the rsp and generate a continuation state */
@@ -517,8 +517,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
}

buf->data_size += handleSize;
- bt_put_be16(rsp_count, pTotalRecordCount);
- bt_put_be16(i - lastIndex, pCurrentRecordCount);
+ put_be16(rsp_count, pTotalRecordCount);
+ put_be16(i - lastIndex, pCurrentRecordCount);

if (i == rsp_count) {
/* set "null" continuationState */
@@ -774,7 +774,7 @@ done:
return status;

/* set attribute list byte count */
- bt_put_be16(buf->data_size - cstate_size, buf->data);
+ put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
return 0;
}
@@ -945,7 +945,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)

if (!status) {
/* set attribute list byte count */
- bt_put_be16(buf->data_size - cstate_size, buf->data);
+ put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
}

@@ -1029,7 +1029,7 @@ static void process_request(sdp_req_t *req)
send_rsp:
if (status) {
rsphdr->pdu_id = SDP_ERROR_RSP;
- bt_put_be16(status, rsp.data);
+ put_be16(status, rsp.data);
rsp.data_size = sizeof(uint16_t);
}

diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index f763436..e001c30 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -463,7 +463,7 @@ success:
return 0;

invalid:
- bt_put_be16(SDP_INVALID_SYNTAX, rsp->data);
+ put_be16(SDP_INVALID_SYNTAX, rsp->data);
rsp->data_size = sizeof(uint16_t);

return -1;
@@ -506,7 +506,7 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp)

done:
p = rsp->data;
- bt_put_be16(status, p);
+ put_be16(status, p);
rsp->data_size = sizeof(uint16_t);
return status;
}
@@ -536,7 +536,7 @@ int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp)
}

p = rsp->data;
- bt_put_be16(status, p);
+ put_be16(status, p);
rsp->data_size = sizeof(uint16_t);

return status;
--
1.8.3.1


2014-03-24 19:25:24

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 03/22] Replace bt_get_be64() by get_be64()

---
android/avrcp-lib.c | 2 +-
monitor/sdp.c | 2 +-
profiles/audio/avrcp.c | 6 +++---
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 5e678ea..934106b 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -506,7 +506,7 @@ static ssize_t get_element_attributes(struct avrcp *session,
if (!params || params_len != 9 + params[8] * 4)
return -EINVAL;

- uid = bt_get_be64(params);
+ uid = get_be64(params);
number = params[8];

for (i = 0; i < number; i++) {
diff --git a/monitor/sdp.c b/monitor/sdp.c
index d729e1f..e997ca5 100644
--- a/monitor/sdp.c
+++ b/monitor/sdp.c
@@ -98,7 +98,7 @@ static void print_uint(uint8_t indent, const uint8_t *data, uint32_t size)
break;
case 8:
print_field("%*c0x%16.16" PRIx64, indent, ' ',
- bt_get_be64(data));
+ get_be64(data));
break;
default:
packet_hexdump(data, size);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 6772984..ebd10a9 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2126,7 +2126,7 @@ static struct media_item *parse_media_element(struct avrcp *session,
if (len < 13)
return NULL;

- uid = bt_get_be64(&operands[0]);
+ uid = get_be64(&operands[0]);

namelen = MIN(get_be16(&operands[11]), sizeof(name) - 1);
if (namelen > 0) {
@@ -2161,7 +2161,7 @@ static struct media_item *parse_media_folder(struct avrcp *session,
if (len < 12)
return NULL;

- uid = bt_get_be64(&operands[0]);
+ uid = get_be64(&operands[0]);
type = operands[8];
playable = operands[9];

@@ -3072,7 +3072,7 @@ static void avrcp_track_changed(struct avrcp *session,
{
if (session->browsing_id) {
struct avrcp_player *player = session->controller->player;
- player->uid = bt_get_be64(&pdu->params[1]);
+ player->uid = get_be64(&pdu->params[1]);
avrcp_get_item_attributes(session, player->uid);
} else
avrcp_get_element_attributes(session);
--
1.8.3.1


2014-03-24 19:25:23

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 02/22] Replace bt_get_be32() by get_be32()

---
android/avrcp-lib.c | 4 ++--
android/avrcp.c | 1 +
monitor/sdp.c | 20 ++++++++++----------
profiles/audio/avrcp.c | 12 ++++++------
profiles/network/bnep.c | 4 ++--
src/sdpd-request.c | 4 ++--
src/sdpd-service.c | 6 +++---
7 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 06aa552..5e678ea 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -510,7 +510,7 @@ static ssize_t get_element_attributes(struct avrcp *session,
number = params[8];

for (i = 0; i < number; i++) {
- attrs[i] = bt_get_be32(&params[9 + i * 4]);
+ attrs[i] = get_be32(&params[9 + i * 4]);

if (attrs[i] == AVRCP_MEDIA_ATTRIBUTE_ILLEGAL ||
attrs[i] > AVRCP_MEDIA_ATTRIBUTE_LAST)
@@ -540,7 +540,7 @@ static ssize_t register_notification(struct avrcp *session, uint8_t transaction,
if (!player->ind || !player->ind->register_notification)
return -ENOSYS;

- interval = bt_get_be32(&params[1]);
+ interval = get_be32(&params[1]);

return player->ind->register_notification(session, transaction,
params[0], interval,
diff --git a/android/avrcp.c b/android/avrcp.c
index abd1b03..c8b4ec0 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -35,6 +35,7 @@
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
#include "src/sdp-client.h"
+#include "src/shared/util.h"
#include "src/log.h"

#include "avctp.h"
diff --git a/monitor/sdp.c b/monitor/sdp.c
index a5e8ff4..d729e1f 100644
--- a/monitor/sdp.c
+++ b/monitor/sdp.c
@@ -94,7 +94,7 @@ static void print_uint(uint8_t indent, const uint8_t *data, uint32_t size)
print_field("%*c0x%4.4x", indent, ' ', get_be16(data));
break;
case 4:
- print_field("%*c0x%8.8x", indent, ' ', bt_get_be32(data));
+ print_field("%*c0x%8.8x", indent, ' ', get_be32(data));
break;
case 8:
print_field("%*c0x%16.16" PRIx64, indent, ' ',
@@ -120,22 +120,22 @@ static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size)
break;
case 4:
print_field("%*c%s (0x%8.8x)", indent, ' ',
- uuid32_to_str(bt_get_be32(data)), bt_get_be32(data));
+ uuid32_to_str(get_be32(data)), get_be32(data));
break;
case 16:
/* BASE_UUID = 00000000-0000-1000-8000-00805F9B34FB */
print_field("%*c%8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.4x",
indent, ' ',
- bt_get_be32(data), get_be16(data + 4),
+ get_be32(data), get_be16(data + 4),
get_be16(data + 6), get_be16(data + 8),
- get_be16(data + 10), bt_get_be32(data + 12));
+ get_be16(data + 10), get_be32(data + 12));
if (get_be16(data + 4) == 0x0000 &&
get_be16(data + 6) == 0x1000 &&
get_be16(data + 8) == 0x8000 &&
get_be16(data + 10) == 0x0080 &&
- bt_get_be32(data + 12) == 0x5F9B34FB)
+ get_be32(data + 12) == 0x5F9B34FB)
print_field("%*c%s", indent, ' ',
- uuid32_to_str(bt_get_be32(data)));
+ uuid32_to_str(get_be32(data)));
break;
default:
packet_hexdump(data, size);
@@ -237,7 +237,7 @@ static uint32_t get_size(const uint8_t *data, uint32_t size)
case 16:
return get_be16(data + 1);
case 32:
- return bt_get_be32(data + 1);
+ return get_be32(data + 1);
default:
return 0;
}
@@ -323,7 +323,7 @@ static uint32_t get_bytes(const uint8_t *data, uint32_t size)
case 6:
return 3 + get_be16(data + 1);
case 7:
- return 5 + bt_get_be32(data + 1);
+ return 5 + get_be32(data + 1);
}

return 0;
@@ -582,7 +582,7 @@ static void service_rsp(const struct l2cap_frame *frame, struct tid_data *tid)

for (i = 0; i < count; i++)
print_field("Record handle: 0x%4.4x",
- bt_get_be32(frame->data + 4 + (i * 4)));
+ get_be32(frame->data + 4 + (i * 4)));

print_continuation(frame->data + 4 + (count * 4),
frame->size - 4 - (count * 4));
@@ -598,7 +598,7 @@ static void attr_req(const struct l2cap_frame *frame, struct tid_data *tid)
return;
}

- print_field("Record handle: 0x%4.4x", bt_get_be32(frame->data));
+ print_field("Record handle: 0x%4.4x", get_be32(frame->data));
print_field("Max attribute bytes: %d", get_be16(frame->data + 4));

attr_bytes = get_bytes(frame->data + 6, frame->size - 6);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 8487682..6772984 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1082,7 +1082,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp *session,
for (i = 0, len = 0, attr_ids = NULL; i < nattr; i++) {
uint32_t id;

- id = bt_get_be32(&pdu->params[9] + (i * sizeof(id)));
+ id = get_be32(&pdu->params[9] + (i * sizeof(id)));

/* Don't add invalid attributes */
if (id == AVRCP_MEDIA_ATTRIBUTE_ILLEGAL ||
@@ -1990,7 +1990,7 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
uint32_t id;
uint16_t charset, len;

- id = bt_get_be32(&operands[i]);
+ id = get_be32(&operands[i]);
i += sizeof(uint32_t);

charset = get_be16(&operands[i]);
@@ -2319,7 +2319,7 @@ static gboolean avrcp_change_path_rsp(struct avctp *conn,
goto done;
}

- ret = bt_get_be32(&pdu->params[1]);
+ ret = get_be32(&pdu->params[1]);

done:
if (ret < 0) {
@@ -2357,7 +2357,7 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
player->uid_counter = get_be16(&pdu->params[1]);
player->browsed = true;

- items = bt_get_be32(&pdu->params[3]);
+ items = get_be32(&pdu->params[3]);

depth = pdu->params[9];

@@ -2681,7 +2681,7 @@ static gboolean avrcp_search_rsp(struct avctp *conn, uint8_t *operands,
}

player->uid_counter = get_be16(&pdu->params[1]);
- ret = bt_get_be32(&pdu->params[3]);
+ ret = get_be32(&pdu->params[3]);

done:
media_player_search_complete(mp, ret);
@@ -2908,7 +2908,7 @@ avrcp_parse_media_player_item(struct avrcp *session, uint8_t *operands,

media_player_set_type(mp, type_to_string(operands[2]));

- subtype = bt_get_be32(&operands[3]);
+ subtype = get_be32(&operands[3]);

media_player_set_subtype(mp, subtype_to_string(subtype));

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 8c95406..87304c5 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -650,13 +650,13 @@ uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,
/* Intentional no-break */

case 4: /* UUID32 */
- val = bt_get_be32(dest);
+ val = get_be32(dest);
if (val > 0xffff)
return BNEP_CONN_INVALID_DST;

*dst = val;

- val = bt_get_be32(source);
+ val = get_be32(source);
if (val > 0xffff)
return BNEP_CONN_INVALID_SRC;

diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index d2ec9e1..a9d92a6 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -203,7 +203,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
struct attrid *aid;
aid = malloc(sizeof(struct attrid));
aid->dtd = dataType;
- aid->uint32 = bt_get_be32(p);
+ aid->uint32 = get_be32(p);

pElem = (char *) aid;
} else {
@@ -648,7 +648,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- handle = bt_get_be32(pdata);
+ handle = get_be32(pdata);

pdata += sizeof(uint32_t);
data_left -= sizeof(uint32_t);
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index 06df94e..f763436 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -331,7 +331,7 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p,
SDPDBG("Unexpected end of packet");
return NULL;
}
- handle = bt_get_be32(p + sizeof(uint8_t) + sizeof(uint16_t) +
+ handle = get_be32(p + sizeof(uint8_t) + sizeof(uint16_t) +
sizeof(uint8_t));
SDPDBG("SvcRecHandle : 0x%x", handle);
rec = sdp_record_find(handle);
@@ -478,7 +478,7 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp)
int status = 0, scanned = 0;
uint8_t *p = req->buf + sizeof(sdp_pdu_hdr_t);
int bufsize = req->len - sizeof(sdp_pdu_hdr_t);
- uint32_t handle = bt_get_be32(p);
+ uint32_t handle = get_be32(p);

SDPDBG("Svc Rec Handle: 0x%x", handle);

@@ -517,7 +517,7 @@ done:
int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp)
{
uint8_t *p = req->buf + sizeof(sdp_pdu_hdr_t);
- uint32_t handle = bt_get_be32(p);
+ uint32_t handle = get_be32(p);
sdp_record_t *rec;
int status = 0;

--
1.8.3.1


2014-03-24 19:25:22

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 01/22] Replace bt_get_be16() by get_be16()

---
android/avrcp-lib.c | 3 ++-
monitor/sdp.c | 44 +++++++++++++++++++++++---------------------
profiles/audio/avrcp.c | 30 +++++++++++++++---------------
profiles/network/bnep.c | 5 +++--
profiles/sap/server.c | 3 ++-
src/sdpd-request.c | 12 +++++++-----
src/sdpd-service.c | 5 +++--
7 files changed, 55 insertions(+), 47 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 3f44315..06aa552 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -31,6 +31,7 @@

#include "lib/bluetooth.h"

+#include "src/shared/util.h"
#include "src/log.h"

#include "avctp.h"
@@ -561,7 +562,7 @@ static ssize_t set_addressed(struct avrcp *session, uint8_t transaction,
if (!player->ind || !player->ind->set_addressed)
return -ENOSYS;

- id = bt_get_be16(params);
+ id = get_be16(params);

return player->ind->set_addressed(session, transaction, id,
player->user_data);
diff --git a/monitor/sdp.c b/monitor/sdp.c
index dd72393..a5e8ff4 100644
--- a/monitor/sdp.c
+++ b/monitor/sdp.c
@@ -33,6 +33,8 @@

#include <bluetooth/bluetooth.h>

+#include "src/shared/util.h"
+
#include "bt.h"
#include "packet.h"
#include "display.h"
@@ -89,7 +91,7 @@ static void print_uint(uint8_t indent, const uint8_t *data, uint32_t size)
print_field("%*c0x%2.2x", indent, ' ', data[0]);
break;
case 2:
- print_field("%*c0x%4.4x", indent, ' ', bt_get_be16(data));
+ print_field("%*c0x%4.4x", indent, ' ', get_be16(data));
break;
case 4:
print_field("%*c0x%8.8x", indent, ' ', bt_get_be32(data));
@@ -114,7 +116,7 @@ static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size)
switch (size) {
case 2:
print_field("%*c%s (0x%4.4x)", indent, ' ',
- uuid16_to_str(bt_get_be16(data)), bt_get_be16(data));
+ uuid16_to_str(get_be16(data)), get_be16(data));
break;
case 4:
print_field("%*c%s (0x%8.8x)", indent, ' ',
@@ -124,13 +126,13 @@ static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size)
/* BASE_UUID = 00000000-0000-1000-8000-00805F9B34FB */
print_field("%*c%8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.4x",
indent, ' ',
- bt_get_be32(data), bt_get_be16(data + 4),
- bt_get_be16(data + 6), bt_get_be16(data + 8),
- bt_get_be16(data + 10), bt_get_be32(data + 12));
- if (bt_get_be16(data + 4) == 0x0000 &&
- bt_get_be16(data + 6) == 0x1000 &&
- bt_get_be16(data + 8) == 0x8000 &&
- bt_get_be16(data + 10) == 0x0080 &&
+ bt_get_be32(data), get_be16(data + 4),
+ get_be16(data + 6), get_be16(data + 8),
+ get_be16(data + 10), bt_get_be32(data + 12));
+ if (get_be16(data + 4) == 0x0000 &&
+ get_be16(data + 6) == 0x1000 &&
+ get_be16(data + 8) == 0x8000 &&
+ get_be16(data + 10) == 0x0080 &&
bt_get_be32(data + 12) == 0x5F9B34FB)
print_field("%*c%s", indent, ' ',
uuid32_to_str(bt_get_be32(data)));
@@ -233,7 +235,7 @@ static uint32_t get_size(const uint8_t *data, uint32_t size)
case 8:
return data[1];
case 16:
- return bt_get_be16(data + 1);
+ return get_be16(data + 1);
case 32:
return bt_get_be32(data + 1);
default:
@@ -319,7 +321,7 @@ static uint32_t get_bytes(const uint8_t *data, uint32_t size)
case 5:
return 2 + data[1];
case 6:
- return 3 + bt_get_be16(data + 1);
+ return 3 + get_be16(data + 1);
case 7:
return 5 + bt_get_be32(data + 1);
}
@@ -354,7 +356,7 @@ static void print_attr(uint32_t position, uint8_t indent, uint8_t type,
int i;

if ((position % 2) == 0) {
- uint16_t id = bt_get_be16(data);
+ uint16_t id = get_be16(data);
const char *str = "Unknown";

for (i = 0; attribute_table[i].str; i++) {
@@ -509,7 +511,7 @@ static uint16_t common_rsp(const struct l2cap_frame *frame,
return 0;
}

- bytes = bt_get_be16(frame->data);
+ bytes = get_be16(frame->data);
print_field("Attribute bytes: %d", bytes);

if (bytes > frame->size - 2) {
@@ -533,7 +535,7 @@ static void error_rsp(const struct l2cap_frame *frame, struct tid_data *tid)
return;
}

- error = bt_get_be16(frame->data);
+ error = get_be16(frame->data);

print_field("Error code: 0x%2.2x", error);
}
@@ -554,7 +556,7 @@ static void service_req(const struct l2cap_frame *frame, struct tid_data *tid)
decode_data_elements(0, 2, frame->data, search_bytes, NULL);

print_field("Max record count: %d",
- bt_get_be16(frame->data + search_bytes));
+ get_be16(frame->data + search_bytes));

print_continuation(frame->data + search_bytes + 2,
frame->size - search_bytes - 2);
@@ -573,9 +575,9 @@ static void service_rsp(const struct l2cap_frame *frame, struct tid_data *tid)
return;
}

- count = bt_get_be16(frame->data + 2);
+ count = get_be16(frame->data + 2);

- print_field("Total record count: %d", bt_get_be16(frame->data));
+ print_field("Total record count: %d", get_be16(frame->data));
print_field("Current record count: %d", count);

for (i = 0; i < count; i++)
@@ -597,7 +599,7 @@ static void attr_req(const struct l2cap_frame *frame, struct tid_data *tid)
}

print_field("Record handle: 0x%4.4x", bt_get_be32(frame->data));
- print_field("Max attribute bytes: %d", bt_get_be16(frame->data + 4));
+ print_field("Max attribute bytes: %d", get_be16(frame->data + 4));

attr_bytes = get_bytes(frame->data + 6, frame->size - 6);
print_field("Attribute list: [len %d]", attr_bytes);
@@ -643,7 +645,7 @@ static void search_attr_req(const struct l2cap_frame *frame,
decode_data_elements(0, 2, frame->data, search_bytes, NULL);

print_field("Max record count: %d",
- bt_get_be16(frame->data + search_bytes));
+ get_be16(frame->data + search_bytes));

attr_bytes = get_bytes(frame->data + search_bytes + 2,
frame->size - search_bytes - 2);
@@ -703,8 +705,8 @@ void sdp_packet(const struct l2cap_frame *frame, uint16_t channel)
}

pdu = *((uint8_t *) frame->data);
- tid = bt_get_be16(frame->data + 1);
- plen = bt_get_be16(frame->data + 3);
+ tid = get_be16(frame->data + 1);
+ plen = get_be16(frame->data + 3);

if (frame->size != plen + 5) {
print_text(COLOR_ERROR, "invalid frame size");
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index c7f2f0b..8487682 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1993,10 +1993,10 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
id = bt_get_be32(&operands[i]);
i += sizeof(uint32_t);

- charset = bt_get_be16(&operands[i]);
+ charset = get_be16(&operands[i]);
i += sizeof(uint16_t);

- len = bt_get_be16(&operands[i]);
+ len = get_be16(&operands[i]);
i += sizeof(uint16_t);

if (charset == 106) {
@@ -2128,7 +2128,7 @@ static struct media_item *parse_media_element(struct avrcp *session,

uid = bt_get_be64(&operands[0]);

- namelen = MIN(bt_get_be16(&operands[11]), sizeof(name) - 1);
+ namelen = MIN(get_be16(&operands[11]), sizeof(name) - 1);
if (namelen > 0) {
memcpy(name, &operands[13], namelen);
name[namelen] = '\0';
@@ -2165,7 +2165,7 @@ static struct media_item *parse_media_folder(struct avrcp *session,
type = operands[8];
playable = operands[9];

- namelen = MIN(bt_get_be16(&operands[12]), sizeof(name) - 1);
+ namelen = MIN(get_be16(&operands[12]), sizeof(name) - 1);
if (namelen > 0) {
memcpy(name, &operands[14], namelen);
name[namelen] = '\0';
@@ -2212,7 +2212,7 @@ static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands,
goto done;
}

- count = bt_get_be16(&operands[6]);
+ count = get_be16(&operands[6]);
if (count == 0)
goto done;

@@ -2222,7 +2222,7 @@ static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands,
uint16_t len;

type = operands[i++];
- len = bt_get_be16(&operands[i]);
+ len = get_be16(&operands[i]);
i += 2;

if (type != 0x03 && type != 0x02) {
@@ -2354,7 +2354,7 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
operand_count < 13)
return FALSE;

- player->uid_counter = bt_get_be16(&pdu->params[1]);
+ player->uid_counter = get_be16(&pdu->params[1]);
player->browsed = true;

items = bt_get_be32(&pdu->params[3]);
@@ -2680,7 +2680,7 @@ static gboolean avrcp_search_rsp(struct avctp *conn, uint8_t *operands,
goto done;
}

- player->uid_counter = bt_get_be16(&pdu->params[1]);
+ player->uid_counter = get_be16(&pdu->params[1]);
ret = bt_get_be32(&pdu->params[3]);

done:
@@ -2894,7 +2894,7 @@ avrcp_parse_media_player_item(struct avrcp *session, uint8_t *operands,
if (len < 28)
return NULL;

- id = bt_get_be16(&operands[0]);
+ id = get_be16(&operands[0]);

player = find_ct_player(session, id);
if (player == NULL) {
@@ -2922,7 +2922,7 @@ avrcp_parse_media_player_item(struct avrcp *session, uint8_t *operands,

avrcp_player_parse_features(player, &operands[8]);

- namelen = bt_get_be16(&operands[26]);
+ namelen = get_be16(&operands[26]);
if (namelen > 0 && namelen + 28 == len) {
namelen = MIN(namelen, sizeof(name) - 1);
memcpy(name, &operands[28], namelen);
@@ -2982,7 +2982,7 @@ static gboolean avrcp_get_media_player_list_rsp(struct avctp *conn,
return FALSE;

removed = g_slist_copy(session->controller->players);
- count = bt_get_be16(&operands[6]);
+ count = get_be16(&operands[6]);

for (i = 8; count && i < operand_count; count--) {
struct avrcp_player *player;
@@ -2990,7 +2990,7 @@ static gboolean avrcp_get_media_player_list_rsp(struct avctp *conn,
uint16_t len;

type = operands[i++];
- len = bt_get_be16(&operands[i]);
+ len = get_be16(&operands[i]);
i += 2;

if (type != 0x01) {
@@ -3112,7 +3112,7 @@ static void avrcp_addressed_player_changed(struct avrcp *session,
struct avrcp_header *pdu)
{
struct avrcp_player *player = session->controller->player;
- uint16_t id = bt_get_be16(&pdu->params[1]);
+ uint16_t id = get_be16(&pdu->params[1]);

if (player != NULL && player->id == id)
return;
@@ -3124,7 +3124,7 @@ static void avrcp_addressed_player_changed(struct avrcp *session,
return;
}

- player->uid_counter = bt_get_be16(&pdu->params[3]);
+ player->uid_counter = get_be16(&pdu->params[3]);
session->controller->player = player;

if (player->features != NULL)
@@ -3137,7 +3137,7 @@ static void avrcp_uids_changed(struct avrcp *session, struct avrcp_header *pdu)
{
struct avrcp_player *player = session->controller->player;

- player->uid_counter = bt_get_be16(&pdu->params[1]);
+ player->uid_counter = get_be16(&pdu->params[1]);
}

static gboolean avrcp_handle_event(struct avctp *conn,
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index b93027a..8c95406 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -43,6 +43,7 @@
#include <glib.h>

#include "src/log.h"
+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "btio/btio.h"

@@ -634,8 +635,8 @@ uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,

switch (req->uuid_size) {
case 2: /* UUID16 */
- *dst = bt_get_be16(dest);
- *src = bt_get_be16(source);
+ *dst = get_be16(dest);
+ *src = get_be16(source);
break;
case 16: /* UUID128 */
/* Check that the bytes in the UUID, except the service ID
diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index 711853f..6b27cfa 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -40,6 +40,7 @@
#include "src/log.h"
#include "src/error.h"
#include "src/dbus-common.h"
+#include "src/shared/util.h"
#include "sap.h"
#include "server.h"

@@ -312,7 +313,7 @@ static void connect_req(struct sap_server *server,

stop_guard_timer(server);

- maxmsgsize = bt_get_be16(&param->val);
+ maxmsgsize = get_be16(&param->val);

DBG("Connect MaxMsgSize: 0x%04x", maxmsgsize);

diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index fbeb488..d2ec9e1 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -37,6 +37,8 @@
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

+#include "src/shared/util.h"
+
#include "sdpd.h"
#include "log.h"

@@ -174,7 +176,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
struct attrid *aid;
aid = malloc(sizeof(struct attrid));
aid->dtd = dataType;
- aid->uint16 = bt_get_be16(p);
+ aid->uint16 = get_be16(p);
pElem = (char *) aid;
} else {
uint16_t tmp;
@@ -392,7 +394,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- expected = bt_get_be16(pdata);
+ expected = get_be16(pdata);

SDPDBG("Expected count: %d", expected);
SDPDBG("Bytes scanned : %d", scanned);
@@ -479,7 +481,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
if (pCache) {
pCacheBuffer = pCache->data;
/* get the rsp_count from the cached buffer */
- rsp_count = bt_get_be16(pCacheBuffer);
+ rsp_count = get_be16(pCacheBuffer);

/* get index of the last sdp_record_t sent */
lastIndex = cstate->cStateValue.lastIndexSent;
@@ -656,7 +658,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- max_rsp_size = bt_get_be16(pdata);
+ max_rsp_size = get_be16(pdata);

pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
@@ -813,7 +815,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- max = bt_get_be16(pdata);
+ max = get_be16(pdata);

pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index 38bf808..06df94e 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -39,6 +39,7 @@

#include <glib.h>

+#include "src/shared/util.h"
#include "sdpd.h"
#include "log.h"

@@ -320,7 +321,7 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p,
return NULL;
}

- lookAheadAttrId = bt_get_be16(p + sizeof(uint8_t));
+ lookAheadAttrId = get_be16(p + sizeof(uint8_t));

SDPDBG("Look ahead attr id : %d", lookAheadAttrId);

@@ -365,7 +366,7 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p,
seqlen, localExtractedLength);
dtd = *(uint8_t *) p;

- attrId = bt_get_be16(p + attrSize);
+ attrId = get_be16(p + attrSize);
attrSize += sizeof(uint16_t);

SDPDBG("DTD of attrId : %d Attr id : 0x%x", dtd, attrId);
--
1.8.3.1


2014-03-24 19:25:21

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH v1 00/22] Cleanup: Byte order

Changes from v1 to v0:
* Macros declared in lib/bluetooth.h should not be removed
* Fix creating 128-bit uuid_t based on GATT service

This patchset contains the following changes:
* Replace att_get_* and att_put_* by util.h helpers
* Replace bt_get_* and bt_put_* by util.h helpers
* Represent 128-bit bt_uuid_t using BIG-ENDIAN format
(human-readable format)

Claudio Takahasi (22):
Replace bt_get_be16() by get_be16()
Replace bt_get_be32() by get_be32()
Replace bt_get_be64() by get_be64()
Replace bt_put_be16() by put_be16()
Replace bt_put_be32() by put_be32()
Replace bt_put_be64() by get_be64()
lib: Remove ntoh128() from bt_string_to_uuid128()
lib: Remove hton128() from bt_uuid_to_string()
lib: Fix UUID 16/32-bits to 128-bit conversion
unit: Fix 128-bit UUID format
attrib: Use LE helpers defined in src/shared/util.h
Replace att_get_u32() by get_le32()
Replace att_put_u32() by put_le32()
Replace att_put_uuid16() by put_le16()
Replace att_get_uuid16() by get_le16()
Replace att_get_u16() by get_le16()
Replace att_get_uuid128() by bswap_128()
Replace att_put_uuid() by util.h helpers
Replace att_put_u16() by put_le16()
tools: Use unaligned access macros from util.h
core: Fix creating 128-bit uuid_t based on GATT service
attrib: Minor code optimization

android/avrcp-lib.c | 23 +++---
android/avrcp.c | 7 +-
attrib/att.c | 148 +++++++++++++++++++++--------------
attrib/gatt-service.c | 24 +++---
attrib/gatt.c | 112 ++++++++++++++++----------
attrib/gattrib.c | 3 +-
attrib/gatttool.c | 18 +++--
attrib/interactive.c | 18 +++--
lib/uuid.c | 45 +++++------
monitor/sdp.c | 62 ++++++++-------
plugins/gatt-example.c | 73 ++++++++---------
profiles/audio/avrcp.c | 72 ++++++++---------
profiles/cyclingspeed/cyclingspeed.c | 27 ++++---
profiles/deviceinfo/deviceinfo.c | 5 +-
profiles/gatt/gas.c | 13 +--
profiles/heartrate/heartrate.c | 19 ++---
profiles/input/hog.c | 9 ++-
profiles/network/bnep.c | 9 ++-
profiles/proximity/reporter.c | 7 +-
profiles/sap/server.c | 5 +-
profiles/scanparam/scan.c | 11 +--
profiles/thermometer/thermometer.c | 29 +++----
profiles/time/server.c | 3 +-
src/attrib-server.c | 52 +++++++-----
src/sdpd-request.c | 40 +++++-----
src/sdpd-service.c | 19 ++---
tools/parser/hci.c | 1 -
tools/parser/l2cap.c | 1 -
tools/parser/parser.h | 9 +--
tools/parser/ppp.c | 2 +-
unit/test-uuid.c | 9 ++-
31 files changed, 488 insertions(+), 387 deletions(-)

--
1.8.3.1


2014-03-21 12:29:08

by Anderson Lizardo

[permalink] [raw]
Subject: Re: [PATCH BlueZ v0 00/62] Cleanup: Byte order

Hi Lukasz,

On Fri, Mar 21, 2014 at 8:00 AM, Lukasz Rymanowski
<[email protected]> wrote:
>>> * Which 128-bit UUID bit order is being used on android? See
>>> android/gatt.c (primary_cb function)
>>
>> Android uses 128-bit little endian uuid.
>>
>
> Actually what I wrote is wrong. To be inline with UUID spec it is
> reverse big endian order :)

Actually, just to be precise, there is no such "reverse big endian
order". By the UUID spec, big endian is the canonical order for UUIDs
(I tend to think they are like a "packed" struct with several fields).
It is Bluetooth Core spec that, on GATT context, requires the UUID to
be reversed when sent over the air on ATT packets.

That said, I'm noticing some inconsistencies on the UUID handling
inside Android code, can you clarify/confirm each of them?

1) Profiles that are BR/EDR only (e.g. RFCOMM, PAN, A2DP etc.) are
using uuid_t from lib/sdp.c. This seems fine, as they are much like
existing non-Android code for these profiles.

2) HAL IPC is using "uint8_t[16]". I not sure about the byte order
here, but you confirm it is big endian right?

3) There are a few casts in android/hal-gatt.c: from the HAL IPC UUIDs
to bt_uuid_t (from Android). So it is safe to assume Android uses big
endian for bt_uuid_t?

4) android/gatt.c has a single usage of bt_uuid_t (now from
lib/uuid.h) where it just memcpy() the raw bytes. This is currently
broken upstream for 128-bit UUIDs because lib/uuid.c reverses bytes
internally on little endian systems, but it should be fixed once
remaining Claudio's patches are applied.

5) android/client/if-gatt.c has gatt_uuid_t2str()/gatt_str2bt_uuid_t()
which is assuming bt_uuid_t is in little endian order. This conflicts
with #3...

6) android/hal-utils.h has
bt_uuid_t2str()/btuuid2str()/str2bt_uuid_t() which assume big endian
for bt_uuid_t, so it agrees with #3. But they look very strange. They
are not following the UUID spec regarding UUID parsing.

Best Regards,
--
Anderson Lizardo
http://www.indt.org/?lang=en
INdT - Manaus - Brazil

2014-03-21 12:00:42

by Lukasz Rymanowski

[permalink] [raw]
Subject: Re: [PATCH BlueZ v0 00/62] Cleanup: Byte order

Hi Claudio,

On Fri, Mar 21, 2014 at 12:16 PM, Lukasz Rymanowski
<[email protected]> wrote:
> Hi Claudio,
>
> On Thu, Mar 20, 2014 at 3:42 PM, Claudio Takahasi
> <[email protected]> wrote:
>> Apply after "[PATCH BlueZ v5 00/16] Add basic GATT characteristics"
>>
>> This patchset contains the following changes:
>> * Replace att_get_* and att_put_* by util.h helpers
>> * Replace bt_get_* and bt_put_* by util.h helpers
>> * Represent 128-bit bt_uuid_t using BIG-ENDIAN format
>> (human-readable format)
>>
>> Open issues:
>> * Remove bt_get_* and bt_put_* from bluetooth.h? ("lib: Remove"
>> patches can be ignored)
>> * Which 128-bit UUID bit order is being used on android? See
>> android/gatt.c (primary_cb function)
>
> Android uses 128-bit little endian uuid.
>

Actually what I wrote is wrong. To be inline with UUID spec it is
reverse big endian order :)

>> * Should src/shared/util.h be included by lib/ files? IMO, lib should
>> be "self contained"
>>
>> TODO:
>> * Replace uint128_t by uint8_t[16]
>>
>> attrib/gatt-service.c and src/attrib-server.c should be removed in the
>> future, there are some repeated definitions of put_uuid_le() that can
>> be moved to a common header file IF necessary.
>>
>> Changing the 128-bit UUID representation makes bt_uuid_t similar to
>> uuid_t. This patchset allows replacing uuid_t in the future.
>>
>> Claudio Takahasi (62):
>> shared: Add put_le64()
>> shared: Add get_le16()
>> shared: Add get_le32()
>> shared: Add get_le64()
>> shared: Add get_be16()
>> shared: Add get_be32()
>> shared: Add get_be64()
>> shared: Add put_be16()
>> shared: Add put_be32()
>> shared: Add put_be64()
>> Replace bt_get_le16() by get_le16()
>> Replace bt_get_le32() by get_le32()
>> Replace bt_get_le64() by get_le64()
>> Replace bt_get_be16() by get_be16()
>> Replace bt_get_be32() by get_be32()
>> Replace bt_get_be64() by get_be64()
>> Replace bt_put_be16() by put_be16()
>> Replace bt_put_be32() by put_be32()
>> Replace bt_put_be64() by get_be64()
>> lib: Remove bt_put_le16()
>> lib: Remove bt_put_le32()
>> lib: Remove bt_put_le64()
>> lib: Remove bt_get_le16()
>> lib: Remove bt_get_le32()
>> lib: Remove bt_get_le64()
>> lib: Remove bt_get_be16()
>> lib: Remove bt_get_be32()
>> lib: Remove bt_get_be64()
>> lib: Remove bt_put_be16()
>> lib: Remove bt_put_be32()
>> lib: Remove bt_put_be64()
>> lib: Remove ntoh128() from bt_string_to_uuid128()
>> lib: Remove hton128() from bt_uuid_to_string()
>> lib: Fix UUID 16/32-bits to 128-bit conversion
>> unit: Use lower-case for 128-bit UUIDs
>> unit: Fix 128-bit UUID format
>> attrib: Use LE helpers defined in src/shared/util.h
>> Replace att_get_u32() by get_le32()
>> Replace att_put_u32() by put_le32()
>> Replace att_put_uuid16() by put_le16()
>> Replace att_get_uuid16() by get_le16()
>> Replace att_get_u16() by get_le16()
>> Replace att_get_uuid128() by bswap_128()
>> Replace att_put_uuid() by util.h helpers
>> Replace att_put_u16() by put_le16()
>> attrib: Remove att_get_u8()
>> attrib: Remove att_put_u8()
>> attrib: Remove att_get_u32()
>> attrib: Remove att_put_u32()
>> attrib: Remove att_get_uuid16()
>> attrib: Remove att_get_u16()
>> attrib: Remove att_get_uuid128()
>> attrib: Remove att_get_u128()
>> attrib: Remove att_put_uuid()
>> attrib: Remove att_put_uuid128()
>> attrib: Remove att_put_u128()
>> attrib: Remove att_put_uuid16()
>> attrib: Remove att_put_u16()
>> lib: Use get_unaligned() instead of bt_get_unaligned()
>> tools: Use unaligned access macros from util.h
>> lib: Remove bt_get_unaligned()
>> lib: Remove bt_put_unaligned()
>>
>> android/android-tester.c | 3 +-
>> android/avrcp-lib.c | 23 +++---
>> android/avrcp.c | 7 +-
>> android/bluetooth.c | 3 +-
>> attrib/att.c | 148 +++++++++++++++++++++--------------
>> attrib/att.h | 89 ---------------------
>> attrib/gatt-service.c | 24 +++---
>> attrib/gatt.c | 112 ++++++++++++++++----------
>> attrib/gattrib.c | 3 +-
>> attrib/gatttool.c | 18 +++--
>> attrib/interactive.c | 18 +++--
>> lib/bluetooth.h | 142 ---------------------------------
>> lib/sdp.c | 83 ++++++++++----------
>> lib/uuid.c | 40 ++++------
>> monitor/control.c | 2 +-
>> monitor/l2cap.c | 92 +++++++++++-----------
>> monitor/packet.c | 46 +++++------
>> monitor/sdp.c | 62 ++++++++-------
>> plugins/gatt-example.c | 73 ++++++++---------
>> profiles/audio/avrcp.c | 75 +++++++++---------
>> profiles/cyclingspeed/cyclingspeed.c | 27 ++++---
>> profiles/deviceinfo/deviceinfo.c | 5 +-
>> profiles/gatt/gas.c | 13 +--
>> profiles/heartrate/heartrate.c | 19 ++---
>> profiles/input/hog.c | 9 ++-
>> profiles/network/bnep.c | 9 ++-
>> profiles/proximity/reporter.c | 9 ++-
>> profiles/sap/server.c | 5 +-
>> profiles/scanparam/scan.c | 11 +--
>> profiles/thermometer/thermometer.c | 29 +++----
>> profiles/time/server.c | 3 +-
>> src/adapter.c | 4 +-
>> src/attrib-server.c | 42 ++++++----
>> src/eir.c | 8 +-
>> src/sdpd-request.c | 40 +++++-----
>> src/sdpd-service.c | 19 ++---
>> src/shared/util.h | 50 ++++++++++++
>> tools/btmgmt.c | 32 ++++----
>> tools/hciconfig.c | 3 +-
>> tools/l2test.c | 4 +-
>> tools/mgmt-tester.c | 3 +-
>> tools/parser/hci.c | 2 +-
>> tools/parser/l2cap.c | 24 +++---
>> tools/parser/parser.h | 9 +--
>> tools/parser/ppp.c | 2 +-
>> unit/test-uuid.c | 13 +--
>> 46 files changed, 689 insertions(+), 768 deletions(-)
>>
>> --
>> 1.8.3.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
>
> \Lukasz

\Lukasz

2014-03-21 11:16:57

by Lukasz Rymanowski

[permalink] [raw]
Subject: Re: [PATCH BlueZ v0 00/62] Cleanup: Byte order

Hi Claudio,

On Thu, Mar 20, 2014 at 3:42 PM, Claudio Takahasi
<[email protected]> wrote:
> Apply after "[PATCH BlueZ v5 00/16] Add basic GATT characteristics"
>
> This patchset contains the following changes:
> * Replace att_get_* and att_put_* by util.h helpers
> * Replace bt_get_* and bt_put_* by util.h helpers
> * Represent 128-bit bt_uuid_t using BIG-ENDIAN format
> (human-readable format)
>
> Open issues:
> * Remove bt_get_* and bt_put_* from bluetooth.h? ("lib: Remove"
> patches can be ignored)
> * Which 128-bit UUID bit order is being used on android? See
> android/gatt.c (primary_cb function)

Android uses 128-bit little endian uuid.

> * Should src/shared/util.h be included by lib/ files? IMO, lib should
> be "self contained"
>
> TODO:
> * Replace uint128_t by uint8_t[16]
>
> attrib/gatt-service.c and src/attrib-server.c should be removed in the
> future, there are some repeated definitions of put_uuid_le() that can
> be moved to a common header file IF necessary.
>
> Changing the 128-bit UUID representation makes bt_uuid_t similar to
> uuid_t. This patchset allows replacing uuid_t in the future.
>
> Claudio Takahasi (62):
> shared: Add put_le64()
> shared: Add get_le16()
> shared: Add get_le32()
> shared: Add get_le64()
> shared: Add get_be16()
> shared: Add get_be32()
> shared: Add get_be64()
> shared: Add put_be16()
> shared: Add put_be32()
> shared: Add put_be64()
> Replace bt_get_le16() by get_le16()
> Replace bt_get_le32() by get_le32()
> Replace bt_get_le64() by get_le64()
> Replace bt_get_be16() by get_be16()
> Replace bt_get_be32() by get_be32()
> Replace bt_get_be64() by get_be64()
> Replace bt_put_be16() by put_be16()
> Replace bt_put_be32() by put_be32()
> Replace bt_put_be64() by get_be64()
> lib: Remove bt_put_le16()
> lib: Remove bt_put_le32()
> lib: Remove bt_put_le64()
> lib: Remove bt_get_le16()
> lib: Remove bt_get_le32()
> lib: Remove bt_get_le64()
> lib: Remove bt_get_be16()
> lib: Remove bt_get_be32()
> lib: Remove bt_get_be64()
> lib: Remove bt_put_be16()
> lib: Remove bt_put_be32()
> lib: Remove bt_put_be64()
> lib: Remove ntoh128() from bt_string_to_uuid128()
> lib: Remove hton128() from bt_uuid_to_string()
> lib: Fix UUID 16/32-bits to 128-bit conversion
> unit: Use lower-case for 128-bit UUIDs
> unit: Fix 128-bit UUID format
> attrib: Use LE helpers defined in src/shared/util.h
> Replace att_get_u32() by get_le32()
> Replace att_put_u32() by put_le32()
> Replace att_put_uuid16() by put_le16()
> Replace att_get_uuid16() by get_le16()
> Replace att_get_u16() by get_le16()
> Replace att_get_uuid128() by bswap_128()
> Replace att_put_uuid() by util.h helpers
> Replace att_put_u16() by put_le16()
> attrib: Remove att_get_u8()
> attrib: Remove att_put_u8()
> attrib: Remove att_get_u32()
> attrib: Remove att_put_u32()
> attrib: Remove att_get_uuid16()
> attrib: Remove att_get_u16()
> attrib: Remove att_get_uuid128()
> attrib: Remove att_get_u128()
> attrib: Remove att_put_uuid()
> attrib: Remove att_put_uuid128()
> attrib: Remove att_put_u128()
> attrib: Remove att_put_uuid16()
> attrib: Remove att_put_u16()
> lib: Use get_unaligned() instead of bt_get_unaligned()
> tools: Use unaligned access macros from util.h
> lib: Remove bt_get_unaligned()
> lib: Remove bt_put_unaligned()
>
> android/android-tester.c | 3 +-
> android/avrcp-lib.c | 23 +++---
> android/avrcp.c | 7 +-
> android/bluetooth.c | 3 +-
> attrib/att.c | 148 +++++++++++++++++++++--------------
> attrib/att.h | 89 ---------------------
> attrib/gatt-service.c | 24 +++---
> attrib/gatt.c | 112 ++++++++++++++++----------
> attrib/gattrib.c | 3 +-
> attrib/gatttool.c | 18 +++--
> attrib/interactive.c | 18 +++--
> lib/bluetooth.h | 142 ---------------------------------
> lib/sdp.c | 83 ++++++++++----------
> lib/uuid.c | 40 ++++------
> monitor/control.c | 2 +-
> monitor/l2cap.c | 92 +++++++++++-----------
> monitor/packet.c | 46 +++++------
> monitor/sdp.c | 62 ++++++++-------
> plugins/gatt-example.c | 73 ++++++++---------
> profiles/audio/avrcp.c | 75 +++++++++---------
> profiles/cyclingspeed/cyclingspeed.c | 27 ++++---
> profiles/deviceinfo/deviceinfo.c | 5 +-
> profiles/gatt/gas.c | 13 +--
> profiles/heartrate/heartrate.c | 19 ++---
> profiles/input/hog.c | 9 ++-
> profiles/network/bnep.c | 9 ++-
> profiles/proximity/reporter.c | 9 ++-
> profiles/sap/server.c | 5 +-
> profiles/scanparam/scan.c | 11 +--
> profiles/thermometer/thermometer.c | 29 +++----
> profiles/time/server.c | 3 +-
> src/adapter.c | 4 +-
> src/attrib-server.c | 42 ++++++----
> src/eir.c | 8 +-
> src/sdpd-request.c | 40 +++++-----
> src/sdpd-service.c | 19 ++---
> src/shared/util.h | 50 ++++++++++++
> tools/btmgmt.c | 32 ++++----
> tools/hciconfig.c | 3 +-
> tools/l2test.c | 4 +-
> tools/mgmt-tester.c | 3 +-
> tools/parser/hci.c | 2 +-
> tools/parser/l2cap.c | 24 +++---
> tools/parser/parser.h | 9 +--
> tools/parser/ppp.c | 2 +-
> unit/test-uuid.c | 13 +--
> 46 files changed, 689 insertions(+), 768 deletions(-)
>
> --
> 1.8.3.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

\Lukasz

2014-03-21 08:46:03

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH BlueZ v0 35/62] unit: Use lower-case for 128-bit UUIDs

Hi Claudio,

On Thu, Mar 20, 2014, Claudio Takahasi wrote:
> According to ISO/IEC 9834-8: "It is recommended that the hexadecimal
> representation used in all human-readable formats be restricted to
> lower-case letters. Software processing this representation is, however,
> required to accept both upper and lower case letters as specified in
> 6.5.2."
> ---
> unit/test-uuid.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)

This patch has also been applied.

Johan

2014-03-21 08:44:08

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH BlueZ v0 14/62] Replace bt_get_be16() by get_be16()

Hi Claudio,

On Thu, Mar 20, 2014, Claudio Takahasi wrote:
> ---
> android/avrcp-lib.c | 3 ++-
> lib/sdp.c | 25 +++++++++++++------------
> monitor/sdp.c | 44 +++++++++++++++++++++++---------------------
> profiles/audio/avrcp.c | 30 +++++++++++++++---------------
> profiles/network/bnep.c | 5 +++--
> profiles/sap/server.c | 3 ++-
> src/sdpd-request.c | 12 +++++++-----
> src/sdpd-service.c | 5 +++--
> 8 files changed, 68 insertions(+), 59 deletions(-)

I've applied patches 1-13 but had to stop with this one due to lib/*
code that should keep using the old functions. I also had to apply an
extra patch to fix an incorrect "const" you had for the destination
pointer in the 32 and 64 bit put functions.

Johan

2014-03-20 14:42:51

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 26/62] lib: Remove bt_get_be16()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 37fa04d..3dcb049 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -182,11 +182,6 @@ static inline uint32_t bt_get_be32(const void *ptr)
return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
}

-static inline uint16_t bt_get_be16(const void *ptr)
-{
- return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
@@ -214,11 +209,6 @@ static inline uint32_t bt_get_be32(const void *ptr)
return bt_get_unaligned((const uint32_t *) ptr);
}

-static inline uint16_t bt_get_be16(const void *ptr)
-{
- return bt_get_unaligned((const uint16_t *) ptr);
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(val, (uint64_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:49

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 24/62] lib: Remove bt_get_le32()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 58ad96a..f045070 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -182,11 +182,6 @@ static inline uint64_t bt_get_be64(const void *ptr)
return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
}

-static inline uint32_t bt_get_le32(const void *ptr)
-{
- return bt_get_unaligned((const uint32_t *) ptr);
-}
-
static inline uint32_t bt_get_be32(const void *ptr)
{
return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
@@ -223,11 +218,6 @@ static inline uint64_t bt_get_be64(const void *ptr)
return bt_get_unaligned((const uint64_t *) ptr);
}

-static inline uint32_t bt_get_le32(const void *ptr)
-{
- return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
-}
-
static inline uint32_t bt_get_be32(const void *ptr)
{
return bt_get_unaligned((const uint32_t *) ptr);
--
1.8.3.1


2014-03-20 14:43:02

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 37/62] attrib: Use LE helpers defined in src/shared/util.h

---
attrib/gatt.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 1db34be..9c6dee1 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -32,6 +32,7 @@
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "att.h"
#include "gattrib.h"
@@ -138,6 +139,15 @@ static struct discover_char *discover_char_ref(struct discover_char *dc)
return dc;
}

+static void put_uuid_le(const bt_uuid_t *uuid, void *dst)
+{
+ if (uuid->type == BT_UUID16)
+ put_le16(uuid->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&uuid->value.u128, dst);
+}
+
static guint16 encode_discover_primary(uint16_t start, uint16_t end,
bt_uuid_t *uuid, uint8_t *pdu, size_t len)
{
@@ -150,22 +160,12 @@ static guint16 encode_discover_primary(uint16_t start, uint16_t end,
/* Discover all primary services */
plen = enc_read_by_grp_req(start, end, &prim, pdu, len);
} else {
- uint16_t u16;
- uint128_t u128;
- const void *value;
+ uint8_t value[16];
size_t vlen;

/* Discover primary service by service UUID */
-
- if (uuid->type == BT_UUID16) {
- u16 = htobs(uuid->value.u16);
- value = &u16;
- vlen = sizeof(u16);
- } else {
- htob128(&uuid->value.u128, &u128);
- value = &u128;
- vlen = sizeof(u128);
- }
+ put_uuid_le(uuid, value);
+ vlen = bt_uuid_len(uuid);

plen = enc_find_by_type_req(start, end, &prim, value, vlen,
pdu, len);
--
1.8.3.1


2014-03-20 14:43:01

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 36/62] unit: Fix 128-bit UUID format

No matter the system, 128-bit UUID must use big endian byte order format
(similar to human-readable format).
---
unit/test-uuid.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/unit/test-uuid.c b/unit/test-uuid.c
index 225a7b5..6c7e9d0 100644
--- a/unit/test-uuid.c
+++ b/unit/test-uuid.c
@@ -97,7 +97,6 @@ static void test_uuid(gconstpointer data)
{
const struct uuid_test_data *test_data = data;
bt_uuid_t uuid;
- uint128_t n128, u128;

g_assert(bt_string_to_uuid(&uuid, test_data->str) == 0);
g_assert(uuid.type == test_data->type);
@@ -110,9 +109,11 @@ static void test_uuid(gconstpointer data)
g_assert(uuid.value.u32 == test_data->val32);
break;
case BT_UUID128:
- memcpy(&n128, test_data->binary, 16);
- ntoh128(&n128, &u128);
- g_assert(memcmp(&uuid.value.u128, &u128, 16) == 0);
+ /*
+ * No matter the system type: 128-bit UUID should use
+ * big-endian (human readable format).
+ */
+ g_assert(memcmp(&uuid.value.u128, test_data->binary, 16) == 0);
break;
default:
return;
--
1.8.3.1


2014-03-20 14:43:03

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 38/62] Replace att_get_u32() by get_le32()

---
profiles/cyclingspeed/cyclingspeed.c | 3 ++-
profiles/thermometer/thermometer.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index f78c224..918f237 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -36,6 +36,7 @@
#include "src/profile.h"
#include "src/service.h"
#include "src/dbus-common.h"
+#include "src/shared/util.h"
#include "src/error.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
@@ -573,7 +574,7 @@ static void process_measurement(struct csc *csc, const uint8_t *pdu,
}

m.has_wheel_rev = true;
- m.wheel_rev = att_get_u32(pdu);
+ m.wheel_rev = get_le32(pdu);
m.last_wheel_time = att_get_u16(pdu + 4);
pdu += 6;
len -= 6;
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index c9ab759..d2ea56b 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -36,6 +36,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "src/error.h"
#include "src/log.h"
#include "attrib/gattrib.h"
@@ -361,7 +362,7 @@ static void proc_measurement(struct thermometer *t, const uint8_t *pdu,
return;
}

- raw = att_get_u32(pdu);
+ raw = get_le32(pdu);
m.mant = raw & 0x00FFFFFF;
m.exp = ((int32_t) raw) >> 24;

--
1.8.3.1


2014-03-20 14:42:54

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 29/62] lib: Remove bt_put_be16()

---
lib/bluetooth.h | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index eb623cc..aa959ef 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -182,11 +182,6 @@ static inline void bt_put_be32(uint32_t val, const void *ptr)
bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
}

-static inline void bt_put_be16(uint16_t val, const void *ptr)
-{
- bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
-}
-
#elif __BYTE_ORDER == __BIG_ENDIAN

static inline void bt_put_be64(uint64_t val, const void *ptr)
@@ -199,10 +194,6 @@ static inline void bt_put_be32(uint32_t val, const void *ptr)
bt_put_unaligned(val, (uint32_t *) ptr);
}

-static inline void bt_put_be16(uint16_t val, const void *ptr)
-{
- bt_put_unaligned(val, (uint16_t *) ptr);
-}
#else
#error "Unknown byte order"
#endif
--
1.8.3.1


2014-03-20 14:43:06

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 41/62] Replace att_get_uuid16() by get_le16()

---
attrib/att.c | 6 +++---
attrib/gatt.c | 11 ++++++++---
attrib/gatttool.c | 3 ++-
attrib/interactive.c | 3 ++-
4 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index c408568..b353499 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -168,7 +168,7 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
*start = att_get_u16(&pdu[1]);
*end = att_get_u16(&pdu[3]);
if (len == min_len + 2)
- *uuid = att_get_uuid16(&pdu[5]);
+ bt_uuid16_create(uuid, get_le16(&pdu[5]));
else
*uuid = att_get_uuid128(&pdu[5]);

@@ -297,7 +297,7 @@ uint16_t dec_find_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
/* Last requested handle number (2 octets) */
*end = att_get_u16(&pdu[3]);
/* 16-bit UUID to find (2 octets) */
- *uuid = att_get_uuid16(&pdu[5]);
+ bt_uuid16_create(uuid, get_le16(&pdu[5]));

/* Attribute value to find */
*vlen = len - 7;
@@ -411,7 +411,7 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
*end = att_get_u16(&pdu[3]);

if (len == min_len + 2)
- *uuid = att_get_uuid16(&pdu[5]);
+ bt_uuid16_create(uuid, get_le16(&pdu[5]));
else
*uuid = att_get_uuid128(&pdu[5]);

diff --git a/attrib/gatt.c b/attrib/gatt.c
index 9c6dee1..0d43913 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -246,7 +246,9 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
end = att_get_u16(&data[2]);

if (list->len == 6) {
- bt_uuid_t uuid16 = att_get_uuid16(&data[4]);
+ bt_uuid_t uuid16;
+
+ bt_uuid16_create(&uuid16, get_le16(&data[4]));
bt_uuid_to_uuid128(&uuid16, &uuid);
} else if (list->len == 20) {
uuid = att_get_uuid128(&data[4]);
@@ -385,8 +387,9 @@ static struct gatt_included *included_from_buf(const uint8_t *buf, gsize len)

if (len == 8) {
bt_uuid_t uuid128;
- bt_uuid_t uuid16 = att_get_uuid16(&buf[6]);
+ bt_uuid_t uuid16;

+ bt_uuid16_create(&uuid16, get_le16(&buf[6]));
bt_uuid_to_uuid128(&uuid16, &uuid128);
bt_uuid_to_string(&uuid128, incl->uuid, sizeof(incl->uuid));
}
@@ -505,7 +508,9 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
last = att_get_u16(value);

if (list->len == 7) {
- bt_uuid_t uuid16 = att_get_uuid16(&value[5]);
+ bt_uuid_t uuid16;
+
+ bt_uuid16_create(&uuid16, get_le16(&value[5]));
bt_uuid_to_uuid128(&uuid16, &uuid);
} else
uuid = att_get_uuid128(&value[5]);
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 9f2ead9..10415a8 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -35,6 +35,7 @@
#include <bluetooth/hci.h>
#include <bluetooth/hci_lib.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "att.h"
#include "btio/btio.h"
@@ -426,7 +427,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
handle = att_get_u16(value);

if (format == 0x01)
- uuid = att_get_uuid16(&value[2]);
+ bt_uuid16_create(&uuid, get_le16(&value[2]));
else
uuid = att_get_uuid128(&value[2]);

diff --git a/attrib/interactive.c b/attrib/interactive.c
index 70c091c..38403dd 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -38,6 +38,7 @@
#include <readline/readline.h>
#include <readline/history.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "btio/btio.h"
#include "att.h"
@@ -295,7 +296,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
handle = att_get_u16(value);

if (format == 0x01)
- uuid = att_get_uuid16(&value[2]);
+ bt_uuid16_create(&uuid, get_le16(&value[2]));
else
uuid = att_get_uuid128(&value[2]);

--
1.8.3.1


2014-03-20 14:43:05

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 40/62] Replace att_put_uuid16() by put_le16()

---
attrib/att.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/attrib/att.c b/attrib/att.c
index e28be25..c408568 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -34,6 +34,7 @@

#include <glib.h>

+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "att.h"

@@ -267,7 +268,7 @@ uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
pdu[0] = ATT_OP_FIND_BY_TYPE_REQ;
att_put_u16(start, &pdu[1]);
att_put_u16(end, &pdu[3]);
- att_put_uuid16(*uuid, &pdu[5]);
+ put_le16(uuid->value.u16, &pdu[5]);

if (vlen > 0) {
memcpy(&pdu[7], value, vlen);
--
1.8.3.1


2014-03-20 14:43:04

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 39/62] Replace att_put_u32() by put_le32()

---
profiles/cyclingspeed/cyclingspeed.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index 918f237..1222532 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -1167,7 +1167,7 @@ static DBusMessage *set_cumulative_wheel_rev(DBusConnection *conn,
csc->pending_req = req;

att_val[0] = SET_CUMULATIVE_VALUE;
- att_put_u32(value, att_val + 1);
+ put_le32(value, att_val + 1);

gatt_write_char(csc->attrib, csc->controlpoint_val_handle, att_val,
sizeof(att_val), controlpoint_write_cb, req);
--
1.8.3.1


2014-03-20 14:42:59

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 34/62] lib: Fix UUID 16/32-bits to 128-bit conversion

16 and 32-bit UUIDs are always created using host order. However,
no matter the system type, 128-bit UUID must use big-endian byte
order format (similar to human-readble format).
---
lib/uuid.c | 29 +++++++++++++----------------
1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/lib/uuid.c b/lib/uuid.c
index dbca330..0d3b204 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -30,9 +30,9 @@
#include <stdlib.h>
#include <errno.h>

+#include "src/shared/util.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 }
@@ -41,24 +41,17 @@ static uint128_t bluetooth_base_uuid = {
#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 *src, bt_uuid_t *dst)
{
dst->value.u128 = bluetooth_base_uuid;
dst->type = BT_UUID128;

- memcpy(&dst->value.u128.data[BASE_UUID16_OFFSET],
- &src->value.u16, sizeof(src->value.u16));
+ /*
+ * No matter the system: 128-bit UUIDs should be stored
+ * as big-endian. 16-bit UUIDs are stored on host order.
+ */
+
+ put_be16(src->value.u16, &dst->value.u128.data[BASE_UUID16_OFFSET]);
}

static void bt_uuid32_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
@@ -66,8 +59,12 @@ static void bt_uuid32_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
dst->value.u128 = bluetooth_base_uuid;
dst->type = BT_UUID128;

- memcpy(&dst->value.u128.data[BASE_UUID32_OFFSET],
- &src->value.u32, sizeof(src->value.u32));
+ /*
+ * No matter the system: 128-bit UUIDs should be stored
+ * as big-endian. 32-bit UUIDs are stored on host order.
+ */
+
+ put_be32(src->value.u32, &dst->value.u128.data[BASE_UUID32_OFFSET]);
}

void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst)
--
1.8.3.1


2014-03-20 14:43:09

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 44/62] Replace att_put_uuid() by util.h helpers

---
attrib/att.c | 13 +++++++++++--
attrib/gatt-service.c | 22 +++++++++++++---------
src/attrib-server.c | 11 ++++++++++-
3 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index bd23142..bdf7c00 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -38,6 +38,15 @@
#include "lib/uuid.h"
#include "att.h"

+static inline void put_uuid_le(const bt_uuid_t *src, void *dst)
+{
+ if (src->type == BT_UUID16)
+ put_le16(src->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&src->value.u128, dst);
+}
+
const char *att_ecode2str(uint8_t status)
{
switch (status) {
@@ -156,7 +165,7 @@ uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Ending Handle (2 octets) */
att_put_u16(end, &pdu[3]);
/* Attribute Group Type (2 or 16 octet UUID) */
- att_put_uuid(*uuid, &pdu[5]);
+ put_uuid_le(uuid, &pdu[5]);

return 5 + uuid_len;
}
@@ -401,7 +410,7 @@ uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Ending Handle (2 octets) */
att_put_u16(end, &pdu[3]);
/* Attribute Type (2 or 16 octet UUID) */
- att_put_uuid(*uuid, &pdu[5]);
+ put_uuid_le(uuid, &pdu[5]);

return 5 + uuid_len;
}
diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index 227d4d4..699ac1e 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -30,6 +30,7 @@
#include <bluetooth/sdp.h>

#include "src/adapter.h"
+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
@@ -56,6 +57,15 @@ struct attrib_cb {
void *user_data;
};

+static inline void put_uuid_le(const bt_uuid_t *src, void *dst)
+{
+ if (src->type == BT_UUID16)
+ put_le16(src->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&src->value.u128, dst);
+}
+
static GSList *parse_opts(gatt_option opt1, va_list args)
{
gatt_option opt = opt1;
@@ -130,14 +140,8 @@ static struct attribute *add_service_declaration(struct btd_adapter *adapter,
uint8_t atval[16];
int len;

- if (uuid->type == BT_UUID16) {
- att_put_u16(uuid->value.u16, &atval[0]);
- len = 2;
- } else if (uuid->type == BT_UUID128) {
- att_put_u128(uuid->value.u128, &atval[0]);
- len = 16;
- } else
- return NULL;
+ put_uuid_le(uuid, &atval[0]);
+ len = bt_uuid_len(uuid);

bt_uuid16_create(&bt_uuid, svc);

@@ -229,7 +233,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
bt_uuid16_create(&bt_uuid, GATT_CHARAC_UUID);
atval[0] = info->props;
att_put_u16(h + 1, &atval[1]);
- att_put_uuid(info->uuid, &atval[3]);
+ put_uuid_le(&info->uuid, &atval[3]);
if (attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 3 + info->uuid.type / 8) == NULL)
return FALSE;
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 5c6b1f8..e089c0d 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -102,6 +102,15 @@ static bt_uuid_t ccc_uuid = {
.value.u16 = GATT_CLIENT_CHARAC_CFG_UUID
};

+static inline void put_uuid_le(const bt_uuid_t *src, void *dst)
+{
+ if (src->type == BT_UUID16)
+ put_le16(src->value.u16, dst);
+ else
+ /* Convert from 128-bit BE to LE */
+ bswap_128(&src->value.u128, dst);
+}
+
static void attrib_free(void *data)
{
struct attribute *a = data;
@@ -676,7 +685,7 @@ static uint16_t find_info(struct gatt_channel *channel, uint16_t start,
att_put_u16(a->handle, value);

/* Attribute Value */
- att_put_uuid(a->uuid, &value[2]);
+ put_uuid_le(&a->uuid, &value[2]);
}

length = enc_find_info_resp(format, adl, pdu, len);
--
1.8.3.1


2014-03-20 14:43:07

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 42/62] Replace att_get_u16() by get_le16()

---
attrib/att.c | 44 ++++++++++++++++++------------------
attrib/gatt.c | 14 ++++++------
attrib/gattrib.c | 3 ++-
attrib/gatttool.c | 6 ++---
attrib/interactive.c | 6 ++---
profiles/cyclingspeed/cyclingspeed.c | 12 +++++-----
profiles/deviceinfo/deviceinfo.c | 5 ++--
profiles/gatt/gas.c | 11 +++++----
profiles/heartrate/heartrate.c | 11 +++++----
profiles/input/hog.c | 9 ++++----
profiles/scanparam/scan.c | 5 ++--
profiles/thermometer/thermometer.c | 14 ++++++------
src/attrib-server.c | 5 ++--
13 files changed, 76 insertions(+), 69 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index b353499..1df6190 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -165,8 +165,8 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (len != (min_len + 2) && len != (min_len + 16))
return 0;

- *start = att_get_u16(&pdu[1]);
- *end = att_get_u16(&pdu[3]);
+ *start = get_le16(&pdu[1]);
+ *end = get_le16(&pdu[3]);
if (len == min_len + 2)
bt_uuid16_create(uuid, get_le16(&pdu[5]));
else
@@ -293,9 +293,9 @@ uint16_t dec_find_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
return 0;

/* First requested handle number (2 octets) */
- *start = att_get_u16(&pdu[1]);
+ *start = get_le16(&pdu[1]);
/* Last requested handle number (2 octets) */
- *end = att_get_u16(&pdu[3]);
+ *end = get_le16(&pdu[3]);
/* 16-bit UUID to find (2 octets) */
bt_uuid16_create(uuid, get_le16(&pdu[5]));

@@ -354,8 +354,8 @@ GSList *dec_find_by_type_resp(const uint8_t *pdu, size_t len)
len >= (offset + sizeof(uint16_t) * 2);
offset += sizeof(uint16_t) * 2) {
range = g_new0(struct att_range, 1);
- range->start = att_get_u16(&pdu[offset]);
- range->end = att_get_u16(&pdu[offset + 2]);
+ range->start = get_le16(&pdu[offset]);
+ range->end = get_le16(&pdu[offset + 2]);

matches = g_slist_append(matches, range);
}
@@ -407,8 +407,8 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ)
return 0;

- *start = att_get_u16(&pdu[1]);
- *end = att_get_u16(&pdu[3]);
+ *start = get_le16(&pdu[1]);
+ *end = get_le16(&pdu[3]);

if (len == min_len + 2)
bt_uuid16_create(uuid, get_le16(&pdu[5]));
@@ -527,7 +527,7 @@ uint16_t dec_write_cmd(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_WRITE_CMD)
return 0;

- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);
memcpy(value, pdu + min_len, len - min_len);
*vlen = len - min_len;

@@ -573,7 +573,7 @@ uint16_t dec_write_req(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_WRITE_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);
*vlen = len - min_len;
if (*vlen > 0)
memcpy(value, pdu + min_len, *vlen);
@@ -647,7 +647,7 @@ uint16_t dec_read_req(const uint8_t *pdu, size_t len, uint16_t *handle)
if (pdu[0] != ATT_OP_READ_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);

return min_len;
}
@@ -673,8 +673,8 @@ uint16_t dec_read_blob_req(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_READ_BLOB_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
- *offset = att_get_u16(&pdu[3]);
+ *handle = get_le16(&pdu[1]);
+ *offset = get_le16(&pdu[3]);

return min_len;
}
@@ -782,8 +782,8 @@ uint16_t dec_find_info_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (pdu[0] != ATT_OP_FIND_INFO_REQ)
return 0;

- *start = att_get_u16(&pdu[1]);
- *end = att_get_u16(&pdu[3]);
+ *start = get_le16(&pdu[1]);
+ *end = get_le16(&pdu[3]);

return min_len;
}
@@ -910,7 +910,7 @@ uint16_t dec_indication(const uint8_t *pdu, size_t len, uint16_t *handle,
dlen = MIN(len - min_len, vlen);

if (handle)
- *handle = att_get_u16(&pdu[1]);
+ *handle = get_le16(&pdu[1]);

memcpy(value, &pdu[3], dlen);

@@ -957,7 +957,7 @@ uint16_t dec_mtu_req(const uint8_t *pdu, size_t len, uint16_t *mtu)
if (pdu[0] != ATT_OP_MTU_REQ)
return 0;

- *mtu = att_get_u16(&pdu[1]);
+ *mtu = get_le16(&pdu[1]);

return min_len;
}
@@ -991,7 +991,7 @@ uint16_t dec_mtu_resp(const uint8_t *pdu, size_t len, uint16_t *mtu)
if (pdu[0] != ATT_OP_MTU_RESP)
return 0;

- *mtu = att_get_u16(&pdu[1]);
+ *mtu = get_le16(&pdu[1]);

return min_len;
}
@@ -1039,8 +1039,8 @@ uint16_t dec_prep_write_req(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_PREP_WRITE_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
- *offset = att_get_u16(&pdu[3]);
+ *handle = get_le16(&pdu[1]);
+ *offset = get_le16(&pdu[3]);

*vlen = len - min_len;
if (*vlen > 0)
@@ -1092,8 +1092,8 @@ uint16_t dec_prep_write_resp(const uint8_t *pdu, size_t len, uint16_t *handle,
if (pdu[0] != ATT_OP_PREP_WRITE_REQ)
return 0;

- *handle = att_get_u16(&pdu[1]);
- *offset = att_get_u16(&pdu[3]);
+ *handle = get_le16(&pdu[1]);
+ *offset = get_le16(&pdu[3]);
*vlen = len - min_len;
if (*vlen > 0)
memcpy(value, pdu + min_len, *vlen);
diff --git a/attrib/gatt.c b/attrib/gatt.c
index 0d43913..83692f4 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -242,8 +242,8 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
struct gatt_primary *primary;
bt_uuid_t uuid;

- start = att_get_u16(&data[0]);
- end = att_get_u16(&data[2]);
+ start = get_le16(&data[0]);
+ end = get_le16(&data[2]);

if (list->len == 6) {
bt_uuid_t uuid16;
@@ -381,9 +381,9 @@ static struct gatt_included *included_from_buf(const uint8_t *buf, gsize len)
{
struct gatt_included *incl = g_new0(struct gatt_included, 1);

- incl->handle = att_get_u16(&buf[0]);
- incl->range.start = att_get_u16(&buf[2]);
- incl->range.end = att_get_u16(&buf[4]);
+ incl->handle = get_le16(&buf[0]);
+ incl->range.start = get_le16(&buf[2]);
+ incl->range.end = get_le16(&buf[4]);

if (len == 8) {
bt_uuid_t uuid128;
@@ -505,7 +505,7 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
struct gatt_char *chars;
bt_uuid_t uuid;

- last = att_get_u16(value);
+ last = get_le16(value);

if (list->len == 7) {
bt_uuid_t uuid16;
@@ -526,7 +526,7 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,

chars->handle = last;
chars->properties = value[2];
- chars->value_handle = att_get_u16(&value[3]);
+ chars->value_handle = get_le16(&value[3]);
bt_uuid_to_string(&uuid, chars->uuid, sizeof(chars->uuid));
dc->characteristics = g_slist_append(dc->characteristics,
chars);
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 31450a3..912dffb 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -37,6 +37,7 @@

#include "btio/btio.h"
#include "lib/uuid.h"
+#include "src/shared/util.h"
#include "src/log.h"
#include "attrib/att.h"
#include "attrib/gattrib.h"
@@ -381,7 +382,7 @@ static bool match_event(struct event *evt, const uint8_t *pdu, gsize len)
if (len < 3)
return false;

- handle = att_get_u16(&pdu[1]);
+ handle = get_le16(&pdu[1]);

if (evt->expected == pdu[0] && evt->handle == handle)
return true;
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 10415a8..4eb2528 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -79,7 +79,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
uint16_t handle, i, olen = 0;
size_t plen;

- handle = att_get_u16(&pdu[1]);
+ handle = get_le16(&pdu[1]);

switch (pdu[0]) {
case ATT_OP_HANDLE_NOTIFY:
@@ -272,7 +272,7 @@ static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
uint8_t *value = list->data[i];
int j;

- g_print("handle: 0x%04x \t value: ", att_get_u16(value));
+ g_print("handle: 0x%04x \t value: ", get_le16(value));
value += 2;
for (j = 0; j < list->len - 2; j++, value++)
g_print("%02x ", *value);
@@ -424,7 +424,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
bt_uuid_t uuid;

value = list->data[i];
- handle = att_get_u16(value);
+ handle = get_le16(value);

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 38403dd..5dd47ec 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -114,7 +114,7 @@ static void events_handler(const uint8_t *pdu, uint16_t len, gpointer user_data)
size_t plen;
GString *s;

- handle = att_get_u16(&pdu[1]);
+ handle = get_le16(&pdu[1]);

switch (pdu[0]) {
case ATT_OP_HANDLE_NOTIFY:
@@ -293,7 +293,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
bt_uuid_t uuid;

value = list->data[i];
- handle = att_get_u16(value);
+ handle = get_le16(value);

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
@@ -362,7 +362,7 @@ static void char_read_by_uuid_cb(guint8 status, const guint8 *pdu,
int j;

g_string_printf(s, "handle: 0x%04x \t value: ",
- att_get_u16(value));
+ get_le16(value));
value += 2;
for (j = 0; j < list->len - 2; j++, value++)
g_string_append_printf(s, "%02x ", *value);
diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index 1222532..63e969a 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -381,7 +381,7 @@ static void read_feature_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- csc->feature = att_get_u16(value);
+ csc->feature = get_le16(value);

if ((csc->feature & MULTI_SENSOR_LOC_SUPPORT)
&& (csc->locations == NULL))
@@ -447,8 +447,8 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu,
char *msg;

value = list->data[i];
- handle = att_get_u16(value);
- uuid = att_get_u16(value + 2);
+ handle = get_le16(value);
+ uuid = get_le16(value + 2);

if (uuid != GATT_CLIENT_CHARAC_CFG_UUID)
continue;
@@ -575,7 +575,7 @@ static void process_measurement(struct csc *csc, const uint8_t *pdu,

m.has_wheel_rev = true;
m.wheel_rev = get_le32(pdu);
- m.last_wheel_time = att_get_u16(pdu + 4);
+ m.last_wheel_time = get_le16(pdu + 4);
pdu += 6;
len -= 6;
}
@@ -587,8 +587,8 @@ static void process_measurement(struct csc *csc, const uint8_t *pdu,
}

m.has_crank_rev = true;
- m.crank_rev = att_get_u16(pdu);
- m.last_crank_time = att_get_u16(pdu + 2);
+ m.crank_rev = get_le16(pdu);
+ m.last_crank_time = get_le16(pdu + 2);
pdu += 4;
len -= 4;
}
diff --git a/profiles/deviceinfo/deviceinfo.c b/profiles/deviceinfo/deviceinfo.c
index 661a5dc..208598a 100644
--- a/profiles/deviceinfo/deviceinfo.c
+++ b/profiles/deviceinfo/deviceinfo.c
@@ -35,6 +35,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "attrib/gattrib.h"
#include "src/attio.h"
#include "attrib/att.h"
@@ -96,8 +97,8 @@ static void read_pnpid_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- btd_device_set_pnpid(ch->d->dev, value[0], att_get_u16(&value[1]),
- att_get_u16(&value[3]), att_get_u16(&value[5]));
+ btd_device_set_pnpid(ch->d->dev, value[0], get_le16(&value[1]),
+ get_le16(&value[3]), get_le16(&value[5]));
}

static void process_deviceinfo_char(struct characteristic *ch)
diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index c0526e5..38f5e72 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
@@ -40,6 +40,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "attrib/att.h"
#include "attrib/gattrib.h"
#include "src/attio.h"
@@ -165,7 +166,7 @@ static void gap_appearance_cb(guint8 status, const guint8 *pdu, guint16 plen,
}

atval = list->data[0] + 2; /* skip handle value */
- app = att_get_u16(atval);
+ app = get_le16(atval);

DBG("GAP Appearance: 0x%04x", app);

@@ -188,8 +189,8 @@ static void indication_cb(const uint8_t *pdu, uint16_t len, gpointer user_data)
return;
}

- start = att_get_u16(&pdu[3]);
- end = att_get_u16(&pdu[5]);
+ start = get_le16(&pdu[3]);
+ end = get_le16(&pdu[5]);

DBG("Service Changed start: 0x%04X end: 0x%04X", start, end);

@@ -263,8 +264,8 @@ static void gatt_descriptors_cb(guint8 status, const guint8 *pdu, guint16 len,
uint8_t *value;

value = list->data[i];
- ccc = att_get_u16(value);
- uuid16 = att_get_u16(&value[2]);
+ ccc = get_le16(value);
+ uuid16 = get_le16(&value[2]);
DBG("CCC: 0x%04x UUID: 0x%04x", ccc, uuid16);
write_ccc(gas->attrib, ccc, user_data);
}
diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index 97af02e..15ccdfd 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -35,6 +35,7 @@
#include "src/dbus-common.h"
#include "src/device.h"
#include "src/profile.h"
+#include "src/shared/util.h"
#include "src/service.h"
#include "src/error.h"
#include "attrib/gattrib.h"
@@ -324,7 +325,7 @@ static void process_measurement(struct heartrate *hr, const uint8_t *pdu,
return;
}

- m.value = att_get_u16(pdu);
+ m.value = get_le16(pdu);
pdu += 2;
len -= 2;
} else {
@@ -345,7 +346,7 @@ static void process_measurement(struct heartrate *hr, const uint8_t *pdu,
}

m.has_energy = TRUE;
- m.energy = att_get_u16(pdu);
+ m.energy = get_le16(pdu);
pdu += 2;
len -= 2;
}
@@ -362,7 +363,7 @@ static void process_measurement(struct heartrate *hr, const uint8_t *pdu,
m.interval = g_new(uint16_t, m.num_interval);

for (i = 0; i < m.num_interval; pdu += 2, i++)
- m.interval[i] = att_get_u16(pdu);
+ m.interval[i] = get_le16(pdu);
}

if (flags & SENSOR_CONTACT_SUPPORT) {
@@ -418,8 +419,8 @@ static void discover_ccc_cb(guint8 status, const guint8 *pdu,
uint8_t attr_val[2];

value = list->data[i];
- handle = att_get_u16(value);
- uuid = att_get_u16(value + 2);
+ handle = get_le16(value);
+ uuid = get_le16(value + 2);

if (uuid != GATT_CLIENT_CHARAC_CFG_UUID)
continue;
diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index fd72e36..25985ec 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -47,6 +47,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"

#include "src/plugin.h"

@@ -234,8 +235,8 @@ static void discover_descriptor_cb(guint8 status, const guint8 *pdu,
uint8_t *value;

value = list->data[i];
- handle = att_get_u16(value);
- uuid16 = att_get_u16(&value[2]);
+ handle = get_le16(value);
+ uuid16 = get_le16(&value[2]);

switch (uuid16) {
case GATT_CLIENT_CHARAC_CFG_UUID:
@@ -336,7 +337,7 @@ static void external_report_reference_cb(guint8 status, const guint8 *pdu,
return;
}

- uuid16 = att_get_u16(&pdu[1]);
+ uuid16 = get_le16(&pdu[1]);
DBG("External report reference read, external report characteristic "
"UUID: 0x%04x", uuid16);
bt_uuid16_create(&uuid, uuid16);
@@ -431,7 +432,7 @@ static void info_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
return;
}

- hogdev->bcdhid = att_get_u16(&value[0]);
+ hogdev->bcdhid = get_le16(&value[0]);
hogdev->bcountrycode = value[2];
hogdev->flags = value[3];

diff --git a/profiles/scanparam/scan.c b/profiles/scanparam/scan.c
index 4fd8f53..d6e477e 100644
--- a/profiles/scanparam/scan.c
+++ b/profiles/scanparam/scan.c
@@ -36,6 +36,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "attrib/att.h"
#include "attrib/gattrib.h"
#include "attrib/gatt.h"
@@ -119,8 +120,8 @@ static void discover_descriptor_cb(guint8 status, const guint8 *pdu,
goto done;

ptr = list->data[0];
- handle = att_get_u16(ptr);
- uuid16 = att_get_u16(&ptr[2]);
+ handle = get_le16(ptr);
+ uuid16 = get_le16(&ptr[2]);

if (uuid16 != GATT_CLIENT_CHARAC_CFG_UUID)
goto done;
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index d2ea56b..5b90792 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -383,7 +383,7 @@ static void proc_measurement(struct thermometer *t, const uint8_t *pdu,
return;
}

- ts.tm_year = att_get_u16(pdu) - 1900;
+ ts.tm_year = get_le16(pdu) - 1900;
ts.tm_mon = *(pdu + 2) - 1;
ts.tm_mday = *(pdu + 3);
ts.tm_hour = *(pdu + 4);
@@ -467,7 +467,7 @@ static void interval_ind_handler(const uint8_t *pdu, uint16_t len,
return;
}

- interval = att_get_u16(pdu + 3);
+ interval = get_le16(pdu + 3);
change_property(t, "Interval", &interval);

opdu = g_attrib_get_buffer(t->attrib, &plen);
@@ -502,8 +502,8 @@ static void valid_range_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- min = att_get_u16(&value[0]);
- max = att_get_u16(&value[2]);
+ min = get_le16(&value[0]);
+ max = get_le16(&value[2]);

if (min == 0 || min > max) {
DBG("Invalid range");
@@ -600,8 +600,8 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu, guint16 len,
uint16_t handle, uuid;

value = list->data[i];
- handle = att_get_u16(value);
- uuid = att_get_u16(value + 2);
+ handle = get_le16(value);
+ uuid = get_le16(value + 2);

process_thermometer_desc(ch, uuid, handle);
}
@@ -690,7 +690,7 @@ static void read_interval_cb(guint8 status, const guint8 *pdu, guint16 len,
return;
}

- interval = att_get_u16(&value[0]);
+ interval = get_le16(&value[0]);
change_property(t, "Interval", &interval);
}

diff --git a/src/attrib-server.c b/src/attrib-server.c
index 3f579bb..5c6b1f8 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -47,6 +47,7 @@
#include "hcid.h"
#include "adapter.h"
#include "device.h"
+#include "src/shared/util.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
#include "attrib/gatt.h"
@@ -307,7 +308,7 @@ static uint32_t attrib_create_sdp_new(struct gatt_server *server,
return 0;

if (a->len == 2)
- sdp_uuid16_create(&svc, att_get_u16(a->data));
+ sdp_uuid16_create(&svc, get_le16(a->data));
else if (a->len == 16)
sdp_uuid128_create(&svc, a->data);
else
@@ -894,7 +895,7 @@ static uint16_t write_value(struct gatt_channel *channel, uint16_t handle,
status, pdu, len);
}
} else {
- uint16_t cccval = att_get_u16(value);
+ uint16_t cccval = get_le16(value);
char *filename;
GKeyFile *key_file;
char group[6], value[5];
--
1.8.3.1


2014-03-20 14:43:18

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 53/62] attrib: Remove att_get_u128()

---
attrib/att.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 0b98df3..670f51a 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -112,16 +112,6 @@ struct att_range {
};

/* These functions do byte conversion */
-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_u16(uint16_t src, void *dst)
{
bt_put_unaligned(htobs(src), (uint16_t *) dst);
--
1.8.3.1


2014-03-20 14:43:15

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 50/62] attrib: Remove att_get_uuid16()

---
attrib/att.h | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 89698dc..35281e5 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -158,15 +158,6 @@ static inline void att_put_uuid(bt_uuid_t src, void *dst)
att_put_uuid128(src, dst);
}

-static inline bt_uuid_t att_get_uuid16(const void *ptr)
-{
- bt_uuid_t uuid;
-
- bt_uuid16_create(&uuid, att_get_u16(ptr));
-
- return uuid;
-}
-
static inline bt_uuid_t att_get_uuid128(const void *ptr)
{
bt_uuid_t uuid;
--
1.8.3.1


2014-03-20 14:43:22

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 57/62] attrib: Remove att_put_uuid16()

---
attrib/att.h | 5 -----
1 file changed, 5 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 0875a3b..4da25dc 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -117,11 +117,6 @@ static inline void att_put_u16(uint16_t src, void *dst)
bt_put_unaligned(htobs(src), (uint16_t *) dst);
}

-static inline void att_put_uuid16(bt_uuid_t src, void *dst)
-{
- att_put_u16(src.value.u16, dst);
-}
-
struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len);
void att_data_list_free(struct att_data_list *list);

--
1.8.3.1


2014-03-20 14:43:21

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 56/62] attrib: Remove att_put_u128()

---
attrib/att.h | 7 -------
1 file changed, 7 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 00dd8d0..0875a3b 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -117,13 +117,6 @@ static inline void att_put_u16(uint16_t src, void *dst)
bt_put_unaligned(htobs(src), (uint16_t *) dst);
}

-static inline void att_put_u128(uint128_t src, void *dst)
-{
- uint128_t *d128 = dst;
-
- htob128(&src, d128);
-}
-
static inline void att_put_uuid16(bt_uuid_t src, void *dst)
{
att_put_u16(src.value.u16, dst);
--
1.8.3.1


2014-03-20 14:43:20

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 55/62] attrib: Remove att_put_uuid128()

---
attrib/att.h | 5 -----
1 file changed, 5 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 6155848..00dd8d0 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -129,11 +129,6 @@ static inline void att_put_uuid16(bt_uuid_t src, void *dst)
att_put_u16(src.value.u16, dst);
}

-static inline void att_put_uuid128(bt_uuid_t src, void *dst)
-{
- att_put_u128(src.value.u128, dst);
-}
-
struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len);
void att_data_list_free(struct att_data_list *list);

--
1.8.3.1


2014-03-20 14:43:17

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 52/62] attrib: Remove att_get_uuid128()

---
attrib/att.h | 11 -----------
1 file changed, 11 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 46bd253..0b98df3 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -152,17 +152,6 @@ static inline void att_put_uuid(bt_uuid_t src, void *dst)
att_put_uuid128(src, dst);
}

-static inline bt_uuid_t att_get_uuid128(const void *ptr)
-{
- bt_uuid_t uuid;
- uint128_t value;
-
- value = att_get_u128(ptr);
- bt_uuid128_create(&uuid, value);
-
- return uuid;
-}
-
struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len);
void att_data_list_free(struct att_data_list *list);

--
1.8.3.1


2014-03-20 14:43:19

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 54/62] attrib: Remove att_put_uuid()

---
attrib/att.h | 8 --------
1 file changed, 8 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 670f51a..6155848 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -134,14 +134,6 @@ static inline void att_put_uuid128(bt_uuid_t src, void *dst)
att_put_u128(src.value.u128, dst);
}

-static inline void att_put_uuid(bt_uuid_t src, void *dst)
-{
- if (src.type == BT_UUID16)
- att_put_uuid16(src, dst);
- else
- att_put_uuid128(src, dst);
-}
-
struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len);
void att_data_list_free(struct att_data_list *list);

--
1.8.3.1


2014-03-20 14:43:27

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 62/62] lib: Remove bt_put_unaligned()

---
lib/bluetooth.h | 8 --------
1 file changed, 8 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 303ad67..9d00717 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -154,14 +154,6 @@ enum {
#error "Unknown byte order"
#endif

-#define bt_put_unaligned(val, ptr) \
-do { \
- struct __attribute__((packed)) { \
- typeof(*(ptr)) __v; \
- } *__p = (typeof(__p)) (ptr); \
- __p->__v = (val); \
-} while(0)
-
/* BD Address */
typedef struct {
uint8_t b[6];
--
1.8.3.1


2014-03-20 14:43:25

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 60/62] tools: Use unaligned access macros from util.h

---
tools/parser/hci.c | 1 -
tools/parser/l2cap.c | 1 -
tools/parser/parser.h | 9 ++++-----
tools/parser/ppp.c | 2 +-
4 files changed, 5 insertions(+), 8 deletions(-)

diff --git a/tools/parser/hci.c b/tools/parser/hci.c
index b018e93..351f843 100644
--- a/tools/parser/hci.c
+++ b/tools/parser/hci.c
@@ -37,7 +37,6 @@
#include "lib/hci.h"
#include "lib/hci_lib.h"
#include "lib/amp.h"
-#include "src/shared/util.h"

static uint16_t manufacturer = DEFAULT_COMPID;

diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index 53dd726..a057964 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -39,7 +39,6 @@
#include "lib/hci.h"
#include "lib/a2mp.h"
#include "lib/amp.h"
-#include "src/shared/util.h"

typedef struct {
uint16_t handle;
diff --git a/tools/parser/parser.h b/tools/parser/parser.h
index c65b4b5..dc49104 100644
--- a/tools/parser/parser.h
+++ b/tools/parser/parser.h
@@ -30,6 +30,7 @@
#include <netinet/in.h>

#include "lib/bluetooth.h"
+#include "src/shared/util.h"

struct frame {
void *data;
@@ -170,24 +171,22 @@ static inline uint8_t get_u8(struct frame *frm)

static inline uint16_t get_u16(struct frame *frm)
{
- uint16_t *u16_ptr = frm->ptr;
frm->ptr += 2;
frm->len -= 2;
- return ntohs(bt_get_unaligned(u16_ptr));
+ return get_be16(frm->ptr);
}

static inline uint32_t get_u32(struct frame *frm)
{
- uint32_t *u32_ptr = frm->ptr;
frm->ptr += 4;
frm->len -= 4;
- return ntohl(bt_get_unaligned(u32_ptr));
+ return get_be32(frm->ptr);
}

static inline uint64_t get_u64(struct frame *frm)
{
uint64_t *u64_ptr = frm->ptr;
- uint64_t u64 = bt_get_unaligned(u64_ptr), tmp;
+ uint64_t u64 = get_unaligned(u64_ptr), tmp;
frm->ptr += 8;
frm->len -= 8;
tmp = ntohl(u64 & 0xffffffff);
diff --git a/tools/parser/ppp.c b/tools/parser/ppp.c
index 947ca56..256e172 100644
--- a/tools/parser/ppp.c
+++ b/tools/parser/ppp.c
@@ -103,7 +103,7 @@ static void hdlc_dump(int level, struct frame *frm)
uint8_t ctrl = get_u8(frm);
uint16_t fcs, proto;

- fcs = bt_get_unaligned((uint16_t *) (frm->ptr + frm->len - 2));
+ fcs = get_unaligned((uint16_t *) (frm->ptr + frm->len - 2));
frm->len -= 2;

p_indent(level, frm);
--
1.8.3.1


2014-03-20 14:43:26

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 61/62] lib: Remove bt_get_unaligned()

---
lib/bluetooth.h | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 57ac7b5..303ad67 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -154,15 +154,6 @@ enum {
#error "Unknown byte order"
#endif

-/* Bluetooth unaligned access */
-#define bt_get_unaligned(ptr) \
-({ \
- struct __attribute__((packed)) { \
- typeof(*(ptr)) __v; \
- } *__p = (typeof(__p)) (ptr); \
- __p->__v; \
-})
-
#define bt_put_unaligned(val, ptr) \
do { \
struct __attribute__((packed)) { \
--
1.8.3.1


2014-03-20 14:43:23

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 58/62] attrib: Remove att_put_u16()

---
attrib/att.h | 6 ------
1 file changed, 6 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 4da25dc..297c302 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -111,12 +111,6 @@ struct att_range {
uint16_t end;
};

-/* These functions do byte conversion */
-static inline void att_put_u16(uint16_t src, void *dst)
-{
- bt_put_unaligned(htobs(src), (uint16_t *) dst);
-}
-
struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len);
void att_data_list_free(struct att_data_list *list);

--
1.8.3.1


2014-03-20 14:43:24

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 59/62] lib: Use get_unaligned() instead of bt_get_unaligned()

---
lib/sdp.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/sdp.c b/lib/sdp.c
index 4a67a89..d55b88f 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -381,27 +381,27 @@ sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value,
d->unitSize += sizeof(int8_t);
break;
case SDP_UINT16:
- d->val.uint16 = bt_get_unaligned((uint16_t *) value);
+ d->val.uint16 = get_unaligned((uint16_t *) value);
d->unitSize += sizeof(uint16_t);
break;
case SDP_INT16:
- d->val.int16 = bt_get_unaligned((int16_t *) value);
+ d->val.int16 = get_unaligned((int16_t *) value);
d->unitSize += sizeof(int16_t);
break;
case SDP_UINT32:
- d->val.uint32 = bt_get_unaligned((uint32_t *) value);
+ d->val.uint32 = get_unaligned((uint32_t *) value);
d->unitSize += sizeof(uint32_t);
break;
case SDP_INT32:
- d->val.int32 = bt_get_unaligned((int32_t *) value);
+ d->val.int32 = get_unaligned((int32_t *) value);
d->unitSize += sizeof(int32_t);
break;
case SDP_INT64:
- d->val.int64 = bt_get_unaligned((int64_t *) value);
+ d->val.int64 = get_unaligned((int64_t *) value);
d->unitSize += sizeof(int64_t);
break;
case SDP_UINT64:
- d->val.uint64 = bt_get_unaligned((uint64_t *) value);
+ d->val.uint64 = get_unaligned((uint64_t *) value);
d->unitSize += sizeof(uint64_t);
break;
case SDP_UINT128:
@@ -413,11 +413,11 @@ sdp_data_t *sdp_data_alloc_with_length(uint8_t dtd, const void *value,
d->unitSize += sizeof(uint128_t);
break;
case SDP_UUID16:
- sdp_uuid16_create(&d->val.uuid, bt_get_unaligned((uint16_t *) value));
+ sdp_uuid16_create(&d->val.uuid, get_unaligned((uint16_t *) value));
d->unitSize += sizeof(uint16_t);
break;
case SDP_UUID32:
- sdp_uuid32_create(&d->val.uuid, bt_get_unaligned((uint32_t *) value));
+ sdp_uuid32_create(&d->val.uuid, get_unaligned((uint32_t *) value));
d->unitSize += sizeof(uint32_t);
break;
case SDP_UUID128:
--
1.8.3.1


2014-03-20 14:43:16

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 51/62] attrib: Remove att_get_u16()

---
attrib/att.h | 6 ------
1 file changed, 6 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 35281e5..46bd253 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -112,12 +112,6 @@ struct att_range {
};

/* These functions do byte conversion */
-static inline uint16_t att_get_u16(const void *ptr)
-{
- const uint16_t *u16_ptr = ptr;
- return btohs(bt_get_unaligned(u16_ptr));
-}
-
static inline uint128_t att_get_u128(const void *ptr)
{
const uint128_t *u128_ptr = ptr;
--
1.8.3.1


2014-03-20 14:43:13

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 48/62] attrib: Remove att_get_u32()

---
attrib/att.h | 6 ------
1 file changed, 6 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 4db015d..ad6bdf6 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -118,12 +118,6 @@ static inline uint16_t att_get_u16(const void *ptr)
return btohs(bt_get_unaligned(u16_ptr));
}

-static inline uint32_t att_get_u32(const void *ptr)
-{
- const uint32_t *u32_ptr = ptr;
- return btohl(bt_get_unaligned(u32_ptr));
-}
-
static inline uint128_t att_get_u128(const void *ptr)
{
const uint128_t *u128_ptr = ptr;
--
1.8.3.1


2014-03-20 14:43:14

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 49/62] attrib: Remove att_put_u32()

---
attrib/att.h | 5 -----
1 file changed, 5 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index ad6bdf6..89698dc 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -133,11 +133,6 @@ static inline void att_put_u16(uint16_t src, void *dst)
bt_put_unaligned(htobs(src), (uint16_t *) dst);
}

-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;
--
1.8.3.1


2014-03-20 14:43:12

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 47/62] attrib: Remove att_put_u8()

---
attrib/att.h | 5 -----
profiles/proximity/reporter.c | 2 +-
2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 645b6cf..4db015d 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -134,11 +134,6 @@ static inline uint128_t att_get_u128(const void *ptr)
return dst;
}

-static inline void att_put_u8(uint8_t src, void *dst)
-{
- bt_put_unaligned(src, (uint8_t *) dst);
-}
-
static inline void att_put_u16(uint16_t src, void *dst)
{
bt_put_unaligned(htobs(src), (uint16_t *) dst);
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index 5861923..9be4a95 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -130,7 +130,7 @@ static void register_tx_power(struct btd_adapter *adapter)

/* Power level value */
bt_uuid16_create(&uuid, POWER_LEVEL_CHR_UUID);
- att_put_u8(0x00, &atval[0]);
+ atval[0] = 0x00;
attrib_db_add(adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 1);

/* Client characteristic configuration */
--
1.8.3.1


2014-03-20 14:43:11

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 46/62] attrib: Remove att_get_u8()

---
attrib/att.h | 6 ------
1 file changed, 6 deletions(-)

diff --git a/attrib/att.h b/attrib/att.h
index 28bc944..645b6cf 100644
--- a/attrib/att.h
+++ b/attrib/att.h
@@ -112,12 +112,6 @@ struct att_range {
};

/* These functions do byte conversion */
-static inline uint8_t att_get_u8(const void *ptr)
-{
- const uint8_t *u8_ptr = ptr;
- return bt_get_unaligned(u8_ptr);
-}
-
static inline uint16_t att_get_u16(const void *ptr)
{
const uint16_t *u16_ptr = ptr;
--
1.8.3.1


2014-03-20 14:43:10

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 45/62] Replace att_put_u16() by put_le16()

---
attrib/att.c | 48 ++++++++++++------------
attrib/gatt-service.c | 2 +-
plugins/gatt-example.c | 73 ++++++++++++++++++------------------
profiles/cyclingspeed/cyclingspeed.c | 10 ++---
profiles/gatt/gas.c | 2 +-
profiles/heartrate/heartrate.c | 8 ++--
profiles/proximity/reporter.c | 7 ++--
profiles/scanparam/scan.c | 6 +--
profiles/thermometer/thermometer.c | 12 +++---
profiles/time/server.c | 3 +-
src/attrib-server.c | 26 ++++++-------
11 files changed, 100 insertions(+), 97 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index bdf7c00..8e9c06d 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -161,9 +161,9 @@ uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_BY_GROUP_REQ;
/* Starting Handle (2 octets) */
- att_put_u16(start, &pdu[1]);
+ put_le16(start, &pdu[1]);
/* Ending Handle (2 octets) */
- att_put_u16(end, &pdu[3]);
+ put_le16(end, &pdu[3]);
/* Attribute Group Type (2 or 16 octet UUID) */
put_uuid_le(uuid, &pdu[5]);

@@ -291,8 +291,8 @@ uint16_t enc_find_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
vlen = len - min_len;

pdu[0] = ATT_OP_FIND_BY_TYPE_REQ;
- att_put_u16(start, &pdu[1]);
- att_put_u16(end, &pdu[3]);
+ put_le16(start, &pdu[1]);
+ put_le16(end, &pdu[3]);
put_le16(uuid->value.u16, &pdu[5]);

if (vlen > 0) {
@@ -347,8 +347,8 @@ uint16_t enc_find_by_type_resp(GSList *matches, uint8_t *pdu, size_t len)
l = l->next, offset += sizeof(uint16_t) * 2) {
struct att_range *range = l->data;

- att_put_u16(range->start, &pdu[offset]);
- att_put_u16(range->end, &pdu[offset + 2]);
+ put_le16(range->start, &pdu[offset]);
+ put_le16(range->end, &pdu[offset + 2]);
}

return offset;
@@ -406,9 +406,9 @@ uint16_t enc_read_by_type_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_BY_TYPE_REQ;
/* Starting Handle (2 octets) */
- att_put_u16(start, &pdu[1]);
+ put_le16(start, &pdu[1]);
/* Ending Handle (2 octets) */
- att_put_u16(end, &pdu[3]);
+ put_le16(end, &pdu[3]);
/* Attribute Type (2 or 16 octet UUID) */
put_uuid_le(uuid, &pdu[5]);

@@ -527,7 +527,7 @@ uint16_t enc_write_cmd(uint16_t handle, const uint8_t *value, size_t vlen,
vlen = len - min_len;

pdu[0] = ATT_OP_WRITE_CMD;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);

if (vlen > 0) {
memcpy(&pdu[3], value, vlen);
@@ -573,7 +573,7 @@ uint16_t enc_write_req(uint16_t handle, const uint8_t *value, size_t vlen,
vlen = len - min_len;

pdu[0] = ATT_OP_WRITE_REQ;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);

if (vlen > 0) {
memcpy(&pdu[3], value, vlen);
@@ -637,7 +637,7 @@ uint16_t enc_read_req(uint16_t handle, uint8_t *pdu, size_t len)
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_REQ;
/* Attribute Handle (2 octets) */
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);

return 3;
}
@@ -651,9 +651,9 @@ uint16_t enc_read_blob_req(uint16_t handle, uint16_t offset, uint8_t *pdu,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_READ_BLOB_REQ;
/* Attribute Handle (2 octets) */
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);
/* Value Offset (2 octets) */
- att_put_u16(offset, &pdu[3]);
+ put_le16(offset, &pdu[3]);

return 5;
}
@@ -769,7 +769,7 @@ uint16_t enc_error_resp(uint8_t opcode, uint16_t handle, uint8_t status,
/* Request Opcode In Error (1 octet) */
pdu[1] = opcode;
/* Attribute Handle In Error (2 octets) */
- att_put_u16(handle, &pdu[2]);
+ put_le16(handle, &pdu[2]);
/* Error Code (1 octet) */
pdu[4] = status;

@@ -785,9 +785,9 @@ uint16_t enc_find_info_req(uint16_t start, uint16_t end, uint8_t *pdu,
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_FIND_INFO_REQ;
/* Starting Handle (2 octets) */
- att_put_u16(start, &pdu[1]);
+ put_le16(start, &pdu[1]);
/* Ending Handle (2 octets) */
- att_put_u16(end, &pdu[3]);
+ put_le16(end, &pdu[3]);

return 5;
}
@@ -895,7 +895,7 @@ uint16_t enc_notification(uint16_t handle, uint8_t *value, size_t vlen,
return 0;

pdu[0] = ATT_OP_HANDLE_NOTIFY;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);
memcpy(&pdu[3], value, vlen);

return vlen + min_len;
@@ -913,7 +913,7 @@ uint16_t enc_indication(uint16_t handle, uint8_t *value, size_t vlen,
return 0;

pdu[0] = ATT_OP_HANDLE_IND;
- att_put_u16(handle, &pdu[1]);
+ put_le16(handle, &pdu[1]);
memcpy(&pdu[3], value, vlen);

return vlen + min_len;
@@ -963,7 +963,7 @@ uint16_t enc_mtu_req(uint16_t mtu, uint8_t *pdu, size_t len)
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_MTU_REQ;
/* Client Rx MTU (2 octets) */
- att_put_u16(mtu, &pdu[1]);
+ put_le16(mtu, &pdu[1]);

return 3;
}
@@ -997,7 +997,7 @@ uint16_t enc_mtu_resp(uint16_t mtu, uint8_t *pdu, size_t len)
/* Attribute Opcode (1 octet) */
pdu[0] = ATT_OP_MTU_RESP;
/* Server Rx MTU (2 octets) */
- att_put_u16(mtu, &pdu[1]);
+ put_le16(mtu, &pdu[1]);

return 3;
}
@@ -1037,8 +1037,8 @@ uint16_t enc_prep_write_req(uint16_t handle, uint16_t offset,
vlen = len - min_len;

pdu[0] = ATT_OP_PREP_WRITE_REQ;
- att_put_u16(handle, &pdu[1]);
- att_put_u16(offset, &pdu[3]);
+ put_le16(handle, &pdu[1]);
+ put_le16(offset, &pdu[3]);

if (vlen > 0) {
memcpy(&pdu[5], value, vlen);
@@ -1090,8 +1090,8 @@ uint16_t enc_prep_write_resp(uint16_t handle, uint16_t offset,
vlen = len - min_len;

pdu[0] = ATT_OP_PREP_WRITE_RESP;
- att_put_u16(handle, &pdu[1]);
- att_put_u16(offset, &pdu[3]);
+ put_le16(handle, &pdu[1]);
+ put_le16(offset, &pdu[3]);

if (vlen > 0) {
memcpy(&pdu[5], value, vlen);
diff --git a/attrib/gatt-service.c b/attrib/gatt-service.c
index 699ac1e..d68e8b9 100644
--- a/attrib/gatt-service.c
+++ b/attrib/gatt-service.c
@@ -232,7 +232,7 @@ static gboolean add_characteristic(struct btd_adapter *adapter,
/* characteristic declaration */
bt_uuid16_create(&bt_uuid, GATT_CHARAC_UUID);
atval[0] = info->props;
- att_put_u16(h + 1, &atval[1]);
+ put_le16(h + 1, &atval[1]);
put_uuid_le(&info->uuid, &atval[3]);
if (attrib_db_add(adapter, h++, &bt_uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 3 + info->uuid.type / 8) == NULL)
diff --git a/plugins/gatt-example.c b/plugins/gatt-example.c
index d710917..22a6925 100644
--- a/plugins/gatt-example.c
+++ b/plugins/gatt-example.c
@@ -33,6 +33,7 @@
#include "src/plugin.h"
#include "src/adapter.h"
#include "src/hcid.h"
+#include "src/shared/util.h"
#include "src/log.h"
#include "attrib/gattrib.h"
#include "attrib/gatt-service.h"
@@ -149,7 +150,7 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,

/* Thermometer: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(THERM_HUMIDITY_SVC_UUID, &atval[0]);
+ put_le16(THERM_HUMIDITY_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

@@ -157,18 +158,18 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,

/* Thermometer: Include */
if (manuf1[0] && manuf1[1]) {
- att_put_u16(manuf1[0], &atval[0]);
- att_put_u16(manuf1[1], &atval[2]);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]);
+ put_le16(manuf1[0], &atval[0]);
+ put_le16(manuf1[1], &atval[2]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[4]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 6);
}

/* Thermometer: Include */
if (manuf2[0] && manuf2[1]) {
- att_put_u16(manuf2[0], &atval[0]);
- att_put_u16(manuf2[1], &atval[2]);
- att_put_u16(VENDOR_SPECIFIC_SVC_UUID, &atval[4]);
+ put_le16(manuf2[0], &atval[0]);
+ put_le16(manuf2[1], &atval[2]);
+ put_le16(VENDOR_SPECIFIC_SVC_UUID, &atval[4]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 6);
}
@@ -176,8 +177,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
/* Thermometer: temperature characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(TEMPERATURE_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(TEMPERATURE_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -192,9 +193,9 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
atval[0] = 0x0E;
atval[1] = 0xFE;
- att_put_u16(FMT_CELSIUS_UUID, &atval[2]);
+ put_le16(FMT_CELSIUS_UUID, &atval[2]);
atval[4] = 0x01;
- att_put_u16(FMT_OUTSIDE_UUID, &atval[5]);
+ put_le16(FMT_OUTSIDE_UUID, &atval[5]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 7);

@@ -208,8 +209,8 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
/* Thermometer: relative humidity characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(RELATIVE_HUMIDITY_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(RELATIVE_HUMIDITY_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -223,9 +224,9 @@ static void register_termometer_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
atval[0] = 0x04;
atval[1] = 0x00;
- att_put_u16(FMT_PERCENT_UUID, &atval[2]);
- att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]);
- att_put_u16(FMT_OUTSIDE_UUID, &atval[6]);
+ put_le16(FMT_PERCENT_UUID, &atval[2]);
+ put_le16(BLUETOOTH_SIG_UUID, &atval[4]);
+ put_le16(FMT_OUTSIDE_UUID, &atval[6]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 8);

@@ -270,15 +271,15 @@ static void register_manuf1_service(struct gatt_example_adapter *adapter,

/* Secondary Service: Manufacturer Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

/* Manufacturer name characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_NAME_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -292,8 +293,8 @@ static void register_manuf1_service(struct gatt_example_adapter *adapter,
/* Manufacturer serial number characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_SERIAL_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -334,15 +335,15 @@ static void register_manuf2_service(struct gatt_example_adapter *adapter,

/* Secondary Service: Manufacturer Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

/* Manufacturer name characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_NAME_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -356,8 +357,8 @@ static void register_manuf2_service(struct gatt_example_adapter *adapter,
/* Characteristic: serial number */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(MANUFACTURER_SERIAL_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -395,15 +396,15 @@ static void register_vendor_service(struct gatt_example_adapter *adapter,

/* Secondary Service: Vendor Specific Service */
bt_uuid16_create(&uuid, GATT_SND_SVC_UUID);
- att_put_u16(VENDOR_SPECIFIC_SVC_UUID, &atval[0]);
+ put_le16(VENDOR_SPECIFIC_SVC_UUID, &atval[0]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

/* Vendor Specific Type characteristic definition */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(VENDOR_SPECIFIC_TYPE_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(VENDOR_SPECIFIC_TYPE_UUID, &atval[3]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -465,9 +466,9 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
if (vendor[0] && vendor[1]) {
/* Weight: include */
bt_uuid16_create(&uuid, GATT_INCLUDE_UUID);
- att_put_u16(vendor[0], &atval[0]);
- att_put_u16(vendor[1], &atval[2]);
- att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]);
+ put_le16(vendor[0], &atval[0]);
+ put_le16(vendor[1], &atval[2]);
+ put_le16(MANUFACTURER_SVC_UUID, &atval[4]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 6);
}
@@ -475,7 +476,7 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
/* Weight: characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(h + 1, &atval[1]);
+ put_le16(h + 1, &atval[1]);
memcpy(&atval[3], &char_weight_uuid_btorder, 16);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 19);
@@ -493,9 +494,9 @@ static void register_weight_service(struct gatt_example_adapter *adapter,
bt_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID);
atval[0] = 0x08;
atval[1] = 0xFD;
- att_put_u16(FMT_KILOGRAM_UUID, &atval[2]);
- att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]);
- att_put_u16(FMT_HANGING_UUID, &atval[6]);
+ put_le16(FMT_KILOGRAM_UUID, &atval[2]);
+ put_le16(BLUETOOTH_SIG_UUID, &atval[4]);
+ put_le16(FMT_HANGING_UUID, &atval[6]);
attrib_db_add(adapter->adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 8);

diff --git a/profiles/cyclingspeed/cyclingspeed.c b/profiles/cyclingspeed/cyclingspeed.c
index 63e969a..2f80bca 100644
--- a/profiles/cyclingspeed/cyclingspeed.c
+++ b/profiles/cyclingspeed/cyclingspeed.c
@@ -457,16 +457,16 @@ static void discover_desc_cb(guint8 status, const guint8 *pdu,
ch->csc->measurement_ccc_handle = handle;

if (g_slist_length(ch->csc->cadapter->watchers) == 0) {
- att_put_u16(0x0000, attr_val);
+ put_le16(0x0000, attr_val);
msg = g_strdup("Disable measurement");
} else {
- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT,
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT,
attr_val);
msg = g_strdup("Enable measurement");
}

} else if (g_strcmp0(ch->uuid, SC_CONTROL_POINT_UUID) == 0) {
- att_put_u16(GATT_CLIENT_CHARAC_CFG_IND_BIT, attr_val);
+ put_le16(GATT_CLIENT_CHARAC_CFG_IND_BIT, attr_val);
msg = g_strdup("Enable SC Control Point indications");
} else {
break;
@@ -817,7 +817,7 @@ static void enable_measurement(gpointer data, gpointer user_data)
if (csc->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
msg = g_strdup("Enable measurement");

gatt_write_char(csc->attrib, handle, value, sizeof(value),
@@ -834,7 +834,7 @@ static void disable_measurement(gpointer data, gpointer user_data)
if (csc->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable measurement");

gatt_write_char(csc->attrib, handle, value, sizeof(value),
diff --git a/profiles/gatt/gas.c b/profiles/gatt/gas.c
index 38f5e72..7a9d34e 100644
--- a/profiles/gatt/gas.c
+++ b/profiles/gatt/gas.c
@@ -233,7 +233,7 @@ static void write_ccc(GAttrib *attrib, uint16_t handle, gpointer user_data)
{
uint8_t value[2];

- att_put_u16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
gatt_write_char(attrib, handle, value, sizeof(value), ccc_written_cb,
user_data);
}
diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index 15ccdfd..1dcbdf4 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -428,10 +428,10 @@ static void discover_ccc_cb(guint8 status, const guint8 *pdu,
hr->measurement_ccc_handle = handle;

if (g_slist_length(hr->hradapter->watchers) == 0) {
- att_put_u16(0x0000, attr_val);
+ put_le16(0x0000, attr_val);
msg = g_strdup("Disable measurement");
} else {
- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, attr_val);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, attr_val);
msg = g_strdup("Enable measurement");
}

@@ -511,7 +511,7 @@ static void enable_measurement(gpointer data, gpointer user_data)
if (hr->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
msg = g_strdup("Enable measurement");

gatt_write_char(hr->attrib, handle, value, sizeof(value),
@@ -528,7 +528,7 @@ static void disable_measurement(gpointer data, gpointer user_data)
if (hr->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable measurement");

gatt_write_char(hr->attrib, handle, value, sizeof(value),
diff --git a/profiles/proximity/reporter.c b/profiles/proximity/reporter.c
index bda993d..5861923 100644
--- a/profiles/proximity/reporter.c
+++ b/profiles/proximity/reporter.c
@@ -43,6 +43,7 @@
#include "src/device.h"
#include "src/profile.h"
#include "src/service.h"
+#include "src/shared/util.h"
#include "src/hcid.h"
#include "attrib/gattrib.h"
#include "attrib/att.h"
@@ -117,14 +118,14 @@ static void register_tx_power(struct btd_adapter *adapter)

/* Primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(TX_POWER_SVC_UUID, &atval[0]);
+ put_le16(TX_POWER_SVC_UUID, &atval[0]);
attrib_db_add(adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2);

/* Power level characteristic */
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ | ATT_CHAR_PROPER_NOTIFY;
- att_put_u16(h + 1, &atval[1]);
- att_put_u16(POWER_LEVEL_CHR_UUID, &atval[3]);
+ put_le16(h + 1, &atval[1]);
+ put_le16(POWER_LEVEL_CHR_UUID, &atval[3]);
attrib_db_add(adapter, h++, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5);

/* Power level value */
diff --git a/profiles/scanparam/scan.c b/profiles/scanparam/scan.c
index d6e477e..156682f 100644
--- a/profiles/scanparam/scan.c
+++ b/profiles/scanparam/scan.c
@@ -67,8 +67,8 @@ static void write_scan_params(GAttrib *attrib, uint16_t handle)
{
uint8_t value[4];

- att_put_u16(SCAN_INTERVAL, &value[0]);
- att_put_u16(SCAN_WINDOW, &value[2]);
+ put_le16(SCAN_INTERVAL, &value[0]);
+ put_le16(SCAN_WINDOW, &value[2]);

gatt_write_cmd(attrib, handle, value, sizeof(value), NULL, NULL);
}
@@ -126,7 +126,7 @@ static void discover_descriptor_cb(guint8 status, const guint8 *pdu,
if (uuid16 != GATT_CLIENT_CHARAC_CFG_UUID)
goto done;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
gatt_write_char(scan->attrib, handle, value, sizeof(value),
ccc_written_cb, user_data);
done:
diff --git a/profiles/thermometer/thermometer.c b/profiles/thermometer/thermometer.c
index 5b90792..9462cc9 100644
--- a/profiles/thermometer/thermometer.c
+++ b/profiles/thermometer/thermometer.c
@@ -569,7 +569,7 @@ static void process_thermometer_desc(struct characteristic *ch, uint16_t uuid,
return;
}

- att_put_u16(val, atval);
+ put_le16(val, atval);
gatt_write_char(ch->t->attrib, handle, atval, sizeof(atval),
write_ccc_cb, msg);
}
@@ -790,7 +790,7 @@ static void enable_final_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_IND_BIT, value);
msg = g_strdup("Enable Temperature Measurement indications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -807,7 +807,7 @@ static void enable_intermediate_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
+ put_le16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT, value);
msg = g_strdup("Enable Intermediate Temperature notifications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -824,7 +824,7 @@ static void disable_final_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable Temperature Measurement indications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -841,7 +841,7 @@ static void disable_intermediate_measurement(gpointer data, gpointer user_data)
if (t->attrib == NULL || !handle)
return;

- att_put_u16(0x0000, value);
+ put_le16(0x0000, value);
msg = g_strdup("Disable Intermediate Temperature notifications");

gatt_write_char(t->attrib, handle, value, sizeof(value),
@@ -1071,7 +1071,7 @@ static void property_set_interval(const GDBusPropertyTable *property,
return;
}

- att_put_u16(val, &atval[0]);
+ put_le16(val, &atval[0]);

interval_data = g_new0(struct tmp_interval_data, 1);
interval_data->thermometer = t;
diff --git a/profiles/time/server.c b/profiles/time/server.c
index 142d15c..31ddb06 100644
--- a/profiles/time/server.c
+++ b/profiles/time/server.c
@@ -41,6 +41,7 @@
#include "attrib/att.h"
#include "attrib/gatt.h"
#include "attrib/att-database.h"
+#include "src/shared/util.h"
#include "src/attrib-server.h"
#include "attrib/gatt-service.h"
#include "src/log.h"
@@ -90,7 +91,7 @@ static int encode_current_time(uint8_t value[10])
return -EINVAL;
}

- att_put_u16(1900 + tm.tm_year, &value[0]); /* Year */
+ put_le16(1900 + tm.tm_year, &value[0]); /* Year */
value[2] = tm.tm_mon + 1; /* Month */
value[3] = tm.tm_mday; /* Day */
value[4] = tm.tm_hour; /* Hours */
diff --git a/src/attrib-server.c b/src/attrib-server.c
index e089c0d..dcd473b 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -513,8 +513,8 @@ static uint16_t read_by_group(struct gatt_channel *channel, uint16_t start,

value = (void *) adl->data[i];

- att_put_u16(cur->handle, value);
- att_put_u16(cur->end, &value[2]);
+ put_le16(cur->handle, value);
+ put_le16(cur->end, &value[2]);
/* Attribute Value */
memcpy(&value[4], cur->data, cur->len);
}
@@ -602,7 +602,7 @@ static uint16_t read_by_type(struct gatt_channel *channel, uint16_t start,

value = (void *) adl->data[i];

- att_put_u16(a->handle, value);
+ put_le16(a->handle, value);

/* Attribute Value */
memcpy(&value[2], a->data, a->len);
@@ -682,7 +682,7 @@ static uint16_t find_info(struct gatt_channel *channel, uint16_t start,

value = (void *) adl->data[i];

- att_put_u16(a->handle, value);
+ put_le16(a->handle, value);

/* Attribute Value */
put_uuid_le(&a->uuid, &value[2]);
@@ -811,7 +811,7 @@ static uint16_t read_value(struct gatt_channel *channel, uint16_t handle,
read_device_ccc(channel->device, handle, &cccval) == 0) {
uint8_t config[2];

- att_put_u16(cccval, config);
+ put_le16(cccval, config);
return enc_read_resp(config, sizeof(config), pdu, len);
}

@@ -852,7 +852,7 @@ static uint16_t read_blob(struct gatt_channel *channel, uint16_t handle,
read_device_ccc(channel->device, handle, &cccval) == 0) {
uint8_t config[2];

- att_put_u16(cccval, config);
+ put_le16(cccval, config);
return enc_read_blob_resp(config, sizeof(config), offset,
pdu, len);
}
@@ -1299,7 +1299,7 @@ static gboolean register_core_services(struct gatt_server *server)

/* GAP service: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(GENERIC_ACCESS_PROFILE_ID, &atval[0]);
+ put_le16(GENERIC_ACCESS_PROFILE_ID, &atval[0]);
attrib_db_add_new(server, 0x0001, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

@@ -1307,8 +1307,8 @@ static gboolean register_core_services(struct gatt_server *server)
server->name_handle = 0x0006;
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(server->name_handle, &atval[1]);
- att_put_u16(GATT_CHARAC_DEVICE_NAME, &atval[3]);
+ put_le16(server->name_handle, &atval[1]);
+ put_le16(GATT_CHARAC_DEVICE_NAME, &atval[3]);
attrib_db_add_new(server, 0x0004, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

@@ -1321,14 +1321,14 @@ static gboolean register_core_services(struct gatt_server *server)
server->appearance_handle = 0x0008;
bt_uuid16_create(&uuid, GATT_CHARAC_UUID);
atval[0] = ATT_CHAR_PROPER_READ;
- att_put_u16(server->appearance_handle, &atval[1]);
- att_put_u16(GATT_CHARAC_APPEARANCE, &atval[3]);
+ put_le16(server->appearance_handle, &atval[1]);
+ put_le16(GATT_CHARAC_APPEARANCE, &atval[3]);
attrib_db_add_new(server, 0x0007, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 5);

/* GAP service: device appearance attribute */
bt_uuid16_create(&uuid, GATT_CHARAC_APPEARANCE);
- att_put_u16(appearance, &atval[0]);
+ put_le16(appearance, &atval[0]);
attrib_db_add_new(server, server->appearance_handle, &uuid, ATT_NONE,
ATT_NOT_PERMITTED, atval, 2);
server->gap_sdp_handle = attrib_create_sdp_new(server, 0x0001,
@@ -1340,7 +1340,7 @@ static gboolean register_core_services(struct gatt_server *server)

/* GATT service: primary service definition */
bt_uuid16_create(&uuid, GATT_PRIM_SVC_UUID);
- att_put_u16(GENERIC_ATTRIB_PROFILE_ID, &atval[0]);
+ put_le16(GENERIC_ATTRIB_PROFILE_ID, &atval[0]);
attrib_db_add_new(server, 0x0010, &uuid, ATT_NONE, ATT_NOT_PERMITTED,
atval, 2);

--
1.8.3.1


2014-03-20 14:43:08

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 43/62] Replace att_get_uuid128() by bswap_128()

GATT/ATT use little-endian byte order format for 128-bit UUID. No matter
the system byte order representation, internally the core will handle
128-bit UUID on big-endian format.
---
attrib/att.c | 38 +++++++++++++++++++++--------
attrib/gatt.c | 69 +++++++++++++++++++++++++++++++++++-----------------
attrib/gatttool.c | 9 +++++--
attrib/interactive.c | 9 +++++--
4 files changed, 89 insertions(+), 36 deletions(-)

diff --git a/attrib/att.c b/attrib/att.c
index 1df6190..bd23142 100644
--- a/attrib/att.c
+++ b/attrib/att.c
@@ -121,6 +121,19 @@ struct att_data_list *att_data_list_alloc(uint16_t num, uint16_t len)
return list;
}

+static void get_uuid(uint8_t type, const void *val, bt_uuid_t *uuid)
+{
+ if (type == BT_UUID16)
+ bt_uuid16_create(uuid, get_le16(val));
+ else {
+ uint128_t u128;
+
+ /* Convert from 128-bit LE to BE */
+ bswap_128(val, &u128);
+ bt_uuid128_create(uuid, u128);
+ }
+}
+
uint16_t enc_read_by_grp_req(uint16_t start, uint16_t end, bt_uuid_t *uuid,
uint8_t *pdu, size_t len)
{
@@ -152,6 +165,7 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
uint16_t *end, bt_uuid_t *uuid)
{
const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end);
+ uint8_t type;

if (pdu == NULL)
return 0;
@@ -162,15 +176,17 @@ uint16_t dec_read_by_grp_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (pdu[0] != ATT_OP_READ_BY_GROUP_REQ)
return 0;

- if (len != (min_len + 2) && len != (min_len + 16))
+ if (len == (min_len + 2))
+ type = BT_UUID16;
+ else if (len == (min_len + 16))
+ type = BT_UUID128;
+ else
return 0;

*start = get_le16(&pdu[1]);
*end = get_le16(&pdu[3]);
- if (len == min_len + 2)
- bt_uuid16_create(uuid, get_le16(&pdu[5]));
- else
- *uuid = att_get_uuid128(&pdu[5]);
+
+ get_uuid(type, &pdu[5], uuid);

return len;
}
@@ -394,6 +410,7 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
uint16_t *end, bt_uuid_t *uuid)
{
const size_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end);
+ uint8_t type;

if (pdu == NULL)
return 0;
@@ -401,7 +418,11 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
if (start == NULL || end == NULL || uuid == NULL)
return 0;

- if (len != (min_len + 2) && len != (min_len + 16))
+ if (len == (min_len + 2))
+ type = BT_UUID16;
+ else if (len == (min_len + 16))
+ type = BT_UUID128;
+ else
return 0;

if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ)
@@ -410,10 +431,7 @@ uint16_t dec_read_by_type_req(const uint8_t *pdu, size_t len, uint16_t *start,
*start = get_le16(&pdu[1]);
*end = get_le16(&pdu[3]);

- if (len == min_len + 2)
- bt_uuid16_create(uuid, get_le16(&pdu[5]));
- else
- *uuid = att_get_uuid128(&pdu[5]);
+ get_uuid(type, &pdu[5], uuid);

return len;
}
diff --git a/attrib/gatt.c b/attrib/gatt.c
index 83692f4..7b8b229 100644
--- a/attrib/gatt.c
+++ b/attrib/gatt.c
@@ -148,6 +148,22 @@ static void put_uuid_le(const bt_uuid_t *uuid, void *dst)
bswap_128(&uuid->value.u128, dst);
}

+static void get_uuid128(uint8_t type, const void *val, bt_uuid_t *uuid)
+{
+ if (type == BT_UUID16) {
+ bt_uuid_t uuid16;
+
+ bt_uuid16_create(uuid, get_le16(val));
+ bt_uuid_to_uuid128(&uuid16, uuid);
+ } else {
+ uint128_t u128;
+
+ /* Convert from 128-bit LE to BE */
+ bswap_128(val, &u128);
+ bt_uuid128_create(uuid, u128);
+ }
+}
+
static guint16 encode_discover_primary(uint16_t start, uint16_t end,
bt_uuid_t *uuid, uint8_t *pdu, size_t len)
{
@@ -225,6 +241,7 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
struct att_data_list *list;
unsigned int i, err;
uint16_t start, end;
+ uint8_t type;

if (status) {
err = status == ATT_ECODE_ATTR_NOT_FOUND ? 0 : status;
@@ -240,23 +257,26 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
for (i = 0, end = 0; i < list->num; i++) {
const uint8_t *data = list->data[i];
struct gatt_primary *primary;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;

start = get_le16(&data[0]);
end = get_le16(&data[2]);

- if (list->len == 6) {
- bt_uuid_t uuid16;
-
- bt_uuid16_create(&uuid16, get_le16(&data[4]));
- bt_uuid_to_uuid128(&uuid16, &uuid);
- } else if (list->len == 20) {
- uuid = att_get_uuid128(&data[4]);
- } else {
+ /*
+ * FIXME: Check before "for". Elements in the Attribute
+ * Data List have the same length (list->len).
+ */
+ if (list->len == 6)
+ type = BT_UUID16;
+ else if (list->len == 20)
+ type = BT_UUID128;
+ else {
/* Skipping invalid data */
continue;
}

+ get_uuid128(type, &data[4], &uuid128);
+
primary = g_try_new0(struct gatt_primary, 1);
if (!primary) {
att_data_list_free(list);
@@ -265,7 +285,7 @@ static void primary_all_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
}
primary->range.start = start;
primary->range.end = end;
- bt_uuid_to_string(&uuid, primary->uuid, sizeof(primary->uuid));
+ bt_uuid_to_string(&uuid128, primary->uuid, sizeof(primary->uuid));
dp->primaries = g_slist_append(dp->primaries, primary);
}

@@ -328,7 +348,7 @@ static void resolve_included_uuid_cb(uint8_t status, const uint8_t *pdu,
struct included_discovery *isd = query->isd;
struct gatt_included *incl = query->included;
unsigned int err = status;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;
size_t buflen;
uint8_t *buf;

@@ -341,8 +361,9 @@ static void resolve_included_uuid_cb(uint8_t status, const uint8_t *pdu,
goto done;
}

- uuid = att_get_uuid128(buf);
- bt_uuid_to_string(&uuid, incl->uuid, sizeof(incl->uuid));
+ get_uuid128(BT_UUID128, buf, &uuid128);
+
+ bt_uuid_to_string(&uuid128, incl->uuid, sizeof(incl->uuid));
isd->includes = g_slist_append(isd->includes, incl);
query->included = NULL;

@@ -503,19 +524,23 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
for (i = 0; i < list->num; i++) {
uint8_t *value = list->data[i];
struct gatt_char *chars;
- bt_uuid_t uuid;
+ bt_uuid_t uuid128;
+ uint8_t type;

last = get_le16(value);

- if (list->len == 7) {
- bt_uuid_t uuid16;
+ /*
+ * FIXME: Check before "for". Elements in the Attribute
+ * Data List have the same length (list->len).
+ */
+ if (list->len == 7)
+ type = BT_UUID16;
+ else
+ type = BT_UUID128;

- bt_uuid16_create(&uuid16, get_le16(&value[5]));
- bt_uuid_to_uuid128(&uuid16, &uuid);
- } else
- uuid = att_get_uuid128(&value[5]);
+ get_uuid128(type, &value[5], &uuid128);

- if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid))
+ if (dc->uuid && bt_uuid_cmp(dc->uuid, &uuid128))
continue;

chars = g_try_new0(struct gatt_char, 1);
@@ -527,7 +552,7 @@ static void char_discovered_cb(guint8 status, const guint8 *ipdu, guint16 iplen,
chars->handle = last;
chars->properties = value[2];
chars->value_handle = get_le16(&value[3]);
- bt_uuid_to_string(&uuid, chars->uuid, sizeof(chars->uuid));
+ bt_uuid_to_string(&uuid128, chars->uuid, sizeof(chars->uuid));
dc->characteristics = g_slist_append(dc->characteristics,
chars);
}
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 4eb2528..ca178ce 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -428,8 +428,13 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
- else
- uuid = att_get_uuid128(&value[2]);
+ else {
+ uint128_t u128;
+
+ /* Converts from LE to BE byte order */
+ bswap_128(&value[2], &u128);
+ bt_uuid128_create(&uuid, u128);
+ }

bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
g_print("handle = 0x%04x, uuid = %s\n", handle, uuidstr);
diff --git a/attrib/interactive.c b/attrib/interactive.c
index 5dd47ec..4865944 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -297,8 +297,13 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,

if (format == 0x01)
bt_uuid16_create(&uuid, get_le16(&value[2]));
- else
- uuid = att_get_uuid128(&value[2]);
+ else {
+ uint128_t u128;
+
+ /* Converts from LE to BE byte order */
+ bswap_128(&value[2], &u128);
+ bt_uuid128_create(&uuid, u128);
+ }

bt_uuid_to_string(&uuid, uuidstr, MAX_LEN_UUID_STR);
rl_printf("handle: 0x%04x, uuid: %s\n", handle, uuidstr);
--
1.8.3.1


2014-03-20 14:42:57

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 32/62] lib: Remove ntoh128() from bt_string_to_uuid128()

No matter the system, 128-bit UUIDs should not be converted to any byte
order when creating the UUID. Conversion to big/little endian should be
performed when transfering the data over-the-air only. bt_uuid_t should
handle 128-bit UUID on big-endian format (human-readable format).
---
lib/uuid.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/uuid.c b/lib/uuid.c
index 4363aee..aa2d0cf 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -231,8 +231,8 @@ static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string)
{
uint32_t data0, data4;
uint16_t data1, data2, data3, data5;
- uint128_t n128, u128;
- uint8_t *val = (uint8_t *) &n128;
+ uint128_t u128;
+ uint8_t *val = (uint8_t *) &u128;

if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx",
&data0, &data1, &data2,
@@ -253,8 +253,6 @@ static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string)
memcpy(&val[10], &data4, 4);
memcpy(&val[14], &data5, 2);

- ntoh128(&n128, &u128);
-
bt_uuid128_create(uuid, u128);

return 0;
--
1.8.3.1


2014-03-20 14:42:56

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 31/62] lib: Remove bt_put_be64()

---
lib/bluetooth.h | 17 -----------------
1 file changed, 17 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 20407d7..57ac7b5 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -171,23 +171,6 @@ do { \
__p->__v = (val); \
} while(0)

-#if __BYTE_ORDER == __LITTLE_ENDIAN
-static inline void bt_put_be64(uint64_t val, const void *ptr)
-{
- bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
-}
-
-#elif __BYTE_ORDER == __BIG_ENDIAN
-
-static inline void bt_put_be64(uint64_t val, const void *ptr)
-{
- bt_put_unaligned(val, (uint64_t *) ptr);
-}
-
-#else
-#error "Unknown byte order"
-#endif
-
/* BD Address */
typedef struct {
uint8_t b[6];
--
1.8.3.1


2014-03-20 14:43:00

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 35/62] unit: Use lower-case for 128-bit UUIDs

According to ISO/IEC 9834-8: "It is recommended that the hexadecimal
representation used in all human-readable formats be restricted to
lower-case letters. Software processing this representation is, however,
required to accept both upper and lower case letters as specified in
6.5.2."
---
unit/test-uuid.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/unit/test-uuid.c b/unit/test-uuid.c
index 79ab3e6..225a7b5 100644
--- a/unit/test-uuid.c
+++ b/unit/test-uuid.c
@@ -46,10 +46,10 @@ static unsigned char uuid_base_binary[] = {
0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb };

static struct uuid_test_data uuid_base = {
- .str = "00000000-0000-1000-8000-00805F9B34FB",
+ .str = "00000000-0000-1000-8000-00805f9b34fb",
.binary = uuid_base_binary,
.type = BT_UUID128,
- .str128 = "00000000-0000-1000-8000-00805F9B34FB",
+ .str128 = "00000000-0000-1000-8000-00805f9b34fb",
.binary128 = uuid_base_binary,
};

--
1.8.3.1


2014-03-20 14:42:58

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 33/62] lib: Remove hton128() from bt_uuid_to_string()

bt_uuid_to_string() helper should get the raw UUID value. Caller should
convert the 128-bit UUID before call this helper if necessary. bt_uuid_t
stores 128-bit UUID on big-endian format (human-readable format), swap
byte order is not necessary.
---
lib/uuid.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/lib/uuid.c b/lib/uuid.c
index aa2d0cf..dbca330 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -154,10 +154,7 @@ int bt_uuid_to_string(const bt_uuid_t *uuid, char *str, size_t n)
unsigned int data4;
unsigned short data5;

- uint128_t nvalue;
- const uint8_t *data = (uint8_t *) &nvalue;
-
- hton128(&uuid->value.u128, &nvalue);
+ const uint8_t *data = (uint8_t *) &uuid->value.u128;

memcpy(&data0, &data[0], 4);
memcpy(&data1, &data[4], 2);
--
1.8.3.1


2014-03-20 14:42:55

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 30/62] lib: Remove bt_put_be32()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index aa959ef..20407d7 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -177,11 +177,6 @@ static inline void bt_put_be64(uint64_t val, const void *ptr)
bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
}

-static inline void bt_put_be32(uint32_t val, const void *ptr)
-{
- bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
-}
-
#elif __BYTE_ORDER == __BIG_ENDIAN

static inline void bt_put_be64(uint64_t val, const void *ptr)
@@ -189,11 +184,6 @@ static inline void bt_put_be64(uint64_t val, const void *ptr)
bt_put_unaligned(val, (uint64_t *) ptr);
}

-static inline void bt_put_be32(uint32_t val, const void *ptr)
-{
- bt_put_unaligned(val, (uint32_t *) ptr);
-}
-
#else
#error "Unknown byte order"
#endif
--
1.8.3.1


2014-03-20 14:42:52

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 27/62] lib: Remove bt_get_be32()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 3dcb049..6843c7f 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -177,11 +177,6 @@ static inline uint64_t bt_get_be64(const void *ptr)
return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
}

-static inline uint32_t bt_get_be32(const void *ptr)
-{
- return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
@@ -204,11 +199,6 @@ static inline uint64_t bt_get_be64(const void *ptr)
return bt_get_unaligned((const uint64_t *) ptr);
}

-static inline uint32_t bt_get_be32(const void *ptr)
-{
- return bt_get_unaligned((const uint32_t *) ptr);
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(val, (uint64_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:53

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 28/62] lib: Remove bt_get_be64()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 6843c7f..eb623cc 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -172,11 +172,6 @@ do { \
} while(0)

#if __BYTE_ORDER == __LITTLE_ENDIAN
-static inline uint64_t bt_get_be64(const void *ptr)
-{
- return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
@@ -194,11 +189,6 @@ static inline void bt_put_be16(uint16_t val, const void *ptr)

#elif __BYTE_ORDER == __BIG_ENDIAN

-static inline uint64_t bt_get_be64(const void *ptr)
-{
- return bt_get_unaligned((const uint64_t *) ptr);
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(val, (uint64_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:50

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 25/62] lib: Remove bt_get_le64()

---
lib/bluetooth.h | 9 ---------
1 file changed, 9 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index f045070..37fa04d 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -172,11 +172,6 @@ do { \
} while(0)

#if __BYTE_ORDER == __LITTLE_ENDIAN
-static inline uint64_t bt_get_le64(const void *ptr)
-{
- return bt_get_unaligned((const uint64_t *) ptr);
-}
-
static inline uint64_t bt_get_be64(const void *ptr)
{
return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
@@ -208,10 +203,6 @@ static inline void bt_put_be16(uint16_t val, const void *ptr)
}

#elif __BYTE_ORDER == __BIG_ENDIAN
-static inline uint64_t bt_get_le64(const void *ptr)
-{
- return bswap_64(bt_get_unaligned((const uint64_t *) ptr));
-}

static inline uint64_t bt_get_be64(const void *ptr)
{
--
1.8.3.1


2014-03-20 14:42:48

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 23/62] lib: Remove bt_get_le16()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index a476180..58ad96a 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -192,11 +192,6 @@ static inline uint32_t bt_get_be32(const void *ptr)
return bswap_32(bt_get_unaligned((const uint32_t *) ptr));
}

-static inline uint16_t bt_get_le16(const void *ptr)
-{
- return bt_get_unaligned((const uint16_t *) ptr);
-}
-
static inline uint16_t bt_get_be16(const void *ptr)
{
return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
@@ -238,11 +233,6 @@ static inline uint32_t bt_get_be32(const void *ptr)
return bt_get_unaligned((const uint32_t *) ptr);
}

-static inline uint16_t bt_get_le16(const void *ptr)
-{
- return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
-}
-
static inline uint16_t bt_get_be16(const void *ptr)
{
return bt_get_unaligned((const uint16_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:46

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 21/62] lib: Remove bt_put_le32()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 8865c00..cb6f563 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -212,11 +212,6 @@ static inline void bt_put_be64(uint64_t val, const void *ptr)
bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
}

-static inline void bt_put_le32(uint32_t val, const void *ptr)
-{
- bt_put_unaligned(val, (uint32_t *) ptr);
-}
-
static inline void bt_put_be32(uint32_t val, const void *ptr)
{
bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
@@ -268,11 +263,6 @@ static inline void bt_put_be64(uint64_t val, const void *ptr)
bt_put_unaligned(val, (uint64_t *) ptr);
}

-static inline void bt_put_le32(uint32_t val, const void *ptr)
-{
- bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
-}
-
static inline void bt_put_be32(uint32_t val, const void *ptr)
{
bt_put_unaligned(val, (uint32_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:47

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 22/62] lib: Remove bt_put_le64()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index cb6f563..a476180 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -202,11 +202,6 @@ static inline uint16_t bt_get_be16(const void *ptr)
return bswap_16(bt_get_unaligned((const uint16_t *) ptr));
}

-static inline void bt_put_le64(uint64_t val, const void *ptr)
-{
- bt_put_unaligned(val, (uint64_t *) ptr);
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
@@ -253,11 +248,6 @@ static inline uint16_t bt_get_be16(const void *ptr)
return bt_get_unaligned((const uint16_t *) ptr);
}

-static inline void bt_put_le64(uint64_t val, const void *ptr)
-{
- bt_put_unaligned(bswap_64(val), (uint64_t *) ptr);
-}
-
static inline void bt_put_be64(uint64_t val, const void *ptr)
{
bt_put_unaligned(val, (uint64_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:44

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 19/62] Replace bt_put_be64() by get_be64()

---
profiles/audio/avrcp.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 1d439ec..da2a746 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2449,7 +2449,7 @@ static void avrcp_get_item_attributes(struct avrcp *session, uint64_t uid)

pdu->pdu_id = AVRCP_GET_ITEM_ATTRIBUTES;
pdu->params[0] = 0x03;
- bt_put_be64(uid, &pdu->params[1]);
+ put_be64(uid, &pdu->params[1]);
put_be16(player->uid_counter, &pdu->params[9]);
pdu->param_len = htons(12);

@@ -2636,7 +2636,7 @@ static void avrcp_change_path(struct avrcp *session, uint8_t direction,
memset(buf, 0, sizeof(buf));
put_be16(player->uid_counter, &pdu->params[0]);
pdu->params[2] = direction;
- bt_put_be64(uid, &pdu->params[3]);
+ put_be64(uid, &pdu->params[3]);
pdu->pdu_id = AVRCP_CHANGE_PATH;
pdu->param_len = htons(11);

@@ -2738,7 +2738,7 @@ static void avrcp_play_item(struct avrcp *session, uint64_t uid)
pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;

pdu->params[0] = player->scope;
- bt_put_be64(uid, &pdu->params[1]);
+ put_be64(uid, &pdu->params[1]);
put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
@@ -2784,7 +2784,7 @@ static void avrcp_add_to_nowplaying(struct avrcp *session, uint64_t uid)
pdu->packet_type = AVRCP_PACKET_TYPE_SINGLE;

pdu->params[0] = player->scope;
- bt_put_be64(uid, &pdu->params[1]);
+ put_be64(uid, &pdu->params[1]);
put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);
--
1.8.3.1


2014-03-20 14:42:28

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 03/62] shared: Add get_le32()

Add helper to avoid possible unaligned memory access when handling
uint32 value using little-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index ef845ae..8caee61 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -106,6 +106,11 @@ static inline uint16_t get_le16(const void *ptr)
return le16_to_cpu(get_unaligned((const uint16_t *) ptr));
}

+static inline uint32_t get_le32(const void *ptr)
+{
+ return le32_to_cpu(get_unaligned((const uint32_t *) ptr));
+}
+
static inline void put_le16(uint16_t val, void *dst)
{
put_unaligned(cpu_to_le16(val), (uint16_t *) dst);
--
1.8.3.1


2014-03-20 14:42:45

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 20/62] lib: Remove bt_put_le16()

---
lib/bluetooth.h | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/lib/bluetooth.h b/lib/bluetooth.h
index 61c1f9a..8865c00 100644
--- a/lib/bluetooth.h
+++ b/lib/bluetooth.h
@@ -222,11 +222,6 @@ static inline void bt_put_be32(uint32_t val, const void *ptr)
bt_put_unaligned(bswap_32(val), (uint32_t *) ptr);
}

-static inline void bt_put_le16(uint16_t val, const void *ptr)
-{
- bt_put_unaligned(val, (uint16_t *) ptr);
-}
-
static inline void bt_put_be16(uint16_t val, const void *ptr)
{
bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
@@ -283,11 +278,6 @@ static inline void bt_put_be32(uint32_t val, const void *ptr)
bt_put_unaligned(val, (uint32_t *) ptr);
}

-static inline void bt_put_le16(uint16_t val, const void *ptr)
-{
- bt_put_unaligned(bswap_16(val), (uint16_t *) ptr);
-}
-
static inline void bt_put_be16(uint16_t val, const void *ptr)
{
bt_put_unaligned(val, (uint16_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:34

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 09/62] shared: Add put_be32()

Add helper to avoid possible unaligned memory access when handling
uint32 value using big-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index 0d0b45f..baeba91 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -146,6 +146,11 @@ static inline void put_le32(uint32_t val, void *dst)
put_unaligned(cpu_to_le32(val), (uint32_t *) dst);
}

+static inline void put_be32(uint32_t val, const void *ptr)
+{
+ put_unaligned(cpu_to_be32(val), (uint32_t *) ptr);
+}
+
static inline void put_le64(uint64_t val, const void *ptr)
{
put_unaligned(cpu_to_le64(val), (uint64_t *) ptr);
--
1.8.3.1


2014-03-20 14:42:41

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 16/62] Replace bt_get_be64() by get_be64()

---
android/avrcp-lib.c | 2 +-
lib/sdp.c | 2 +-
monitor/sdp.c | 2 +-
profiles/audio/avrcp.c | 6 +++---
4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 5e678ea..934106b 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -506,7 +506,7 @@ static ssize_t get_element_attributes(struct avrcp *session,
if (!params || params_len != 9 + params[8] * 4)
return -EINVAL;

- uid = bt_get_be64(params);
+ uid = get_be64(params);
number = params[8];

for (i = 0; i < number; i++) {
diff --git a/lib/sdp.c b/lib/sdp.c
index e4b0d43..9fc2b92 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -1093,7 +1093,7 @@ static sdp_data_t *extract_int(const void *p, int bufsize, int *len)
return NULL;
}
*len += sizeof(uint64_t);
- d->val.uint64 = bt_get_be64(p);
+ d->val.uint64 = get_be64(p);
break;
case SDP_INT128:
case SDP_UINT128:
diff --git a/monitor/sdp.c b/monitor/sdp.c
index d729e1f..e997ca5 100644
--- a/monitor/sdp.c
+++ b/monitor/sdp.c
@@ -98,7 +98,7 @@ static void print_uint(uint8_t indent, const uint8_t *data, uint32_t size)
break;
case 8:
print_field("%*c0x%16.16" PRIx64, indent, ' ',
- bt_get_be64(data));
+ get_be64(data));
break;
default:
packet_hexdump(data, size);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 6772984..ebd10a9 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2126,7 +2126,7 @@ static struct media_item *parse_media_element(struct avrcp *session,
if (len < 13)
return NULL;

- uid = bt_get_be64(&operands[0]);
+ uid = get_be64(&operands[0]);

namelen = MIN(get_be16(&operands[11]), sizeof(name) - 1);
if (namelen > 0) {
@@ -2161,7 +2161,7 @@ static struct media_item *parse_media_folder(struct avrcp *session,
if (len < 12)
return NULL;

- uid = bt_get_be64(&operands[0]);
+ uid = get_be64(&operands[0]);
type = operands[8];
playable = operands[9];

@@ -3072,7 +3072,7 @@ static void avrcp_track_changed(struct avrcp *session,
{
if (session->browsing_id) {
struct avrcp_player *player = session->controller->player;
- player->uid = bt_get_be64(&pdu->params[1]);
+ player->uid = get_be64(&pdu->params[1]);
avrcp_get_item_attributes(session, player->uid);
} else
avrcp_get_element_attributes(session);
--
1.8.3.1


2014-03-20 14:42:39

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 14/62] Replace bt_get_be16() by get_be16()

---
android/avrcp-lib.c | 3 ++-
lib/sdp.c | 25 +++++++++++++------------
monitor/sdp.c | 44 +++++++++++++++++++++++---------------------
profiles/audio/avrcp.c | 30 +++++++++++++++---------------
profiles/network/bnep.c | 5 +++--
profiles/sap/server.c | 3 ++-
src/sdpd-request.c | 12 +++++++-----
src/sdpd-service.c | 5 +++--
8 files changed, 68 insertions(+), 59 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 3f44315..06aa552 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -31,6 +31,7 @@

#include "lib/bluetooth.h"

+#include "src/shared/util.h"
#include "src/log.h"

#include "avctp.h"
@@ -561,7 +562,7 @@ static ssize_t set_addressed(struct avrcp *session, uint8_t transaction,
if (!player->ind || !player->ind->set_addressed)
return -ENOSYS;

- id = bt_get_be16(params);
+ id = get_be16(params);

return player->ind->set_addressed(session, transaction, id,
player->user_data);
diff --git a/lib/sdp.c b/lib/sdp.c
index e5e4622..fec658a 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -48,6 +48,7 @@
#include "l2cap.h"
#include "sdp.h"
#include "sdp_lib.h"
+#include "src/shared/util.h"

#define SDPINF(fmt, arg...) syslog(LOG_INFO, fmt "\n", ## arg)
#define SDPERR(fmt, arg...) syslog(LOG_ERR, "%s: " fmt "\n", __func__ , ## arg)
@@ -1010,7 +1011,7 @@ int sdp_uuid_extract(const uint8_t *p, int bufsize, uuid_t *uuid, int *scanned)
SDPERR("Not enough room for 16-bit UUID");
return -1;
}
- sdp_uuid16_create(uuid, bt_get_be16(p));
+ sdp_uuid16_create(uuid, get_be16(p));
*scanned += sizeof(uint16_t);
} else if (type == SDP_UUID32) {
if (bufsize < (int) sizeof(uint32_t)) {
@@ -1072,7 +1073,7 @@ static sdp_data_t *extract_int(const void *p, int bufsize, int *len)
return NULL;
}
*len += sizeof(uint16_t);
- d->val.uint16 = bt_get_be16(p);
+ d->val.uint16 = get_be16(p);
break;
case SDP_INT32:
case SDP_UINT32:
@@ -1175,7 +1176,7 @@ static sdp_data_t *extract_str(const void *p, int bufsize, int *len)
free(d);
return NULL;
}
- n = bt_get_be16(p);
+ n = get_be16(p);
p += sizeof(uint16_t);
*len += sizeof(uint16_t);
bufsize -= sizeof(uint16_t);
@@ -1245,7 +1246,7 @@ int sdp_extract_seqtype(const uint8_t *buf, int bufsize, uint8_t *dtdp, int *siz
SDPERR("Unexpected end of packet");
return 0;
}
- *size = bt_get_be16(buf);
+ *size = get_be16(buf);
scanned += sizeof(uint16_t);
break;
case SDP_SEQ32:
@@ -1421,7 +1422,7 @@ sdp_record_t *sdp_extract_pdu(const uint8_t *buf, int bufsize, int *scanned)
}

dtd = *(uint8_t *) p;
- attr = bt_get_be16(p + n);
+ attr = get_be16(p + n);
n += sizeof(uint16_t);

SDPDBG("DTD of attrId : %d Attr id : 0x%x ", dtd, attr);
@@ -3482,7 +3483,7 @@ int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search,
pdata += sizeof(uint16_t);
scanned += sizeof(uint16_t);
pdata_len -= sizeof(uint16_t);
- rec_count = bt_get_be16(pdata);
+ rec_count = get_be16(pdata);
pdata += sizeof(uint16_t);
scanned += sizeof(uint16_t);
pdata_len -= sizeof(uint16_t);
@@ -3648,7 +3649,7 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle,
goto end;
}

- rsp_count = bt_get_be16(pdata);
+ rsp_count = get_be16(pdata);
attr_list_len += rsp_count;
pdata += sizeof(uint16_t);
pdata_len -= sizeof(uint16_t);
@@ -4198,9 +4199,9 @@ int sdp_process(sdp_session_t *session)
* CSRC: Current Service Record Count (2 bytes)
*/
ssr_pdata = pdata;
- tsrc = bt_get_be16(ssr_pdata);
+ tsrc = get_be16(ssr_pdata);
ssr_pdata += sizeof(uint16_t);
- csrc = bt_get_be16(ssr_pdata);
+ csrc = get_be16(ssr_pdata);

/* csrc should never be larger than tsrc */
if (csrc > tsrc) {
@@ -4245,7 +4246,7 @@ int sdp_process(sdp_session_t *session)
break;
case SDP_SVC_ATTR_RSP:
case SDP_SVC_SEARCH_ATTR_RSP:
- rsp_count = bt_get_be16(pdata);
+ rsp_count = get_be16(pdata);
SDPDBG("Attrlist byte count : %d", rsp_count);

/* Valid range for rsp_count is 0x0002-0xFFFF */
@@ -4266,7 +4267,7 @@ int sdp_process(sdp_session_t *session)
status = 0x0000;
break;
case SDP_ERROR_RSP:
- status = bt_get_be16(pdata);
+ status = get_be16(pdata);
size = ntohs(rsphdr->plen);

goto end;
@@ -4502,7 +4503,7 @@ int sdp_service_search_attr_req(sdp_session_t *session, const sdp_list_t *search
goto end;
}

- rsp_count = bt_get_be16(pdata);
+ rsp_count = get_be16(pdata);
attr_list_len += rsp_count;
pdata += sizeof(uint16_t); /* pdata points to attribute list */
pdata_len -= sizeof(uint16_t);
diff --git a/monitor/sdp.c b/monitor/sdp.c
index dd72393..a5e8ff4 100644
--- a/monitor/sdp.c
+++ b/monitor/sdp.c
@@ -33,6 +33,8 @@

#include <bluetooth/bluetooth.h>

+#include "src/shared/util.h"
+
#include "bt.h"
#include "packet.h"
#include "display.h"
@@ -89,7 +91,7 @@ static void print_uint(uint8_t indent, const uint8_t *data, uint32_t size)
print_field("%*c0x%2.2x", indent, ' ', data[0]);
break;
case 2:
- print_field("%*c0x%4.4x", indent, ' ', bt_get_be16(data));
+ print_field("%*c0x%4.4x", indent, ' ', get_be16(data));
break;
case 4:
print_field("%*c0x%8.8x", indent, ' ', bt_get_be32(data));
@@ -114,7 +116,7 @@ static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size)
switch (size) {
case 2:
print_field("%*c%s (0x%4.4x)", indent, ' ',
- uuid16_to_str(bt_get_be16(data)), bt_get_be16(data));
+ uuid16_to_str(get_be16(data)), get_be16(data));
break;
case 4:
print_field("%*c%s (0x%8.8x)", indent, ' ',
@@ -124,13 +126,13 @@ static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size)
/* BASE_UUID = 00000000-0000-1000-8000-00805F9B34FB */
print_field("%*c%8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.4x",
indent, ' ',
- bt_get_be32(data), bt_get_be16(data + 4),
- bt_get_be16(data + 6), bt_get_be16(data + 8),
- bt_get_be16(data + 10), bt_get_be32(data + 12));
- if (bt_get_be16(data + 4) == 0x0000 &&
- bt_get_be16(data + 6) == 0x1000 &&
- bt_get_be16(data + 8) == 0x8000 &&
- bt_get_be16(data + 10) == 0x0080 &&
+ bt_get_be32(data), get_be16(data + 4),
+ get_be16(data + 6), get_be16(data + 8),
+ get_be16(data + 10), bt_get_be32(data + 12));
+ if (get_be16(data + 4) == 0x0000 &&
+ get_be16(data + 6) == 0x1000 &&
+ get_be16(data + 8) == 0x8000 &&
+ get_be16(data + 10) == 0x0080 &&
bt_get_be32(data + 12) == 0x5F9B34FB)
print_field("%*c%s", indent, ' ',
uuid32_to_str(bt_get_be32(data)));
@@ -233,7 +235,7 @@ static uint32_t get_size(const uint8_t *data, uint32_t size)
case 8:
return data[1];
case 16:
- return bt_get_be16(data + 1);
+ return get_be16(data + 1);
case 32:
return bt_get_be32(data + 1);
default:
@@ -319,7 +321,7 @@ static uint32_t get_bytes(const uint8_t *data, uint32_t size)
case 5:
return 2 + data[1];
case 6:
- return 3 + bt_get_be16(data + 1);
+ return 3 + get_be16(data + 1);
case 7:
return 5 + bt_get_be32(data + 1);
}
@@ -354,7 +356,7 @@ static void print_attr(uint32_t position, uint8_t indent, uint8_t type,
int i;

if ((position % 2) == 0) {
- uint16_t id = bt_get_be16(data);
+ uint16_t id = get_be16(data);
const char *str = "Unknown";

for (i = 0; attribute_table[i].str; i++) {
@@ -509,7 +511,7 @@ static uint16_t common_rsp(const struct l2cap_frame *frame,
return 0;
}

- bytes = bt_get_be16(frame->data);
+ bytes = get_be16(frame->data);
print_field("Attribute bytes: %d", bytes);

if (bytes > frame->size - 2) {
@@ -533,7 +535,7 @@ static void error_rsp(const struct l2cap_frame *frame, struct tid_data *tid)
return;
}

- error = bt_get_be16(frame->data);
+ error = get_be16(frame->data);

print_field("Error code: 0x%2.2x", error);
}
@@ -554,7 +556,7 @@ static void service_req(const struct l2cap_frame *frame, struct tid_data *tid)
decode_data_elements(0, 2, frame->data, search_bytes, NULL);

print_field("Max record count: %d",
- bt_get_be16(frame->data + search_bytes));
+ get_be16(frame->data + search_bytes));

print_continuation(frame->data + search_bytes + 2,
frame->size - search_bytes - 2);
@@ -573,9 +575,9 @@ static void service_rsp(const struct l2cap_frame *frame, struct tid_data *tid)
return;
}

- count = bt_get_be16(frame->data + 2);
+ count = get_be16(frame->data + 2);

- print_field("Total record count: %d", bt_get_be16(frame->data));
+ print_field("Total record count: %d", get_be16(frame->data));
print_field("Current record count: %d", count);

for (i = 0; i < count; i++)
@@ -597,7 +599,7 @@ static void attr_req(const struct l2cap_frame *frame, struct tid_data *tid)
}

print_field("Record handle: 0x%4.4x", bt_get_be32(frame->data));
- print_field("Max attribute bytes: %d", bt_get_be16(frame->data + 4));
+ print_field("Max attribute bytes: %d", get_be16(frame->data + 4));

attr_bytes = get_bytes(frame->data + 6, frame->size - 6);
print_field("Attribute list: [len %d]", attr_bytes);
@@ -643,7 +645,7 @@ static void search_attr_req(const struct l2cap_frame *frame,
decode_data_elements(0, 2, frame->data, search_bytes, NULL);

print_field("Max record count: %d",
- bt_get_be16(frame->data + search_bytes));
+ get_be16(frame->data + search_bytes));

attr_bytes = get_bytes(frame->data + search_bytes + 2,
frame->size - search_bytes - 2);
@@ -703,8 +705,8 @@ void sdp_packet(const struct l2cap_frame *frame, uint16_t channel)
}

pdu = *((uint8_t *) frame->data);
- tid = bt_get_be16(frame->data + 1);
- plen = bt_get_be16(frame->data + 3);
+ tid = get_be16(frame->data + 1);
+ plen = get_be16(frame->data + 3);

if (frame->size != plen + 5) {
print_text(COLOR_ERROR, "invalid frame size");
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index c7f2f0b..8487682 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1993,10 +1993,10 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
id = bt_get_be32(&operands[i]);
i += sizeof(uint32_t);

- charset = bt_get_be16(&operands[i]);
+ charset = get_be16(&operands[i]);
i += sizeof(uint16_t);

- len = bt_get_be16(&operands[i]);
+ len = get_be16(&operands[i]);
i += sizeof(uint16_t);

if (charset == 106) {
@@ -2128,7 +2128,7 @@ static struct media_item *parse_media_element(struct avrcp *session,

uid = bt_get_be64(&operands[0]);

- namelen = MIN(bt_get_be16(&operands[11]), sizeof(name) - 1);
+ namelen = MIN(get_be16(&operands[11]), sizeof(name) - 1);
if (namelen > 0) {
memcpy(name, &operands[13], namelen);
name[namelen] = '\0';
@@ -2165,7 +2165,7 @@ static struct media_item *parse_media_folder(struct avrcp *session,
type = operands[8];
playable = operands[9];

- namelen = MIN(bt_get_be16(&operands[12]), sizeof(name) - 1);
+ namelen = MIN(get_be16(&operands[12]), sizeof(name) - 1);
if (namelen > 0) {
memcpy(name, &operands[14], namelen);
name[namelen] = '\0';
@@ -2212,7 +2212,7 @@ static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands,
goto done;
}

- count = bt_get_be16(&operands[6]);
+ count = get_be16(&operands[6]);
if (count == 0)
goto done;

@@ -2222,7 +2222,7 @@ static gboolean avrcp_list_items_rsp(struct avctp *conn, uint8_t *operands,
uint16_t len;

type = operands[i++];
- len = bt_get_be16(&operands[i]);
+ len = get_be16(&operands[i]);
i += 2;

if (type != 0x03 && type != 0x02) {
@@ -2354,7 +2354,7 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
operand_count < 13)
return FALSE;

- player->uid_counter = bt_get_be16(&pdu->params[1]);
+ player->uid_counter = get_be16(&pdu->params[1]);
player->browsed = true;

items = bt_get_be32(&pdu->params[3]);
@@ -2680,7 +2680,7 @@ static gboolean avrcp_search_rsp(struct avctp *conn, uint8_t *operands,
goto done;
}

- player->uid_counter = bt_get_be16(&pdu->params[1]);
+ player->uid_counter = get_be16(&pdu->params[1]);
ret = bt_get_be32(&pdu->params[3]);

done:
@@ -2894,7 +2894,7 @@ avrcp_parse_media_player_item(struct avrcp *session, uint8_t *operands,
if (len < 28)
return NULL;

- id = bt_get_be16(&operands[0]);
+ id = get_be16(&operands[0]);

player = find_ct_player(session, id);
if (player == NULL) {
@@ -2922,7 +2922,7 @@ avrcp_parse_media_player_item(struct avrcp *session, uint8_t *operands,

avrcp_player_parse_features(player, &operands[8]);

- namelen = bt_get_be16(&operands[26]);
+ namelen = get_be16(&operands[26]);
if (namelen > 0 && namelen + 28 == len) {
namelen = MIN(namelen, sizeof(name) - 1);
memcpy(name, &operands[28], namelen);
@@ -2982,7 +2982,7 @@ static gboolean avrcp_get_media_player_list_rsp(struct avctp *conn,
return FALSE;

removed = g_slist_copy(session->controller->players);
- count = bt_get_be16(&operands[6]);
+ count = get_be16(&operands[6]);

for (i = 8; count && i < operand_count; count--) {
struct avrcp_player *player;
@@ -2990,7 +2990,7 @@ static gboolean avrcp_get_media_player_list_rsp(struct avctp *conn,
uint16_t len;

type = operands[i++];
- len = bt_get_be16(&operands[i]);
+ len = get_be16(&operands[i]);
i += 2;

if (type != 0x01) {
@@ -3112,7 +3112,7 @@ static void avrcp_addressed_player_changed(struct avrcp *session,
struct avrcp_header *pdu)
{
struct avrcp_player *player = session->controller->player;
- uint16_t id = bt_get_be16(&pdu->params[1]);
+ uint16_t id = get_be16(&pdu->params[1]);

if (player != NULL && player->id == id)
return;
@@ -3124,7 +3124,7 @@ static void avrcp_addressed_player_changed(struct avrcp *session,
return;
}

- player->uid_counter = bt_get_be16(&pdu->params[3]);
+ player->uid_counter = get_be16(&pdu->params[3]);
session->controller->player = player;

if (player->features != NULL)
@@ -3137,7 +3137,7 @@ static void avrcp_uids_changed(struct avrcp *session, struct avrcp_header *pdu)
{
struct avrcp_player *player = session->controller->player;

- player->uid_counter = bt_get_be16(&pdu->params[1]);
+ player->uid_counter = get_be16(&pdu->params[1]);
}

static gboolean avrcp_handle_event(struct avctp *conn,
diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index b93027a..8c95406 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -43,6 +43,7 @@
#include <glib.h>

#include "src/log.h"
+#include "src/shared/util.h"
#include "lib/uuid.h"
#include "btio/btio.h"

@@ -634,8 +635,8 @@ uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,

switch (req->uuid_size) {
case 2: /* UUID16 */
- *dst = bt_get_be16(dest);
- *src = bt_get_be16(source);
+ *dst = get_be16(dest);
+ *src = get_be16(source);
break;
case 16: /* UUID128 */
/* Check that the bytes in the UUID, except the service ID
diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index 711853f..6b27cfa 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -40,6 +40,7 @@
#include "src/log.h"
#include "src/error.h"
#include "src/dbus-common.h"
+#include "src/shared/util.h"
#include "sap.h"
#include "server.h"

@@ -312,7 +313,7 @@ static void connect_req(struct sap_server *server,

stop_guard_timer(server);

- maxmsgsize = bt_get_be16(&param->val);
+ maxmsgsize = get_be16(&param->val);

DBG("Connect MaxMsgSize: 0x%04x", maxmsgsize);

diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index fbeb488..d2ec9e1 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -37,6 +37,8 @@
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>

+#include "src/shared/util.h"
+
#include "sdpd.h"
#include "log.h"

@@ -174,7 +176,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
struct attrid *aid;
aid = malloc(sizeof(struct attrid));
aid->dtd = dataType;
- aid->uint16 = bt_get_be16(p);
+ aid->uint16 = get_be16(p);
pElem = (char *) aid;
} else {
uint16_t tmp;
@@ -392,7 +394,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- expected = bt_get_be16(pdata);
+ expected = get_be16(pdata);

SDPDBG("Expected count: %d", expected);
SDPDBG("Bytes scanned : %d", scanned);
@@ -479,7 +481,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
if (pCache) {
pCacheBuffer = pCache->data;
/* get the rsp_count from the cached buffer */
- rsp_count = bt_get_be16(pCacheBuffer);
+ rsp_count = get_be16(pCacheBuffer);

/* get index of the last sdp_record_t sent */
lastIndex = cstate->cStateValue.lastIndexSent;
@@ -656,7 +658,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- max_rsp_size = bt_get_be16(pdata);
+ max_rsp_size = get_be16(pdata);

pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
@@ -813,7 +815,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- max = bt_get_be16(pdata);
+ max = get_be16(pdata);

pdata += sizeof(uint16_t);
data_left -= sizeof(uint16_t);
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index 38bf808..06df94e 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -39,6 +39,7 @@

#include <glib.h>

+#include "src/shared/util.h"
#include "sdpd.h"
#include "log.h"

@@ -320,7 +321,7 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p,
return NULL;
}

- lookAheadAttrId = bt_get_be16(p + sizeof(uint8_t));
+ lookAheadAttrId = get_be16(p + sizeof(uint8_t));

SDPDBG("Look ahead attr id : %d", lookAheadAttrId);

@@ -365,7 +366,7 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p,
seqlen, localExtractedLength);
dtd = *(uint8_t *) p;

- attrId = bt_get_be16(p + attrSize);
+ attrId = get_be16(p + attrSize);
attrSize += sizeof(uint16_t);

SDPDBG("DTD of attrId : %d Attr id : 0x%x", dtd, attrId);
--
1.8.3.1


2014-03-20 14:42:43

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 18/62] Replace bt_put_be32() by put_be32()

---
android/avrcp-lib.c | 6 +++---
android/avrcp.c | 2 +-
lib/sdp.c | 12 ++++++------
profiles/audio/avrcp.c | 4 ++--
src/sdpd-request.c | 4 ++--
src/sdpd-service.c | 2 +-
6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 5e9bb1a..c7b8b6a 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -713,7 +713,7 @@ int avrcp_register_notification(struct avrcp *session, uint8_t event,
uint8_t params[5];

params[0] = event;
- bt_put_be32(interval, &params[1]);
+ put_be32(interval, &params[1]);

return avrcp_send_req(session, AVC_CTYPE_NOTIFY, AVC_SUBUNIT_PANEL,
AVRCP_REGISTER_NOTIFICATION,
@@ -915,8 +915,8 @@ int avrcp_get_play_status_rsp(struct avrcp *session, uint8_t transaction,
{
uint8_t pdu[9];

- bt_put_be32(position, &pdu[0]);
- bt_put_be32(duration, &pdu[4]);
+ put_be32(position, &pdu[0]);
+ put_be32(duration, &pdu[4]);
pdu[8] = status;

return avrcp_send(session, transaction, AVC_CTYPE_STABLE,
diff --git a/android/avrcp.c b/android/avrcp.c
index 046a959..45268a5 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -180,7 +180,7 @@ static size_t write_element_text(uint8_t id, uint8_t text_len, uint8_t *text,
uint16_t charset = 106;
size_t len = 0;

- bt_put_be32(id, pdu);
+ put_be32(id, pdu);
pdu += 4;
len += 4;

diff --git a/lib/sdp.c b/lib/sdp.c
index 4a1f69b..4a67a89 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -633,7 +633,7 @@ void sdp_set_seq_len(uint8_t *ptr, uint32_t length)
case SDP_ALT32:
case SDP_TEXT_STR32:
case SDP_URL_STR32:
- bt_put_be32(length, ptr);
+ put_be32(length, ptr);
break;
}
}
@@ -2860,7 +2860,7 @@ void sdp_append_to_buf(sdp_buf_t *dst, uint8_t *data, uint32_t len)
put_be16(dst->data_size - sizeof(uint8_t) - sizeof(uint16_t), p);
break;
case SDP_SEQ32:
- bt_put_be32(dst->data_size - sizeof(uint8_t) - sizeof(uint32_t), p);
+ put_be32(dst->data_size - sizeof(uint8_t) - sizeof(uint32_t), p);
break;
}
}
@@ -3040,7 +3040,7 @@ int sdp_device_record_unregister_binary(sdp_session_t *session, bdaddr_t *device

p = reqbuf + sizeof(sdp_pdu_hdr_t);
reqsize = sizeof(sdp_pdu_hdr_t);
- bt_put_be32(handle, p);
+ put_be32(handle, p);
reqsize += sizeof(uint32_t);

reqhdr->plen = htons(reqsize - sizeof(sdp_pdu_hdr_t));
@@ -3138,7 +3138,7 @@ int sdp_device_record_update(sdp_session_t *session, bdaddr_t *device, const sdp
p = reqbuf + sizeof(sdp_pdu_hdr_t);
reqsize = sizeof(sdp_pdu_hdr_t);

- bt_put_be32(handle, p);
+ put_be32(handle, p);
reqsize += sizeof(uint32_t);
p += sizeof(uint32_t);

@@ -3592,7 +3592,7 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle,
reqsize = sizeof(sdp_pdu_hdr_t);

/* add the service record handle */
- bt_put_be32(handle, pdata);
+ put_be32(handle, pdata);
reqsize += sizeof(uint32_t);
pdata += sizeof(uint32_t);

@@ -3944,7 +3944,7 @@ int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_
t->reqsize = sizeof(sdp_pdu_hdr_t);

/* add the service record handle */
- bt_put_be32(handle, pdata);
+ put_be32(handle, pdata);
t->reqsize += sizeof(uint32_t);
pdata += sizeof(uint32_t);

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 913d2be..1d439ec 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2283,8 +2283,8 @@ static void avrcp_list_items(struct avrcp *session, uint32_t start,

pdu->params[0] = player->scope;

- bt_put_be32(start, &pdu->params[1]);
- bt_put_be32(end, &pdu->params[5]);
+ put_be32(start, &pdu->params[1]);
+ put_be32(end, &pdu->params[5]);

pdu->params[9] = 1;

diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index 600237a..3e58c22 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -212,7 +212,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
memcpy(&tmp, p, sizeof(tmp));

pElem = malloc(sizeof(uint32_t));
- bt_put_be32(tmp, pElem);
+ put_be32(tmp, pElem);
}
p += sizeof(uint32_t);
seqlen += sizeof(uint32_t);
@@ -442,7 +442,7 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
if (sdp_match_uuid(pattern, rec->pattern) > 0 &&
sdp_check_access(rec->handle, &req->device)) {
rsp_count++;
- bt_put_be32(rec->handle, pdata);
+ put_be32(rec->handle, pdata);
pdata += sizeof(uint32_t);
handleSize += sizeof(uint32_t);
}
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index e001c30..a90b299 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -457,7 +457,7 @@ success:
update_db_timestamp();

/* Build a rsp buffer */
- bt_put_be32(rec->handle, rsp->data);
+ put_be32(rec->handle, rsp->data);
rsp->data_size = sizeof(uint32_t);

return 0;
--
1.8.3.1


2014-03-20 14:42:40

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 15/62] Replace bt_get_be32() by get_be32()

---
android/avrcp-lib.c | 4 ++--
android/avrcp.c | 1 +
lib/sdp.c | 10 +++++-----
monitor/sdp.c | 20 ++++++++++----------
profiles/audio/avrcp.c | 12 ++++++------
profiles/network/bnep.c | 4 ++--
src/sdpd-request.c | 4 ++--
src/sdpd-service.c | 6 +++---
8 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 06aa552..5e678ea 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -510,7 +510,7 @@ static ssize_t get_element_attributes(struct avrcp *session,
number = params[8];

for (i = 0; i < number; i++) {
- attrs[i] = bt_get_be32(&params[9 + i * 4]);
+ attrs[i] = get_be32(&params[9 + i * 4]);

if (attrs[i] == AVRCP_MEDIA_ATTRIBUTE_ILLEGAL ||
attrs[i] > AVRCP_MEDIA_ATTRIBUTE_LAST)
@@ -540,7 +540,7 @@ static ssize_t register_notification(struct avrcp *session, uint8_t transaction,
if (!player->ind || !player->ind->register_notification)
return -ENOSYS;

- interval = bt_get_be32(&params[1]);
+ interval = get_be32(&params[1]);

return player->ind->register_notification(session, transaction,
params[0], interval,
diff --git a/android/avrcp.c b/android/avrcp.c
index 7d5f53f..a435594 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -35,6 +35,7 @@
#include "lib/sdp.h"
#include "lib/sdp_lib.h"
#include "src/sdp-client.h"
+#include "src/shared/util.h"
#include "src/log.h"

#include "avctp.h"
diff --git a/lib/sdp.c b/lib/sdp.c
index fec658a..e4b0d43 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -1018,7 +1018,7 @@ int sdp_uuid_extract(const uint8_t *p, int bufsize, uuid_t *uuid, int *scanned)
SDPERR("Not enough room for 32-bit UUID");
return -1;
}
- sdp_uuid32_create(uuid, bt_get_be32(p));
+ sdp_uuid32_create(uuid, get_be32(p));
*scanned += sizeof(uint32_t);
} else {
if (bufsize < (int) sizeof(uint128_t)) {
@@ -1083,7 +1083,7 @@ static sdp_data_t *extract_int(const void *p, int bufsize, int *len)
return NULL;
}
*len += sizeof(uint32_t);
- d->val.uint32 = bt_get_be32(p);
+ d->val.uint32 = get_be32(p);
break;
case SDP_INT64:
case SDP_UINT64:
@@ -1255,7 +1255,7 @@ int sdp_extract_seqtype(const uint8_t *buf, int bufsize, uint8_t *dtdp, int *siz
SDPERR("Unexpected end of packet");
return 0;
}
- *size = bt_get_be32(buf);
+ *size = get_be32(buf);
scanned += sizeof(uint32_t);
break;
default:
@@ -2957,7 +2957,7 @@ int sdp_device_record_register_binary(sdp_session_t *session, bdaddr_t *device,
goto end;
}
if (handle)
- *handle = bt_get_be32(p);
+ *handle = get_be32(p);
}

end:
@@ -3259,7 +3259,7 @@ static void extract_record_handle_seq(uint8_t *pdu, int bufsize, sdp_list_t **se
pSvcRec = malloc(sizeof(uint32_t));
if (!pSvcRec)
break;
- *pSvcRec = bt_get_be32(pdata);
+ *pSvcRec = get_be32(pdata);
pSeq = sdp_list_append(pSeq, pSvcRec);
pdata += sizeof(uint32_t);
*scanned += sizeof(uint32_t);
diff --git a/monitor/sdp.c b/monitor/sdp.c
index a5e8ff4..d729e1f 100644
--- a/monitor/sdp.c
+++ b/monitor/sdp.c
@@ -94,7 +94,7 @@ static void print_uint(uint8_t indent, const uint8_t *data, uint32_t size)
print_field("%*c0x%4.4x", indent, ' ', get_be16(data));
break;
case 4:
- print_field("%*c0x%8.8x", indent, ' ', bt_get_be32(data));
+ print_field("%*c0x%8.8x", indent, ' ', get_be32(data));
break;
case 8:
print_field("%*c0x%16.16" PRIx64, indent, ' ',
@@ -120,22 +120,22 @@ static void print_uuid(uint8_t indent, const uint8_t *data, uint32_t size)
break;
case 4:
print_field("%*c%s (0x%8.8x)", indent, ' ',
- uuid32_to_str(bt_get_be32(data)), bt_get_be32(data));
+ uuid32_to_str(get_be32(data)), get_be32(data));
break;
case 16:
/* BASE_UUID = 00000000-0000-1000-8000-00805F9B34FB */
print_field("%*c%8.8x-%4.4x-%4.4x-%4.4x-%4.4x%8.4x",
indent, ' ',
- bt_get_be32(data), get_be16(data + 4),
+ get_be32(data), get_be16(data + 4),
get_be16(data + 6), get_be16(data + 8),
- get_be16(data + 10), bt_get_be32(data + 12));
+ get_be16(data + 10), get_be32(data + 12));
if (get_be16(data + 4) == 0x0000 &&
get_be16(data + 6) == 0x1000 &&
get_be16(data + 8) == 0x8000 &&
get_be16(data + 10) == 0x0080 &&
- bt_get_be32(data + 12) == 0x5F9B34FB)
+ get_be32(data + 12) == 0x5F9B34FB)
print_field("%*c%s", indent, ' ',
- uuid32_to_str(bt_get_be32(data)));
+ uuid32_to_str(get_be32(data)));
break;
default:
packet_hexdump(data, size);
@@ -237,7 +237,7 @@ static uint32_t get_size(const uint8_t *data, uint32_t size)
case 16:
return get_be16(data + 1);
case 32:
- return bt_get_be32(data + 1);
+ return get_be32(data + 1);
default:
return 0;
}
@@ -323,7 +323,7 @@ static uint32_t get_bytes(const uint8_t *data, uint32_t size)
case 6:
return 3 + get_be16(data + 1);
case 7:
- return 5 + bt_get_be32(data + 1);
+ return 5 + get_be32(data + 1);
}

return 0;
@@ -582,7 +582,7 @@ static void service_rsp(const struct l2cap_frame *frame, struct tid_data *tid)

for (i = 0; i < count; i++)
print_field("Record handle: 0x%4.4x",
- bt_get_be32(frame->data + 4 + (i * 4)));
+ get_be32(frame->data + 4 + (i * 4)));

print_continuation(frame->data + 4 + (count * 4),
frame->size - 4 - (count * 4));
@@ -598,7 +598,7 @@ static void attr_req(const struct l2cap_frame *frame, struct tid_data *tid)
return;
}

- print_field("Record handle: 0x%4.4x", bt_get_be32(frame->data));
+ print_field("Record handle: 0x%4.4x", get_be32(frame->data));
print_field("Max attribute bytes: %d", get_be16(frame->data + 4));

attr_bytes = get_bytes(frame->data + 6, frame->size - 6);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 8487682..6772984 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1082,7 +1082,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp *session,
for (i = 0, len = 0, attr_ids = NULL; i < nattr; i++) {
uint32_t id;

- id = bt_get_be32(&pdu->params[9] + (i * sizeof(id)));
+ id = get_be32(&pdu->params[9] + (i * sizeof(id)));

/* Don't add invalid attributes */
if (id == AVRCP_MEDIA_ATTRIBUTE_ILLEGAL ||
@@ -1990,7 +1990,7 @@ static void avrcp_parse_attribute_list(struct avrcp_player *player,
uint32_t id;
uint16_t charset, len;

- id = bt_get_be32(&operands[i]);
+ id = get_be32(&operands[i]);
i += sizeof(uint32_t);

charset = get_be16(&operands[i]);
@@ -2319,7 +2319,7 @@ static gboolean avrcp_change_path_rsp(struct avctp *conn,
goto done;
}

- ret = bt_get_be32(&pdu->params[1]);
+ ret = get_be32(&pdu->params[1]);

done:
if (ret < 0) {
@@ -2357,7 +2357,7 @@ static gboolean avrcp_set_browsed_player_rsp(struct avctp *conn,
player->uid_counter = get_be16(&pdu->params[1]);
player->browsed = true;

- items = bt_get_be32(&pdu->params[3]);
+ items = get_be32(&pdu->params[3]);

depth = pdu->params[9];

@@ -2681,7 +2681,7 @@ static gboolean avrcp_search_rsp(struct avctp *conn, uint8_t *operands,
}

player->uid_counter = get_be16(&pdu->params[1]);
- ret = bt_get_be32(&pdu->params[3]);
+ ret = get_be32(&pdu->params[3]);

done:
media_player_search_complete(mp, ret);
@@ -2908,7 +2908,7 @@ avrcp_parse_media_player_item(struct avrcp *session, uint8_t *operands,

media_player_set_type(mp, type_to_string(operands[2]));

- subtype = bt_get_be32(&operands[3]);
+ subtype = get_be32(&operands[3]);

media_player_set_subtype(mp, subtype_to_string(subtype));

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index 8c95406..87304c5 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -650,13 +650,13 @@ uint16_t bnep_setup_decode(struct bnep_setup_conn_req *req, uint16_t *dst,
/* Intentional no-break */

case 4: /* UUID32 */
- val = bt_get_be32(dest);
+ val = get_be32(dest);
if (val > 0xffff)
return BNEP_CONN_INVALID_DST;

*dst = val;

- val = bt_get_be32(source);
+ val = get_be32(source);
if (val > 0xffff)
return BNEP_CONN_INVALID_SRC;

diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index d2ec9e1..a9d92a6 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -203,7 +203,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
struct attrid *aid;
aid = malloc(sizeof(struct attrid));
aid->dtd = dataType;
- aid->uint32 = bt_get_be32(p);
+ aid->uint32 = get_be32(p);

pElem = (char *) aid;
} else {
@@ -648,7 +648,7 @@ static int service_attr_req(sdp_req_t *req, sdp_buf_t *buf)
goto done;
}

- handle = bt_get_be32(pdata);
+ handle = get_be32(pdata);

pdata += sizeof(uint32_t);
data_left -= sizeof(uint32_t);
diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index 06df94e..f763436 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -331,7 +331,7 @@ static sdp_record_t *extract_pdu_server(bdaddr_t *device, uint8_t *p,
SDPDBG("Unexpected end of packet");
return NULL;
}
- handle = bt_get_be32(p + sizeof(uint8_t) + sizeof(uint16_t) +
+ handle = get_be32(p + sizeof(uint8_t) + sizeof(uint16_t) +
sizeof(uint8_t));
SDPDBG("SvcRecHandle : 0x%x", handle);
rec = sdp_record_find(handle);
@@ -478,7 +478,7 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp)
int status = 0, scanned = 0;
uint8_t *p = req->buf + sizeof(sdp_pdu_hdr_t);
int bufsize = req->len - sizeof(sdp_pdu_hdr_t);
- uint32_t handle = bt_get_be32(p);
+ uint32_t handle = get_be32(p);

SDPDBG("Svc Rec Handle: 0x%x", handle);

@@ -517,7 +517,7 @@ done:
int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp)
{
uint8_t *p = req->buf + sizeof(sdp_pdu_hdr_t);
- uint32_t handle = bt_get_be32(p);
+ uint32_t handle = get_be32(p);
sdp_record_t *rec;
int status = 0;

--
1.8.3.1


2014-03-20 14:42:42

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 17/62] Replace bt_put_be16() by put_be16()

---
android/avrcp-lib.c | 8 ++++----
android/avrcp.c | 4 ++--
lib/sdp.c | 18 +++++++++---------
profiles/audio/avrcp.c | 12 ++++++------
profiles/sap/server.c | 2 +-
src/sdpd-request.c | 20 ++++++++++----------
src/sdpd-service.c | 6 +++---
7 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/android/avrcp-lib.c b/android/avrcp-lib.c
index 934106b..5e9bb1a 100644
--- a/android/avrcp-lib.c
+++ b/android/avrcp-lib.c
@@ -815,7 +815,7 @@ int avrcp_set_addressed_player(struct avrcp *session, uint16_t player_id,
{
uint8_t params[2];

- bt_put_be16(player_id, params);
+ put_be16(player_id, params);

return avrcp_send_req(session, AVC_CTYPE_CONTROL, AVC_SUBUNIT_PANEL,
AVRCP_SET_ADDRESSED_PLAYER, params,
@@ -881,7 +881,7 @@ int avrcp_get_player_attribute_text_rsp(struct avrcp *session,
len = strlen(text[i]);

ptr[0] = attrs[i];
- bt_put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
+ put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
ptr[3] = len;
memcpy(&ptr[4], text[i], len);
ptr += 4 + len;
@@ -945,7 +945,7 @@ int avrcp_get_player_values_text_rsp(struct avrcp *session,
len = strlen(text[i]);

ptr[0] = values[i];
- bt_put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
+ put_be16(AVRCP_CHARSET_UTF8, &ptr[1]);
ptr[3] = len;
memcpy(&ptr[4], text[i], len);
ptr += 4 + len;
@@ -1016,7 +1016,7 @@ int avrcp_send_passthrough(struct avrcp *session, uint32_t vendor, uint8_t op)
return avctp_send_passthrough(session->conn, op, NULL, 0);

hton24(params, vendor);
- bt_put_be16(op, &params[3]);
+ put_be16(op, &params[3]);

return avctp_send_passthrough(session->conn, AVC_VENDOR_UNIQUE, params,
sizeof(params));
diff --git a/android/avrcp.c b/android/avrcp.c
index a435594..046a959 100644
--- a/android/avrcp.c
+++ b/android/avrcp.c
@@ -184,11 +184,11 @@ static size_t write_element_text(uint8_t id, uint8_t text_len, uint8_t *text,
pdu += 4;
len += 4;

- bt_put_be16(charset, pdu);
+ put_be16(charset, pdu);
pdu += 2;
len += 2;

- bt_put_be16(text_len, pdu);
+ put_be16(text_len, pdu);
pdu += 2;
len += 2;

diff --git a/lib/sdp.c b/lib/sdp.c
index 9fc2b92..4a1f69b 100644
--- a/lib/sdp.c
+++ b/lib/sdp.c
@@ -627,7 +627,7 @@ void sdp_set_seq_len(uint8_t *ptr, uint32_t length)
case SDP_ALT16:
case SDP_TEXT_STR16:
case SDP_URL_STR16:
- bt_put_be16(length, ptr);
+ put_be16(length, ptr);
break;
case SDP_SEQ32:
case SDP_ALT32:
@@ -673,7 +673,7 @@ void sdp_set_attrid(sdp_buf_t *buf, uint16_t attr)
/* data type for attr */
*p++ = SDP_UINT16;
buf->data_size = sizeof(uint8_t);
- bt_put_be16(attr, p);
+ put_be16(attr, p);
buf->data_size += sizeof(uint16_t);
}

@@ -2857,7 +2857,7 @@ void sdp_append_to_buf(sdp_buf_t *dst, uint8_t *data, uint32_t len)
*(uint8_t *) p = dst->data_size - sizeof(uint8_t) - sizeof(uint8_t);
break;
case SDP_SEQ16:
- bt_put_be16(dst->data_size - sizeof(uint8_t) - sizeof(uint16_t), p);
+ put_be16(dst->data_size - sizeof(uint8_t) - sizeof(uint16_t), p);
break;
case SDP_SEQ32:
bt_put_be32(dst->data_size - sizeof(uint8_t) - sizeof(uint32_t), p);
@@ -3430,7 +3430,7 @@ int sdp_service_search_req(sdp_session_t *session, const sdp_list_t *search,
pdata += seqlen;

/* specify the maximum svc rec count that client expects */
- bt_put_be16(max_rec_num, pdata);
+ put_be16(max_rec_num, pdata);
reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);

@@ -3597,7 +3597,7 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle,
pdata += sizeof(uint32_t);

/* specify the response limit */
- bt_put_be16(65535, pdata);
+ put_be16(65535, pdata);
reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);

@@ -3851,7 +3851,7 @@ int sdp_service_search_async(sdp_session_t *session, const sdp_list_t *search, u
t->reqsize += seqlen;
pdata += seqlen;

- bt_put_be16(max_rec_num, pdata);
+ put_be16(max_rec_num, pdata);
t->reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);

@@ -3949,7 +3949,7 @@ int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_
pdata += sizeof(uint32_t);

/* specify the response limit */
- bt_put_be16(65535, pdata);
+ put_be16(65535, pdata);
t->reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);

@@ -4064,7 +4064,7 @@ int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *sear
t->reqsize += seqlen;
pdata += seqlen;

- bt_put_be16(SDP_MAX_ATTR_LEN, pdata);
+ put_be16(SDP_MAX_ATTR_LEN, pdata);
t->reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);

@@ -4444,7 +4444,7 @@ int sdp_service_search_attr_req(sdp_session_t *session, const sdp_list_t *search
reqsize += seqlen;
pdata += seqlen;

- bt_put_be16(SDP_MAX_ATTR_LEN, pdata);
+ put_be16(SDP_MAX_ATTR_LEN, pdata);
reqsize += sizeof(uint16_t);
pdata += sizeof(uint16_t);

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index ebd10a9..913d2be 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2450,7 +2450,7 @@ static void avrcp_get_item_attributes(struct avrcp *session, uint64_t uid)
pdu->pdu_id = AVRCP_GET_ITEM_ATTRIBUTES;
pdu->params[0] = 0x03;
bt_put_be64(uid, &pdu->params[1]);
- bt_put_be16(player->uid_counter, &pdu->params[9]);
+ put_be16(player->uid_counter, &pdu->params[9]);
pdu->param_len = htons(12);

avctp_send_browsing_req(session->conn, buf, sizeof(buf),
@@ -2634,7 +2634,7 @@ static void avrcp_change_path(struct avrcp *session, uint8_t direction,
struct avrcp_browsing_header *pdu = (void *) buf;

memset(buf, 0, sizeof(buf));
- bt_put_be16(player->uid_counter, &pdu->params[0]);
+ put_be16(player->uid_counter, &pdu->params[0]);
pdu->params[2] = direction;
bt_put_be64(uid, &pdu->params[3]);
pdu->pdu_id = AVRCP_CHANGE_PATH;
@@ -2700,8 +2700,8 @@ static void avrcp_search(struct avrcp *session, const char *string)
stringlen = strnlen(string, sizeof(buf) - len);
len += stringlen;

- bt_put_be16(AVRCP_CHARSET_UTF8, &pdu->params[0]);
- bt_put_be16(stringlen, &pdu->params[2]);
+ put_be16(AVRCP_CHARSET_UTF8, &pdu->params[0]);
+ put_be16(stringlen, &pdu->params[2]);
memcpy(&pdu->params[4], string, stringlen);
pdu->pdu_id = AVRCP_SEARCH;
pdu->param_len = htons(len - AVRCP_BROWSING_HEADER_LENGTH);
@@ -2739,7 +2739,7 @@ static void avrcp_play_item(struct avrcp *session, uint64_t uid)

pdu->params[0] = player->scope;
bt_put_be64(uid, &pdu->params[1]);
- bt_put_be16(player->uid_counter, &pdu->params[9]);
+ put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);

@@ -2785,7 +2785,7 @@ static void avrcp_add_to_nowplaying(struct avrcp *session, uint64_t uid)

pdu->params[0] = player->scope;
bt_put_be64(uid, &pdu->params[1]);
- bt_put_be16(player->uid_counter, &pdu->params[9]);
+ put_be16(player->uid_counter, &pdu->params[9]);

length = AVRCP_HEADER_LENGTH + ntohs(pdu->params_len);

diff --git a/profiles/sap/server.c b/profiles/sap/server.c
index 6b27cfa..20c6cab 100644
--- a/profiles/sap/server.c
+++ b/profiles/sap/server.c
@@ -668,7 +668,7 @@ int sap_connect_rsp(void *sap_device, uint8_t status)
param = (struct sap_parameter *) &buf[size];
param->id = SAP_PARAM_ID_MAX_MSG_SIZE;
param->len = htons(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);
- bt_put_be16(SAP_BUF_SIZE, &param->val);
+ put_be16(SAP_BUF_SIZE, &param->val);
size += PARAMETER_SIZE(SAP_PARAM_ID_MAX_MSG_SIZE_LEN);

/* fall */
diff --git a/src/sdpd-request.c b/src/sdpd-request.c
index a9d92a6..600237a 100644
--- a/src/sdpd-request.c
+++ b/src/sdpd-request.c
@@ -184,7 +184,7 @@ static int extract_des(uint8_t *buf, int len, sdp_list_t **svcReqSeq, uint8_t *p
memcpy(&tmp, p, sizeof(tmp));

pElem = malloc(sizeof(uint16_t));
- bt_put_be16(tmp, pElem);
+ put_be16(tmp, pElem);
}
p += sizeof(uint16_t);
seqlen += sizeof(uint16_t);
@@ -419,13 +419,13 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)

/* total service record count = 0 */
pTotalRecordCount = pdata;
- bt_put_be16(0, pdata);
+ put_be16(0, pdata);
pdata += sizeof(uint16_t);
buf->data_size += sizeof(uint16_t);

/* current service record count = 0 */
pCurrentRecordCount = pdata;
- bt_put_be16(0, pdata);
+ put_be16(0, pdata);
pdata += sizeof(uint16_t);
buf->data_size += sizeof(uint16_t);

@@ -451,8 +451,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
SDPDBG("Match count: %d", rsp_count);

buf->data_size += handleSize;
- bt_put_be16(rsp_count, pTotalRecordCount);
- bt_put_be16(rsp_count, pCurrentRecordCount);
+ put_be16(rsp_count, pTotalRecordCount);
+ put_be16(rsp_count, pCurrentRecordCount);

if (rsp_count > actual) {
/* cache the rsp and generate a continuation state */
@@ -517,8 +517,8 @@ static int service_search_req(sdp_req_t *req, sdp_buf_t *buf)
}

buf->data_size += handleSize;
- bt_put_be16(rsp_count, pTotalRecordCount);
- bt_put_be16(i - lastIndex, pCurrentRecordCount);
+ put_be16(rsp_count, pTotalRecordCount);
+ put_be16(i - lastIndex, pCurrentRecordCount);

if (i == rsp_count) {
/* set "null" continuationState */
@@ -774,7 +774,7 @@ done:
return status;

/* set attribute list byte count */
- bt_put_be16(buf->data_size - cstate_size, buf->data);
+ put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
return 0;
}
@@ -945,7 +945,7 @@ static int service_search_attr_req(sdp_req_t *req, sdp_buf_t *buf)

if (!status) {
/* set attribute list byte count */
- bt_put_be16(buf->data_size - cstate_size, buf->data);
+ put_be16(buf->data_size - cstate_size, buf->data);
buf->data_size += sizeof(uint16_t);
}

@@ -1029,7 +1029,7 @@ static void process_request(sdp_req_t *req)
send_rsp:
if (status) {
rsphdr->pdu_id = SDP_ERROR_RSP;
- bt_put_be16(status, rsp.data);
+ put_be16(status, rsp.data);
rsp.data_size = sizeof(uint16_t);
}

diff --git a/src/sdpd-service.c b/src/sdpd-service.c
index f763436..e001c30 100644
--- a/src/sdpd-service.c
+++ b/src/sdpd-service.c
@@ -463,7 +463,7 @@ success:
return 0;

invalid:
- bt_put_be16(SDP_INVALID_SYNTAX, rsp->data);
+ put_be16(SDP_INVALID_SYNTAX, rsp->data);
rsp->data_size = sizeof(uint16_t);

return -1;
@@ -506,7 +506,7 @@ int service_update_req(sdp_req_t *req, sdp_buf_t *rsp)

done:
p = rsp->data;
- bt_put_be16(status, p);
+ put_be16(status, p);
rsp->data_size = sizeof(uint16_t);
return status;
}
@@ -536,7 +536,7 @@ int service_remove_req(sdp_req_t *req, sdp_buf_t *rsp)
}

p = rsp->data;
- bt_put_be16(status, p);
+ put_be16(status, p);
rsp->data_size = sizeof(uint16_t);

return status;
--
1.8.3.1


2014-03-20 14:42:38

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 13/62] Replace bt_get_le64() by get_le64()

---
monitor/l2cap.c | 2 +-
profiles/audio/avrcp.c | 3 ++-
tools/parser/l2cap.c | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index 75363b5..993aa8b 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -932,7 +932,7 @@ static void sig_info_rsp(const struct l2cap_frame *frame)
packet_hexdump(data, size);
break;
}
- print_channels(bt_get_le64(data));
+ print_channels(get_le64(data));
break;
default:
packet_hexdump(data, size);
diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 4c5ab61..c7f2f0b 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -57,6 +57,7 @@
#include "src/error.h"
#include "src/sdpd.h"
#include "src/dbus-common.h"
+#include "src/shared/util.h"

#include "avctp.h"
#include "avrcp.h"
@@ -1055,7 +1056,7 @@ static uint8_t avrcp_handle_get_element_attributes(struct avrcp *session,
{
struct avrcp_player *player = target_get_player(session);
uint16_t len = ntohs(pdu->params_len);
- uint64_t identifier = bt_get_le64(&pdu->params[0]);
+ uint64_t identifier = get_le64(&pdu->params[0]);
uint16_t pos;
uint8_t nattr;
GList *attr_ids;
diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index f1f6a97..53dd726 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -854,7 +854,7 @@ static void info_opt(int level, int type, void *ptr, int len)
}
break;
case 0x0003:
- fc_mask = bt_get_le64(ptr);
+ fc_mask = get_le64(ptr);
printf("Fixed channel list 0x%8.8" PRIx64 "\n", fc_mask);
if (parser.flags & DUMP_VERBOSE)
for (i=0; l2cap_fix_chan[i].name; i++)
--
1.8.3.1


2014-03-20 14:42:37

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 12/62] Replace bt_get_le32() by get_le32()

---
android/android-tester.c | 3 ++-
android/bluetooth.c | 3 ++-
monitor/control.c | 2 +-
monitor/l2cap.c | 26 +++++++++++++-------------
monitor/packet.c | 16 ++++++++--------
src/adapter.c | 4 ++--
src/eir.c | 2 +-
tools/btmgmt.c | 10 +++++-----
tools/l2test.c | 2 +-
tools/mgmt-tester.c | 3 ++-
tools/parser/l2cap.c | 2 +-
11 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/android/android-tester.c b/android/android-tester.c
index bab92a1..76dd0ea 100644
--- a/android/android-tester.c
+++ b/android/android-tester.c
@@ -30,6 +30,7 @@
#include "lib/bluetooth.h"
#include "lib/mgmt.h"

+#include "src/shared/util.h"
#include "src/shared/tester.h"
#include "src/shared/mgmt.h"
#include "src/shared/hciemu.h"
@@ -281,7 +282,7 @@ static void command_generic_new_settings(uint16_t index, uint16_t length,
return;
}

- settings = bt_get_le32(param);
+ settings = get_le32(param);

if ((settings & test_data->expect_settings_set) !=
test_data->expect_settings_set)
diff --git a/android/bluetooth.c b/android/bluetooth.c
index 1becdfb..4ad8298 100644
--- a/android/bluetooth.c
+++ b/android/bluetooth.c
@@ -37,6 +37,7 @@
#include "lib/bluetooth.h"
#include "lib/sdp.h"
#include "lib/mgmt.h"
+#include "src/shared/util.h"
#include "src/shared/mgmt.h"
#include "src/uuid-helper.h"
#include "src/eir.h"
@@ -539,7 +540,7 @@ static void new_settings_callback(uint16_t index, uint16_t length,
return;
}

- settings = bt_get_le32(param);
+ settings = get_le32(param);

DBG("settings: 0x%8.8x -> 0x%8.8x", adapter.current_settings,
settings);
diff --git a/monitor/control.c b/monitor/control.c
index 6394387..8197813 100644
--- a/monitor/control.c
+++ b/monitor/control.c
@@ -121,7 +121,7 @@ static void mgmt_new_settings(uint16_t len, const void *buf)
return;
}

- settings = bt_get_le32(buf);
+ settings = get_le32(buf);

printf("@ New Settings: 0x%4.4x\n", settings);

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index 362a0b3..75363b5 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -482,15 +482,15 @@ static void print_config_options(const struct l2cap_frame *frame,
print_field(" Service type: %s (0x%2.2x)",
str, data[consumed + 3]);
print_field(" Token rate: 0x%8.8x",
- bt_get_le32(data + consumed + 4));
+ get_le32(data + consumed + 4));
print_field(" Token bucket size: 0x%8.8x",
- bt_get_le32(data + consumed + 8));
+ get_le32(data + consumed + 8));
print_field(" Peak bandwidth: 0x%8.8x",
- bt_get_le32(data + consumed + 12));
+ get_le32(data + consumed + 12));
print_field(" Latency: 0x%8.8x",
- bt_get_le32(data + consumed + 16));
+ get_le32(data + consumed + 16));
print_field(" Delay variation: 0x%8.8x",
- bt_get_le32(data + consumed + 20));
+ get_le32(data + consumed + 20));
break;
case 0x04:
if (response)
@@ -564,11 +564,11 @@ static void print_config_options(const struct l2cap_frame *frame,
print_field(" Maximum SDU size: 0x%4.4x",
get_le16(data + consumed + 4));
print_field(" SDU inter-arrival time: 0x%8.8x",
- bt_get_le32(data + consumed + 6));
+ get_le32(data + consumed + 6));
print_field(" Access latency: 0x%8.8x",
- bt_get_le32(data + consumed + 10));
+ get_le32(data + consumed + 10));
print_field(" Flush timeout: 0x%8.8x",
- bt_get_le32(data + consumed + 14));
+ get_le32(data + consumed + 14));
break;
case 0x07:
print_field(" Max window size: %d",
@@ -924,7 +924,7 @@ static void sig_info_rsp(const struct l2cap_frame *frame)
packet_hexdump(data, size);
break;
}
- print_features(bt_get_le32(data));
+ print_features(get_le32(data));
break;
case 0x0003:
if (size != 8) {
@@ -1701,16 +1701,16 @@ static void print_uuid(const char *label, const void *data, uint16_t size)
print_field("%s: %s (0x%4.4x)", label, str, get_le16(data));
break;
case 4:
- str = uuid32_to_str(bt_get_le32(data));
- print_field("%s: %s (0x%8.8x)", label, str, bt_get_le32(data));
+ str = uuid32_to_str(get_le32(data));
+ print_field("%s: %s (0x%8.8x)", label, str, get_le32(data));
break;
case 16:
str = uuid128_to_str(data);
print_field("%s: %s (%8.8x-%4.4x-%4.4x-%4.4x-%8.8x%4.4x)",
label, str,
- bt_get_le32(data + 12), get_le16(data + 10),
+ get_le32(data + 12), get_le16(data + 10),
get_le16(data + 8), get_le16(data + 6),
- bt_get_le32(data + 2), get_le16(data + 0));
+ get_le32(data + 2), get_le16(data + 0));
break;
default:
packet_hexdump(data, size);
diff --git a/monitor/packet.c b/monitor/packet.c
index 73c804a..8fec2eb 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -1917,9 +1917,9 @@ static void print_flow_spec(const char *label, const uint8_t *data)
print_field("%s flow spec: 0x%2.2x", label, data[0]);
print_field(" Service type: %s (0x%2.2x)", str, data[1]);
print_field(" Maximum SDU size: 0x%4.4x", get_le16(data + 2));
- print_field(" SDU inter-arrival time: 0x%8.8x", bt_get_le32(data + 4));
- print_field(" Access latency: 0x%8.8x", bt_get_le32(data + 8));
- print_field(" Flush timeout: 0x%8.8x", bt_get_le32(data + 12));
+ print_field(" SDU inter-arrival time: 0x%8.8x", get_le32(data + 4));
+ print_field(" Access latency: 0x%8.8x", get_le32(data + 8));
+ print_field(" Flush timeout: 0x%8.8x", get_le32(data + 12));
}

static void print_short_range_mode(uint8_t mode)
@@ -2767,9 +2767,9 @@ static void print_manufacturer_apple(const void *data, uint8_t data_len)

uuid = data + 2;
print_field(" iBeacon: %8.8x-%4.4x-%4.4x-%4.4x-%8.8x%4.4x",
- bt_get_le32(&uuid[12]), get_le16(&uuid[10]),
+ get_le32(&uuid[12]), get_le16(&uuid[10]),
get_le16(&uuid[8]), get_le16(&uuid[6]),
- bt_get_le32(&uuid[2]), get_le16(&uuid[0]));
+ get_le32(&uuid[2]), get_le16(&uuid[0]));

major = get_le16(data + 18);
minor = get_le16(data + 20);
@@ -2885,7 +2885,7 @@ static void print_uuid32_list(const char *label, const void *data,
print_field("%s: %u entr%s", label, count, count == 1 ? "y" : "ies");

for (i = 0; i < count; i++) {
- uint32_t uuid = bt_get_le32(data + (i * 4));
+ uint32_t uuid = get_le32(data + (i * 4));
print_field(" %s (0x%8.8x)", uuid32_to_str(uuid), uuid);
}
}
@@ -2902,9 +2902,9 @@ static void print_uuid128_list(const char *label, const void *data,
const uint8_t *uuid = data + (i * 16);

print_field(" %8.8x-%4.4x-%4.4x-%4.4x-%8.8x%4.4x",
- bt_get_le32(&uuid[12]), get_le16(&uuid[10]),
+ get_le32(&uuid[12]), get_le16(&uuid[10]),
get_le16(&uuid[8]), get_le16(&uuid[6]),
- bt_get_le32(&uuid[2]), get_le16(&uuid[0]));
+ get_le32(&uuid[2]), get_le16(&uuid[0]));
}
}

diff --git a/src/adapter.c b/src/adapter.c
index 56bee35..14366df 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -497,7 +497,7 @@ static void new_settings_callback(uint16_t index, uint16_t length,
return;
}

- settings = bt_get_le32(param);
+ settings = get_le32(param);

if (settings == adapter->current_settings)
return;
@@ -5025,7 +5025,7 @@ static void user_passkey_notify_callback(uint16_t index, uint16_t length,
return;
}

- passkey = bt_get_le32(&ev->passkey);
+ passkey = get_le32(&ev->passkey);

DBG("passkey %06u entered %u", passkey, ev->entered);

diff --git a/src/eir.c b/src/eir.c
index 62e91ac..db9175b 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -84,7 +84,7 @@ static void eir_parse_uuid32(struct eir_data *eir, const void *data,

service.type = SDP_UUID32;
for (i = 0; i < len / 4; i++, uuid32++) {
- service.value.uuid32 = bt_get_le32(uuid32);
+ service.value.uuid32 = get_le32(uuid32);

uuid_str = bt_uuid2string(&service);
if (!uuid_str)
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index e8552e2..adb5747 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -123,7 +123,7 @@ static void new_settings(uint16_t index, uint16_t len,

if (monitor) {
printf("hci%u new_settings: ", index);
- print_settings(bt_get_le32(ev));
+ print_settings(get_le32(ev));
printf("\n");
}
}
@@ -561,7 +561,7 @@ static void user_confirm(uint16_t index, uint16_t len, const void *param,
}

ba2str(&ev->addr.bdaddr, addr);
- val = bt_get_le32(&ev->value);
+ val = get_le32(&ev->value);

if (monitor)
printf("hci%u %s User Confirm %06u hint %u\n", index, addr,
@@ -719,10 +719,10 @@ static void info_rsp(uint8_t status, uint16_t len, const void *param,
rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);

printf("\tsupported settings: ");
- print_settings(bt_get_le32(&rp->supported_settings));
+ print_settings(get_le32(&rp->supported_settings));

printf("\n\tcurrent settings: ");
- print_settings(bt_get_le32(&rp->current_settings));
+ print_settings(get_le32(&rp->current_settings));

printf("\n\tname %s\n", rp->name);
printf("\tshort name %s\n", rp->short_name);
@@ -886,7 +886,7 @@ static void setting_rsp(uint16_t op, uint16_t id, uint8_t status, uint16_t len,
}

printf("hci%u %s complete, settings: ", id, mgmt_opstr(op));
- print_settings(bt_get_le32(rp));
+ print_settings(get_le32(rp));
printf("\n");

done:
diff --git a/tools/l2test.c b/tools/l2test.c
index 5381a50..c70bac0 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -911,7 +911,7 @@ static void recv_mode(int sk)
}

/* Check sequence */
- sq = bt_get_le32(buf);
+ sq = get_le32(buf);
if (seq != sq) {
syslog(LOG_INFO, "seq missmatch: %d -> %d", seq, sq);
seq = sq;
diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c
index a3c1c72..567efa0 100644
--- a/tools/mgmt-tester.c
+++ b/tools/mgmt-tester.c
@@ -36,6 +36,7 @@
#include "monitor/bt.h"
#include "emulator/bthost.h"

+#include "src/shared/util.h"
#include "src/shared/tester.h"
#include "src/shared/mgmt.h"
#include "src/shared/hciemu.h"
@@ -3236,7 +3237,7 @@ static void command_generic_new_settings_alt(uint16_t index, uint16_t length,
return;
}

- settings = bt_get_le32(param);
+ settings = get_le32(param);

tester_print("New settings 0x%08x received", settings);

diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index b6bb8be..f1f6a97 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -253,7 +253,7 @@ static uint32_t get_val(uint8_t *ptr, uint8_t len)
case 2:
return get_le16(ptr);
case 4:
- return bt_get_le32(ptr);
+ return get_le32(ptr);
}
return 0;
}
--
1.8.3.1


2014-03-20 14:42:36

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 11/62] Replace bt_get_le16() by get_le16()

---
monitor/l2cap.c | 68 ++++++++++++++++++++++++++--------------------------
monitor/packet.c | 38 ++++++++++++++---------------
src/eir.c | 6 ++---
tools/btmgmt.c | 22 ++++++++---------
tools/hciconfig.c | 3 ++-
tools/l2test.c | 2 +-
tools/parser/hci.c | 3 ++-
tools/parser/l2cap.c | 21 ++++++++--------
8 files changed, 83 insertions(+), 80 deletions(-)

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index 58c8c5c..362a0b3 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -457,11 +457,11 @@ static void print_config_options(const struct l2cap_frame *frame,
switch (type) {
case 0x01:
print_field(" MTU: %d",
- bt_get_le16(data + consumed + 2));
+ get_le16(data + consumed + 2));
break;
case 0x02:
print_field(" Flush timeout: %d",
- bt_get_le16(data + consumed + 2));
+ get_le16(data + consumed + 2));
break;
case 0x03:
switch (data[consumed + 3]) {
@@ -521,11 +521,11 @@ static void print_config_options(const struct l2cap_frame *frame,
print_field(" TX window size: %d", data[consumed + 3]);
print_field(" Max transmit: %d", data[consumed + 4]);
print_field(" Retransmission timeout: %d",
- bt_get_le16(data + consumed + 5));
+ get_le16(data + consumed + 5));
print_field(" Monitor timeout: %d",
- bt_get_le16(data + consumed + 7));
+ get_le16(data + consumed + 7));
print_field(" Maximum PDU size: %d",
- bt_get_le16(data + consumed + 9));
+ get_le16(data + consumed + 9));
break;
case 0x05:
switch (data[consumed + 2]) {
@@ -562,7 +562,7 @@ static void print_config_options(const struct l2cap_frame *frame,
print_field(" Service type: %s (0x%2.2x)",
str, data[consumed + 3]);
print_field(" Maximum SDU size: 0x%4.4x",
- bt_get_le16(data + consumed + 4));
+ get_le16(data + consumed + 4));
print_field(" SDU inter-arrival time: 0x%8.8x",
bt_get_le32(data + consumed + 6));
print_field(" Access latency: 0x%8.8x",
@@ -572,7 +572,7 @@ static void print_config_options(const struct l2cap_frame *frame,
break;
case 0x07:
print_field(" Max window size: %d",
- bt_get_le16(data + consumed + 2));
+ get_le16(data + consumed + 2));
break;
default:
packet_hexdump(data + consumed + 2, len);
@@ -794,7 +794,7 @@ static void sig_cmd_reject(const struct l2cap_frame *frame)
packet_hexdump(data, size);
break;
}
- print_field("MTU: %d", bt_get_le16(data));
+ print_field("MTU: %d", get_le16(data));
break;
case 0x0002:
if (size != 4) {
@@ -802,8 +802,8 @@ static void sig_cmd_reject(const struct l2cap_frame *frame)
packet_hexdump(data, size);
break;
}
- dcid = bt_get_le16(data);
- scid = bt_get_le16(data + 2);
+ dcid = get_le16(data);
+ scid = get_le16(data + 2);
print_cid("Destination", cpu_to_le16(dcid));
print_cid("Source", cpu_to_le16(scid));
break;
@@ -916,7 +916,7 @@ static void sig_info_rsp(const struct l2cap_frame *frame)
packet_hexdump(data, size);
break;
}
- print_field("MTU: %d", bt_get_le16(data));
+ print_field("MTU: %d", get_le16(data));
break;
case 0x0002:
if (size != 4) {
@@ -1604,8 +1604,8 @@ static void amp_packet(uint16_t index, bool in, uint16_t handle,
return;
}

- control = bt_get_le16(data);
- fcs = bt_get_le16(data + size - 2);
+ control = get_le16(data);
+ fcs = get_le16(data + size - 2);

print_indent(6, COLOR_CYAN, "Channel:", "", COLOR_OFF,
" %d dlen %d control 0x%4.4x fcs 0x%4.4x",
@@ -1622,7 +1622,7 @@ static void amp_packet(uint16_t index, bool in, uint16_t handle,

opcode = *((const uint8_t *) (data + 2));
ident = *((const uint8_t *) (data + 3));
- len = bt_get_le16(data + 4);
+ len = get_le16(data + 4);

if (len != size - 8) {
print_text(COLOR_ERROR, "invalid manager packet size");
@@ -1697,8 +1697,8 @@ static void print_uuid(const char *label, const void *data, uint16_t size)

switch (size) {
case 2:
- str = uuid16_to_str(bt_get_le16(data));
- print_field("%s: %s (0x%4.4x)", label, str, bt_get_le16(data));
+ str = uuid16_to_str(get_le16(data));
+ print_field("%s: %s (0x%4.4x)", label, str, get_le16(data));
break;
case 4:
str = uuid32_to_str(bt_get_le32(data));
@@ -1708,9 +1708,9 @@ static void print_uuid(const char *label, const void *data, uint16_t size)
str = uuid128_to_str(data);
print_field("%s: %s (%8.8x-%4.4x-%4.4x-%4.4x-%8.8x%4.4x)",
label, str,
- bt_get_le32(data + 12), bt_get_le16(data + 10),
- bt_get_le16(data + 8), bt_get_le16(data + 6),
- bt_get_le32(data + 2), bt_get_le16(data + 0));
+ bt_get_le32(data + 12), get_le16(data + 10),
+ get_le16(data + 8), get_le16(data + 6),
+ bt_get_le32(data + 2), get_le16(data + 0));
break;
default:
packet_hexdump(data, size);
@@ -1721,7 +1721,7 @@ static void print_uuid(const char *label, const void *data, uint16_t size)
static void print_handle_range(const char *label, const void *data)
{
print_field("%s: 0x%4.4x-0x%4.4x", label,
- bt_get_le16(data), bt_get_le16(data + 2));
+ get_le16(data), get_le16(data + 2));
}

static void print_data_list(const char *label, uint8_t length,
@@ -1737,7 +1737,7 @@ static void print_data_list(const char *label, uint8_t length,
print_field("%s: %u entr%s", label, count, count == 1 ? "y" : "ies");

while (size >= length) {
- print_field("Handle: 0x%4.4x", bt_get_le16(data));
+ print_field("Handle: 0x%4.4x", get_le16(data));
print_hex_field("Value", data + 2, length - 2);

data += length;
@@ -1772,7 +1772,7 @@ static void print_attribute_info(uint16_t type, const void *data, uint16_t len)
break;
}
print_field(" Properties: 0x%2.2x", *((uint8_t *) data));
- print_field(" Handle: 0x%2.2x", bt_get_le16(data + 1));
+ print_field(" Handle: 0x%2.2x", get_le16(data + 1));
print_uuid(" UUID", data + 3, len - 3);
break;
default:
@@ -1885,7 +1885,7 @@ static const char *att_format_str(uint8_t format)
static uint16_t print_info_data_16(const uint16_t *data, uint16_t len)
{
while (len >= 4) {
- print_field("Handle: 0x%4.4x", bt_get_le16(data));
+ print_field("Handle: 0x%4.4x", get_le16(data));
print_uuid("UUID", data + 2, 2);
data += 4;
len -= 4;
@@ -1897,7 +1897,7 @@ static uint16_t print_info_data_16(const uint16_t *data, uint16_t len)
static uint16_t print_info_data_128(const uint16_t *data, uint16_t len)
{
while (len >= 18) {
- print_field("Handle: 0x%4.4x", bt_get_le16(data));
+ print_field("Handle: 0x%4.4x", get_le16(data));
print_uuid("UUID", data + 2, 16);
data += 18;
len -= 18;
@@ -1929,7 +1929,7 @@ static void att_find_by_type_val_req(const struct l2cap_frame *frame)

print_handle_range("Handle range", frame->data);

- type = bt_get_le16(frame->data + 4);
+ type = get_le16(frame->data + 4);
print_attribute_info(type, frame->data + 6, frame->size - 6);
}

@@ -1976,8 +1976,8 @@ static void att_read_rsp(const struct l2cap_frame *frame)

static void att_read_blob_req(const struct l2cap_frame *frame)
{
- print_field("Handle: 0x%4.4x", bt_get_le16(frame->data));
- print_field("Offset: 0x%4.4x", bt_get_le16(frame->data + 2));
+ print_field("Handle: 0x%4.4x", get_le16(frame->data));
+ print_field("Offset: 0x%4.4x", get_le16(frame->data + 2));
}

static void att_read_blob_rsp(const struct l2cap_frame *frame)
@@ -1993,7 +1993,7 @@ static void att_read_multiple_req(const struct l2cap_frame *frame)

for (i = 0; i < count; i++)
print_field("Handle: 0x%4.4x",
- bt_get_le16(frame->data + (i * 2)));
+ get_le16(frame->data + (i * 2)));
}

static void att_read_group_type_req(const struct l2cap_frame *frame)
@@ -2013,7 +2013,7 @@ static void att_read_group_type_rsp(const struct l2cap_frame *frame)

static void att_write_req(const struct l2cap_frame *frame)
{
- print_field("Handle: 0x%4.4x", bt_get_le16(frame->data));
+ print_field("Handle: 0x%4.4x", get_le16(frame->data));
print_hex_field(" Data", frame->data + 2, frame->size - 2);
}

@@ -2023,15 +2023,15 @@ static void att_write_rsp(const struct l2cap_frame *frame)

static void att_prepare_write_req(const struct l2cap_frame *frame)
{
- print_field("Handle: 0x%4.4x", bt_get_le16(frame->data));
- print_field("Offset: 0x%4.4x", bt_get_le16(frame->data + 2));
+ print_field("Handle: 0x%4.4x", get_le16(frame->data));
+ print_field("Offset: 0x%4.4x", get_le16(frame->data + 2));
print_hex_field(" Data", frame->data + 4, frame->size - 4);
}

static void att_prepare_write_rsp(const struct l2cap_frame *frame)
{
- print_field("Handle: 0x%4.4x", bt_get_le16(frame->data));
- print_field("Offset: 0x%4.4x", bt_get_le16(frame->data + 2));
+ print_field("Handle: 0x%4.4x", get_le16(frame->data));
+ print_field("Offset: 0x%4.4x", get_le16(frame->data + 2));
print_hex_field(" Data", frame->data + 4, frame->size - 4);
}

@@ -2077,7 +2077,7 @@ static void att_handle_value_conf(const struct l2cap_frame *frame)

static void att_write_command(const struct l2cap_frame *frame)
{
- print_field("Handle: 0x%4.4x", bt_get_le16(frame->data));
+ print_field("Handle: 0x%4.4x", get_le16(frame->data));
print_hex_field(" Data", frame->data + 2, frame->size - 2);
}

diff --git a/monitor/packet.c b/monitor/packet.c
index 83dafe2..73c804a 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -1916,7 +1916,7 @@ static void print_flow_spec(const char *label, const uint8_t *data)

print_field("%s flow spec: 0x%2.2x", label, data[0]);
print_field(" Service type: %s (0x%2.2x)", str, data[1]);
- print_field(" Maximum SDU size: 0x%4.4x", bt_get_le16(data + 2));
+ print_field(" Maximum SDU size: 0x%4.4x", get_le16(data + 2));
print_field(" SDU inter-arrival time: 0x%8.8x", bt_get_le32(data + 4));
print_field(" Access latency: 0x%8.8x", bt_get_le32(data + 8));
print_field(" Flush timeout: 0x%8.8x", bt_get_le32(data + 12));
@@ -2767,12 +2767,12 @@ static void print_manufacturer_apple(const void *data, uint8_t data_len)

uuid = data + 2;
print_field(" iBeacon: %8.8x-%4.4x-%4.4x-%4.4x-%8.8x%4.4x",
- bt_get_le32(&uuid[12]), bt_get_le16(&uuid[10]),
- bt_get_le16(&uuid[8]), bt_get_le16(&uuid[6]),
- bt_get_le32(&uuid[2]), bt_get_le16(&uuid[0]));
+ bt_get_le32(&uuid[12]), get_le16(&uuid[10]),
+ get_le16(&uuid[8]), get_le16(&uuid[6]),
+ bt_get_le32(&uuid[2]), get_le16(&uuid[0]));

- major = bt_get_le16(data + 18);
- minor = bt_get_le16(data + 20);
+ major = get_le16(data + 18);
+ minor = get_le16(data + 20);
print_field(" Version: %u.%u", major, minor);

tx_power = *(int8_t *) (data + 22);
@@ -2786,7 +2786,7 @@ static void print_manufacturer_apple(const void *data, uint8_t data_len)

static void print_manufacturer_data(const void *data, uint8_t data_len)
{
- uint16_t company = bt_get_le16(data);
+ uint16_t company = get_le16(data);

packet_print_company("Company", company);

@@ -2810,10 +2810,10 @@ static void print_device_id(const void *data, uint8_t data_len)
if (data_len < 8)
return;

- source = bt_get_le16(data);
- vendor = bt_get_le16(data + 2);
- product = bt_get_le16(data + 4);
- version = bt_get_le16(data + 6);
+ source = get_le16(data);
+ vendor = get_le16(data + 2);
+ product = get_le16(data + 4);
+ version = get_le16(data + 6);

switch (source) {
case 0x0001:
@@ -2871,7 +2871,7 @@ static void print_uuid16_list(const char *label, const void *data,
print_field("%s: %u entr%s", label, count, count == 1 ? "y" : "ies");

for (i = 0; i < count; i++) {
- uint16_t uuid = bt_get_le16(data + (i * 2));
+ uint16_t uuid = get_le16(data + (i * 2));
print_field(" %s (0x%4.4x)", uuid16_to_str(uuid), uuid);
}
}
@@ -2902,9 +2902,9 @@ static void print_uuid128_list(const char *label, const void *data,
const uint8_t *uuid = data + (i * 16);

print_field(" %8.8x-%4.4x-%4.4x-%4.4x-%8.8x%4.4x",
- bt_get_le32(&uuid[12]), bt_get_le16(&uuid[10]),
- bt_get_le16(&uuid[8]), bt_get_le16(&uuid[6]),
- bt_get_le32(&uuid[2]), bt_get_le16(&uuid[0]));
+ bt_get_le32(&uuid[12]), get_le16(&uuid[10]),
+ get_le16(&uuid[8]), get_le16(&uuid[6]),
+ bt_get_le32(&uuid[2]), get_le16(&uuid[0]));
}
}

@@ -3074,8 +3074,8 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
if (data_len < 4)
break;
print_field("Slave Conn. Interval: 0x%4.4x - 0x%4.4x",
- bt_get_le16(&data[0]),
- bt_get_le16(&data[2]));
+ get_le16(&data[0]),
+ get_le16(&data[2]));
break;

case BT_EIR_SERVICE_UUID16:
@@ -3096,7 +3096,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
if (data_len < 2)
break;
sprintf(label, "Service Data (UUID 0x%4.4x)",
- bt_get_le16(&data[0]));
+ get_le16(&data[0]));
print_hex_field(label, &data[2], data_len - 2);
break;

@@ -3115,7 +3115,7 @@ static void print_eir(const uint8_t *eir, uint8_t eir_len, bool le)
case BT_EIR_GAP_APPEARANCE:
if (data_len < 2)
break;
- print_appearance(bt_get_le16(data));
+ print_appearance(get_le16(data));
break;

case BT_EIR_SSP_HASH_P256:
diff --git a/src/eir.c b/src/eir.c
index be83718..62e91ac 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -65,7 +65,7 @@ static void eir_parse_uuid16(struct eir_data *eir, const void *data,

service.type = SDP_UUID16;
for (i = 0; i < len / 2; i++, uuid16++) {
- service.value.uuid16 = bt_get_le16(uuid16);
+ service.value.uuid16 = get_le16(uuid16);

uuid_str = bt_uuid2string(&service);
if (!uuid_str)
@@ -216,7 +216,7 @@ void eir_parse(struct eir_data *eir, const uint8_t *eir_data, uint8_t eir_len)
case EIR_GAP_APPEARANCE:
if (data_len < 2)
break;
- eir->appearance = bt_get_le16(data);
+ eir->appearance = get_le16(data);
break;

case EIR_SSP_HASH:
@@ -252,7 +252,7 @@ int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len)
if (eir_len < EIR_OOB_MIN)
return -1;

- if (eir_len != bt_get_le16(eir_data))
+ if (eir_len != get_le16(eir_data))
return -1;

eir_data += sizeof(uint16_t);
diff --git a/tools/btmgmt.c b/tools/btmgmt.c
index 9a5e971..e8552e2 100644
--- a/tools/btmgmt.c
+++ b/tools/btmgmt.c
@@ -191,7 +191,7 @@ static void connected(uint16_t index, uint16_t len, const void *param,
return;
}

- eir_len = bt_get_le16(&ev->eir_len);
+ eir_len = get_le16(&ev->eir_len);
if (len != sizeof(*ev) + eir_len) {
fprintf(stderr, "Invalid connected event length "
"(%u bytes, eir_len %u bytes)\n", len, eir_len);
@@ -358,7 +358,7 @@ static void device_found(uint16_t index, uint16_t len, const void *param,

flags = btohl(ev->flags);

- eir_len = bt_get_le16(&ev->eir_len);
+ eir_len = get_le16(&ev->eir_len);
if (len != sizeof(*ev) + eir_len) {
fprintf(stderr, "dev_found: expected %zu bytes, got %u bytes\n",
sizeof(*ev) + eir_len, len);
@@ -615,7 +615,7 @@ static void version_rsp(uint8_t status, uint16_t len, const void *param,
}

printf("MGMT Version %u, revision %u\n", rp->version,
- bt_get_le16(&rp->revision));
+ get_le16(&rp->revision));

done:
mainloop_quit();
@@ -651,8 +651,8 @@ static void commands_rsp(uint8_t status, uint16_t len, const void *param,
goto done;
}

- num_commands = bt_get_le16(&rp->num_commands);
- num_events = bt_get_le16(&rp->num_events);
+ num_commands = get_le16(&rp->num_commands);
+ num_events = get_le16(&rp->num_events);

expected_len = sizeof(*rp) + num_commands * sizeof(uint16_t) +
num_events * sizeof(uint16_t);
@@ -667,13 +667,13 @@ static void commands_rsp(uint8_t status, uint16_t len, const void *param,

printf("%u commands:\n", num_commands);
for (i = 0; i < num_commands; i++) {
- uint16_t op = bt_get_le16(opcode++);
+ uint16_t op = get_le16(opcode++);
printf("\t%s (0x%04x)\n", mgmt_opstr(op), op);
}

printf("%u events:\n", num_events);
for (i = 0; i < num_events; i++) {
- uint16_t ev = bt_get_le16(opcode++);
+ uint16_t ev = get_le16(opcode++);
printf("\t%s (0x%04x)\n", mgmt_evstr(ev), ev);
}

@@ -715,7 +715,7 @@ static void info_rsp(uint8_t status, uint16_t len, const void *param,
ba2str(&rp->bdaddr, addr);
printf("hci%u:\taddr %s version %u manufacturer %u"
" class 0x%02x%02x%02x\n", index,
- addr, rp->version, bt_get_le16(&rp->manufacturer),
+ addr, rp->version, get_le16(&rp->manufacturer),
rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]);

printf("\tsupported settings: ");
@@ -755,7 +755,7 @@ static void index_rsp(uint8_t status, uint16_t len, const void *param,
goto done;
}

- count = bt_get_le16(&rp->num_controllers);
+ count = get_le16(&rp->num_controllers);

if (len < sizeof(*rp) + count * sizeof(uint16_t)) {
fprintf(stderr,
@@ -778,7 +778,7 @@ static void index_rsp(uint8_t status, uint16_t len, const void *param,
uint16_t index;
void *data;

- index = bt_get_le16(&rp->index[i]);
+ index = get_le16(&rp->index[i]);

if (monitor)
printf("hci%u ", index);
@@ -1188,7 +1188,7 @@ static void con_rsp(uint8_t status, uint16_t len, const void *param,
goto done;
}

- count = bt_get_le16(&rp->conn_count);
+ count = get_le16(&rp->conn_count);
if (len != sizeof(*rp) + count * sizeof(struct mgmt_addr_info)) {
fprintf(stderr, "Invalid get_connections length "
" (count=%u, len=%u)\n", count, len);
diff --git a/tools/hciconfig.c b/tools/hciconfig.c
index 548e572..765d980 100644
--- a/tools/hciconfig.c
+++ b/tools/hciconfig.c
@@ -44,6 +44,7 @@
#include <bluetooth/hci_lib.h>

#include "src/textfile.h"
+#include "src/shared/util.h"
#include "tools/csr.h"

static struct hci_dev_info di;
@@ -1316,7 +1317,7 @@ static void cmd_inq_data(int ctl, int hdev, char *opt)
printf("\t%s service classes:",
type == 0x02 ? "Shortened" : "Complete");
for (i = 0; i < (len - 1) / 2; i++) {
- uint16_t val = bt_get_le16((ptr + (i * 2)));
+ uint16_t val = get_le16((ptr + (i * 2)));
printf(" 0x%4.4x", val);
}
printf("\n");
diff --git a/tools/l2test.c b/tools/l2test.c
index a9fc642..5381a50 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -919,7 +919,7 @@ static void recv_mode(int sk)
seq++;

/* Check length */
- l = bt_get_le16(buf + 4);
+ l = get_le16(buf + 4);
if (len != l) {
syslog(LOG_INFO, "size missmatch: %d -> %d", len, l);
continue;
diff --git a/tools/parser/hci.c b/tools/parser/hci.c
index 17b776d..b018e93 100644
--- a/tools/parser/hci.c
+++ b/tools/parser/hci.c
@@ -37,6 +37,7 @@
#include "lib/hci.h"
#include "lib/hci_lib.h"
#include "lib/amp.h"
+#include "src/shared/util.h"

static uint16_t manufacturer = DEFAULT_COMPID;

@@ -792,7 +793,7 @@ static inline void ext_inquiry_data_dump(int level, struct frame *frm,
type == 0x02 ? "Shortened" : "Complete");

for (i = 0; i < len / 2; i++)
- printf(" 0x%4.4x", bt_get_le16(data + i * 2));
+ printf(" 0x%4.4x", get_le16(data + i * 2));

printf("\n");
break;
diff --git a/tools/parser/l2cap.c b/tools/parser/l2cap.c
index f0fb78b..b6bb8be 100644
--- a/tools/parser/l2cap.c
+++ b/tools/parser/l2cap.c
@@ -39,6 +39,7 @@
#include "lib/hci.h"
#include "lib/a2mp.h"
#include "lib/amp.h"
+#include "src/shared/util.h"

typedef struct {
uint16_t handle;
@@ -250,7 +251,7 @@ static uint32_t get_val(uint8_t *ptr, uint8_t len)
case 1:
return *ptr;
case 2:
- return bt_get_le16(ptr);
+ return get_le16(ptr);
case 4:
return bt_get_le32(ptr);
}
@@ -595,9 +596,9 @@ static void conf_rfc(void *ptr, int len, int in, uint16_t handle,
uint16_t rto, mto, mps;
txwin = *((uint8_t *) (ptr + 1));
maxtrans = *((uint8_t *) (ptr + 2));
- rto = bt_get_le16(ptr + 3);
- mto = bt_get_le16(ptr + 5);
- mps = bt_get_le16(ptr + 7);
+ rto = get_le16(ptr + 3);
+ mto = get_le16(ptr + 5);
+ mps = get_le16(ptr + 7);
printf(", TxWin %d, MaxTx %d, RTo %d, MTo %d, MPS %d",
txwin, maxtrans, rto, mto, mps);
}
@@ -916,7 +917,7 @@ static void l2cap_ctrl_ext_parse(int level, struct frame *frm, uint32_t ctrl)
printf(" %s", sar2str(sar));
if (sar == L2CAP_SAR_START) {
uint16_t len;
- len = bt_get_le16(frm->ptr);
+ len = get_le16(frm->ptr);
frm->ptr += L2CAP_SDULEN_SIZE;
frm->len -= L2CAP_SDULEN_SIZE;
printf(" (len %d)", len);
@@ -949,7 +950,7 @@ static void l2cap_ctrl_parse(int level, struct frame *frm, uint32_t ctrl)
printf(" %s", sar2str(sar));
if (sar == L2CAP_SAR_START) {
uint16_t len;
- len = bt_get_le16(frm->ptr);
+ len = get_le16(frm->ptr);
frm->ptr += L2CAP_SDULEN_SIZE;
frm->len -= L2CAP_SDULEN_SIZE;
printf(" (len %d)", len);
@@ -1062,7 +1063,7 @@ static inline void a2mp_discover_req(int level, struct frame *frm, uint16_t len)

do {
len -= 2;
- mask = bt_get_le16(octet);
+ mask = get_le16(octet);
printf(" 0x%4.4x", mask);

extension = octet[1] & 0x80;
@@ -1102,7 +1103,7 @@ static inline void a2mp_discover_rsp(int level, struct frame *frm, uint16_t len)

do {
len -= 2;
- mask = bt_get_le16(octet);
+ mask = get_le16(octet);
printf(" 0x%4.4x", mask);

extension = octet[1] & 0x80;
@@ -1324,7 +1325,7 @@ static void l2cap_parse(int level, struct frame *frm)
if (p_filter(FILT_L2CAP))
return;

- psm = bt_get_le16(frm->ptr);
+ psm = get_le16(frm->ptr);
frm->ptr += 2;
frm->len -= 2;

@@ -1433,7 +1434,7 @@ static void l2cap_parse(int level, struct frame *frm)
frm->ptr += 2;
frm->len -= 4;
}
- fcs = bt_get_le16(frm->ptr + frm->len);
+ fcs = get_le16(frm->ptr + frm->len);
}

if (!p_filter(FILT_L2CAP)) {
--
1.8.3.1


2014-03-20 14:42:35

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 10/62] shared: Add put_be64()

Add helper to avoid possible unaligned memory access when handling
uint64 value using big-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index baeba91..883b278 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -155,3 +155,8 @@ static inline void put_le64(uint64_t val, const void *ptr)
{
put_unaligned(cpu_to_le64(val), (uint64_t *) ptr);
}
+
+static inline void put_be64(uint64_t val, const void *ptr)
+{
+ put_unaligned(cpu_to_be64(val), (uint64_t *) ptr);
+}
--
1.8.3.1


2014-03-20 14:42:30

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 05/62] shared: Add get_be16()

Add helper to avoid possible unaligned memory access when handling
uint16 value using big-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index 29f6f6b..e315f84 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -106,6 +106,11 @@ static inline uint16_t get_le16(const void *ptr)
return le16_to_cpu(get_unaligned((const uint16_t *) ptr));
}

+static inline uint16_t get_be16(const void *ptr)
+{
+ return be16_to_cpu(get_unaligned((const uint16_t *) ptr));
+}
+
static inline uint32_t get_le32(const void *ptr)
{
return le32_to_cpu(get_unaligned((const uint32_t *) ptr));
--
1.8.3.1


2014-03-20 14:42:33

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 08/62] shared: Add put_be16()

Add helper to avoid possible unaligned memory access when handling
uint16 value using big-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index 9e4d0c0..0d0b45f 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -136,6 +136,11 @@ static inline void put_le16(uint16_t val, void *dst)
put_unaligned(cpu_to_le16(val), (uint16_t *) dst);
}

+static inline void put_be16(uint16_t val, const void *ptr)
+{
+ put_unaligned(cpu_to_be16(val), (uint16_t *) ptr);
+}
+
static inline void put_le32(uint32_t val, void *dst)
{
put_unaligned(cpu_to_le32(val), (uint32_t *) dst);
--
1.8.3.1


2014-03-20 14:42:32

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 07/62] shared: Add get_be64()

Add helper to avoid possible unaligned memory access when handling
uint64 value using big-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index 251ea2a..9e4d0c0 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -126,6 +126,11 @@ static inline uint64_t get_le64(const void *ptr)
return le64_to_cpu(get_unaligned((const uint64_t *) ptr));
}

+static inline uint64_t get_be64(const void *ptr)
+{
+ return be64_to_cpu(get_unaligned((const uint64_t *) ptr));
+}
+
static inline void put_le16(uint16_t val, void *dst)
{
put_unaligned(cpu_to_le16(val), (uint16_t *) dst);
--
1.8.3.1


2014-03-20 14:42:31

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 06/62] shared: Add get_be32()

Add helper to avoid possible unaligned memory access when handling
uint32 value using big-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index e315f84..251ea2a 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -116,6 +116,11 @@ static inline uint32_t get_le32(const void *ptr)
return le32_to_cpu(get_unaligned((const uint32_t *) ptr));
}

+static inline uint32_t get_be32(const void *ptr)
+{
+ return be32_to_cpu(get_unaligned((const uint32_t *) ptr));
+}
+
static inline uint64_t get_le64(const void *ptr)
{
return le64_to_cpu(get_unaligned((const uint64_t *) ptr));
--
1.8.3.1


2014-03-20 14:42:29

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 04/62] shared: Add get_le64()

Add helper to avoid possible unaligned memory access when handling
uint64 value using little-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index 8caee61..29f6f6b 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -111,6 +111,11 @@ static inline uint32_t get_le32(const void *ptr)
return le32_to_cpu(get_unaligned((const uint32_t *) ptr));
}

+static inline uint64_t get_le64(const void *ptr)
+{
+ return le64_to_cpu(get_unaligned((const uint64_t *) ptr));
+}
+
static inline void put_le16(uint16_t val, void *dst)
{
put_unaligned(cpu_to_le16(val), (uint16_t *) dst);
--
1.8.3.1


2014-03-20 14:42:27

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 02/62] shared: Add get_le16()

Add helper to avoid possible unaligned memory access when handling
uint16 value using little-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index a129272..ef845ae 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -101,6 +101,11 @@ static inline void bswap_128(const void *src, void *dst)
d[15 - i] = s[i];
}

+static inline uint16_t get_le16(const void *ptr)
+{
+ return le16_to_cpu(get_unaligned((const uint16_t *) ptr));
+}
+
static inline void put_le16(uint16_t val, void *dst)
{
put_unaligned(cpu_to_le16(val), (uint16_t *) dst);
--
1.8.3.1


2014-03-20 14:42:26

by Claudio Takahasi

[permalink] [raw]
Subject: [PATCH BlueZ v0 01/62] shared: Add put_le64()

Add helper to avoid possible unaligned memory access when handling
uint64 value using little-endian representation.
---
src/shared/util.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/src/shared/util.h b/src/shared/util.h
index f9170bb..a129272 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -110,3 +110,8 @@ static inline void put_le32(uint32_t val, void *dst)
{
put_unaligned(cpu_to_le32(val), (uint32_t *) dst);
}
+
+static inline void put_le64(uint64_t val, const void *ptr)
+{
+ put_unaligned(cpu_to_le64(val), (uint64_t *) ptr);
+}
--
1.8.3.1