2014-11-19 11:21:58

by Marcin Kraglak

[permalink] [raw]
Subject: [PATCH 1/2] unit/test-gatt: Create PDU macro with initial discovery

Don't duplicate PDU data used in a few gatt-client test cases.
---
unit/test-gatt.c | 146 +++++++++++++------------------------------------------
1 file changed, 34 insertions(+), 112 deletions(-)

diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 4d5d7ea..9917ec9 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -114,6 +114,36 @@ struct context {
#define define_test_client(name, function, bt_services, test_step, args...)\
define_test(name, function, CLIENT, NULL, bt_services, test_step, args)

+#define SERVICE_DATA_1_PDU \
+ raw_pdu(0x02, 0x00, 0x02), \
+ raw_pdu(0x03, 0x00, 0x02), \
+ raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28), \
+ raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),\
+ raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28), \
+ raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),\
+ raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28), \
+ raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a), \
+ raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28), \
+ raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a), \
+ raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28), \
+ raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a), \
+ raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28), \
+ raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a), \
+ raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28), \
+ raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00, \
+ 0x2a), \
+ raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28), \
+ raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a), \
+ raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00), \
+ raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29), \
+ raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28), \
+ raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29, \
+ 0x2a), \
+ raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28), \
+ raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a), \
+ raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00), \
+ raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29)
+
static bt_uuid_t uuid_16 = {
.type = BT_UUID16,
.value.u16 = 0x1800
@@ -689,133 +719,25 @@ int main(int argc, char *argv[])

define_test_client("/TP/GAR/CL/BV-01-C", test_client, service_data_1,
&test_read_1,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
- raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
- raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
- raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
- 0x2a),
- raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
- raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
- raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
- 0x2a),
- raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
- raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
- raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
+ SERVICE_DATA_1_PDU,
raw_pdu(0x0a, 0x03, 0x00),
raw_pdu(0x0b, 0x01, 0x02, 0x03));

define_test_client("/TP/GAR/CL/BI-01-C", test_client, service_data_1,
&test_read_2,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
- raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
- raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
- raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
- 0x2a),
- raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
- raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
- raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
- 0x2a),
- raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
- raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
- raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
+ SERVICE_DATA_1_PDU,
raw_pdu(0x0a, 0x00, 0x00),
raw_pdu(0x01, 0x0a, 0x00, 0x00, 0x01));

define_test_client("/TP/GAR/CL/BI-02-C", test_client, service_data_1,
&test_read_3,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
- raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
- raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
- raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
- 0x2a),
- raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
- raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
- raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
- 0x2a),
- raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
- raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
- raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
+ SERVICE_DATA_1_PDU,
raw_pdu(0x0a, 0x03, 0x00),
raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x02));

define_test_client("/TP/GAR/CL/BI-03-C", test_client, service_data_1,
&test_read_4,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
- raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
- raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
- raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
- raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
- raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
- raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
- 0x2a),
- raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
- raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
- raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
- raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
- 0x2a),
- raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
- raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
- raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
- raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
+ SERVICE_DATA_1_PDU,
raw_pdu(0x0a, 0x03, 0x00),
raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x08));

--
1.9.3



2014-11-19 16:03:49

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH 1/2] unit/test-gatt: Create PDU macro with initial discovery

Hi Marcin,

On Wed, Nov 19, 2014 at 1:21 PM, Marcin Kraglak
<[email protected]> wrote:
> Don't duplicate PDU data used in a few gatt-client test cases.
> ---
> unit/test-gatt.c | 146 +++++++++++++------------------------------------------
> 1 file changed, 34 insertions(+), 112 deletions(-)
>
> diff --git a/unit/test-gatt.c b/unit/test-gatt.c
> index 4d5d7ea..9917ec9 100644
> --- a/unit/test-gatt.c
> +++ b/unit/test-gatt.c
> @@ -114,6 +114,36 @@ struct context {
> #define define_test_client(name, function, bt_services, test_step, args...)\
> define_test(name, function, CLIENT, NULL, bt_services, test_step, args)
>
> +#define SERVICE_DATA_1_PDU \
> + raw_pdu(0x02, 0x00, 0x02), \
> + raw_pdu(0x03, 0x00, 0x02), \
> + raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28), \
> + raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),\
> + raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28), \
> + raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),\
> + raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28), \
> + raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a), \
> + raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28), \
> + raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a), \
> + raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28), \
> + raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a), \
> + raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28), \
> + raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a), \
> + raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28), \
> + raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00, \
> + 0x2a), \
> + raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28), \
> + raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a), \
> + raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00), \
> + raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29), \
> + raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28), \
> + raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29, \
> + 0x2a), \
> + raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28), \
> + raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a), \
> + raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00), \
> + raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29)
> +
> static bt_uuid_t uuid_16 = {
> .type = BT_UUID16,
> .value.u16 = 0x1800
> @@ -689,133 +719,25 @@ int main(int argc, char *argv[])
>
> define_test_client("/TP/GAR/CL/BV-01-C", test_client, service_data_1,
> &test_read_1,
> - raw_pdu(0x02, 0x00, 0x02),
> - raw_pdu(0x03, 0x00, 0x02),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
> - raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
> - raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
> - raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
> - 0x2a),
> - raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
> - raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
> - raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
> - 0x2a),
> - raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
> - raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
> - raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
> + SERVICE_DATA_1_PDU,
> raw_pdu(0x0a, 0x03, 0x00),
> raw_pdu(0x0b, 0x01, 0x02, 0x03));
>
> define_test_client("/TP/GAR/CL/BI-01-C", test_client, service_data_1,
> &test_read_2,
> - raw_pdu(0x02, 0x00, 0x02),
> - raw_pdu(0x03, 0x00, 0x02),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
> - raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
> - raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
> - raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
> - 0x2a),
> - raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
> - raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
> - raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
> - 0x2a),
> - raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
> - raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
> - raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
> + SERVICE_DATA_1_PDU,
> raw_pdu(0x0a, 0x00, 0x00),
> raw_pdu(0x01, 0x0a, 0x00, 0x00, 0x01));
>
> define_test_client("/TP/GAR/CL/BI-02-C", test_client, service_data_1,
> &test_read_3,
> - raw_pdu(0x02, 0x00, 0x02),
> - raw_pdu(0x03, 0x00, 0x02),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
> - raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
> - raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
> - raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
> - 0x2a),
> - raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
> - raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
> - raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
> - 0x2a),
> - raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
> - raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
> - raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
> + SERVICE_DATA_1_PDU,
> raw_pdu(0x0a, 0x03, 0x00),
> raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x02));
>
> define_test_client("/TP/GAR/CL/BI-03-C", test_client, service_data_1,
> &test_read_4,
> - raw_pdu(0x02, 0x00, 0x02),
> - raw_pdu(0x03, 0x00, 0x02),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18),
> - raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x11, 0x06, 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
> - raw_pdu(0x10, 0x09, 0x00, 0xff, 0xff, 0x00, 0x28),
> - raw_pdu(0x01, 0x10, 0x09, 0x00, 0x0a),
> - raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
> - raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x02, 0x28),
> - raw_pdu(0x01, 0x08, 0x05, 0x00, 0x0a),
> - raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x02, 0x00, 0x02, 0x03, 0x00, 0x00,
> - 0x2a),
> - raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
> - raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
> - raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
> - raw_pdu(0x08, 0x05, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x09, 0x07, 0x06, 0x00, 0x02, 0x07, 0x00, 0x29,
> - 0x2a),
> - raw_pdu(0x08, 0x07, 0x00, 0x08, 0x00, 0x03, 0x28),
> - raw_pdu(0x01, 0x08, 0x07, 0x00, 0x0a),
> - raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00),
> - raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29),
> + SERVICE_DATA_1_PDU,
> raw_pdu(0x0a, 0x03, 0x00),
> raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x08));
>
> --
> 1.9.3

Applied, thanks.


--
Luiz Augusto von Dentz

2014-11-19 11:21:59

by Marcin Kraglak

[permalink] [raw]
Subject: [PATCH 2/2] shared/gatt-helpers: Simplify appending gatt_results

Don't duplicate appending gatt_results.
---
src/shared/gatt-helpers.c | 91 ++++++++++++++++-------------------------------
1 file changed, 30 insertions(+), 61 deletions(-)

diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index 9c8a3ba..97e62fe 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -221,6 +221,27 @@ struct discovery_op {
bt_gatt_destroy_func_t destroy;
};

+static struct bt_gatt_result *result_append(uint8_t opcode, const void *pdu,
+ uint16_t pdu_len,
+ uint16_t data_len,
+ struct discovery_op *op)
+{
+ struct bt_gatt_result *result;
+
+ result = result_create(opcode, pdu, pdu_len, data_len, op);
+ if (!result)
+ return NULL;
+
+ if (!op->result_head)
+ op->result_head = op->result_tail = result;
+ else {
+ op->result_tail->next = result;
+ op->result_tail = result;
+ }
+
+ return result;
+}
+
bool bt_gatt_iter_next_included_service(struct bt_gatt_iter *iter,
uint16_t *handle, uint16_t *start_handle,
uint16_t *end_handle, uint8_t uuid[16])
@@ -594,20 +615,13 @@ static void read_by_grp_type_cb(uint8_t opcode, const void *pdu,
/* PDU is correctly formatted. Get the last end handle to process the
* next request and store the PDU.
*/
- cur_result = result_create(opcode, pdu + 1, list_length,
- data_length, op);
+ cur_result = result_append(opcode, pdu + 1, list_length, data_length,
+ op);
if (!cur_result) {
success = false;
goto done;
}

- if (!op->result_head)
- op->result_head = op->result_tail = cur_result;
- else {
- op->result_tail->next = cur_result;
- op->result_tail = cur_result;
- }
-
last_end = get_le16(pdu + length - data_length + 2);
if (last_end < op->end_handle) {
uint8_t pdu[6];
@@ -654,7 +668,6 @@ static void find_by_type_val_cb(uint8_t opcode, const void *pdu,
bool success;
uint8_t att_ecode = 0;
struct bt_gatt_result *final_result = NULL;
- struct bt_gatt_result *cur_result;
uint16_t last_end;

if (opcode == BT_ATT_OP_ERROR_RSP) {
@@ -677,19 +690,11 @@ static void find_by_type_val_cb(uint8_t opcode, const void *pdu,
goto done;
}

- cur_result = result_create(opcode, pdu, length, 4, op);
- if (!cur_result) {
+ if (!result_append(opcode, pdu, length, 4, op)) {
success = false;
goto done;
}

- if (!op->result_head)
- op->result_head = op->result_tail = cur_result;
- else {
- op->result_tail->next = cur_result;
- op->result_tail = cur_result;
- }
-
/*
* Each data set contains:
* 2 octets with start handle
@@ -873,7 +878,6 @@ static void read_included_cb(uint8_t opcode, const void *pdu,
struct read_incl_data *data = user_data;
struct bt_gatt_result *final_result = NULL;
struct discovery_op *op = data->op;
- struct bt_gatt_result *cur_result;
uint8_t att_ecode = 0;
uint8_t read_pdu[2];
bool success;
@@ -898,19 +902,11 @@ static void read_included_cb(uint8_t opcode, const void *pdu,
goto done;
}

- cur_result = result_create(opcode, pdu, length, length, op);
- if (!cur_result) {
+ if (!result_append(opcode, pdu, length, length, op)) {
success = false;
goto done;
}

- if (!op->result_head) {
- op->result_head = op->result_tail = cur_result;
- } else {
- op->result_tail->next = cur_result;
- op->result_tail = cur_result;
- }
-
if (data->pos == data->result->pdu_len) {
uint16_t last_handle;
uint8_t pdu[6];
@@ -1019,20 +1015,13 @@ static void discover_included_cb(uint8_t opcode, const void *pdu,
goto failed;
}

- cur_result = result_create(opcode, pdu + 1, length - 1,
- data_length, op);
+ cur_result = result_append(opcode, pdu + 1, length - 1, data_length,
+ op);
if (!cur_result) {
success = false;
goto failed;
}

- if (!op->result_head) {
- op->result_head = op->result_tail = cur_result;
- } else {
- op->result_tail->next = cur_result;
- op->result_tail = cur_result;
- }
-
if (data_length == 6) {
struct read_incl_data *data;

@@ -1120,7 +1109,6 @@ static void discover_chrcs_cb(uint8_t opcode, const void *pdu,
bool success;
uint8_t att_ecode = 0;
struct bt_gatt_result *final_result = NULL;
- struct bt_gatt_result *cur_result;
size_t data_length;
uint16_t last_handle;

@@ -1156,20 +1144,11 @@ static void discover_chrcs_cb(uint8_t opcode, const void *pdu,
goto done;
}

- cur_result = result_create(opcode, pdu + 1, length - 1,
- data_length, op);
- if (!cur_result) {
+ if (!result_append(opcode, pdu + 1, length - 1,
+ data_length, op)) {
success = false;
goto done;
}
-
- if (!op->result_head)
- op->result_head = op->result_tail = cur_result;
- else {
- op->result_tail->next = cur_result;
- op->result_tail = cur_result;
- }
-
last_handle = get_le16(pdu + length - data_length);
if (last_handle != op->end_handle) {
uint8_t pdu[6];
@@ -1245,7 +1224,6 @@ static void discover_descs_cb(uint8_t opcode, const void *pdu,
bool success;
uint8_t att_ecode = 0;
struct bt_gatt_result *final_result = NULL;
- struct bt_gatt_result *cur_result;
uint8_t format;
uint16_t last_handle;
size_t data_length;
@@ -1288,20 +1266,11 @@ static void discover_descs_cb(uint8_t opcode, const void *pdu,
goto done;
}

- cur_result = result_create(opcode, pdu + 1, length - 1,
- data_length, op);
- if (!cur_result) {
+ if (!result_append(opcode, pdu + 1, length - 1, data_length, op)) {
success = false;
goto done;
}

- if (!op->result_head)
- op->result_head = op->result_tail = cur_result;
- else {
- op->result_tail->next = cur_result;
- op->result_tail = cur_result;
- }
-
last_handle = get_le16(pdu + length - data_length);
if (last_handle != op->end_handle) {
uint8_t pdu[4];
--
1.9.3