This patch set's main goal is to add the small source database as defined
by page 24 of the GATT Test Spec.
It also adds improvements to bt_string_to_uuid to ease defined service UUID
strings, and some minor simplification of the existing test data.
Finally it allows the test database used by the IUT to be switched.
Michael Janssen (5):
lib/uuid: Simplify BT base UUIDs when possible
unit/gatt: Define repeated MTU PDUs.
unit/gatt: Use source db for server_tests
unit/gatt: Add test spec "small test database"
unit/gatt: minor fix for test PDUs
lib/uuid.c | 4 +
unit/test-gatt.c | 278 +++++++++++++++++++++++++++++++++++++------------------
unit/test-uuid.c | 22 ++++-
3 files changed, 212 insertions(+), 92 deletions(-)
--
2.2.0.rc0.207.ga3a616c
Hi Michael,
On Tue, Dec 9, 2014 at 2:05 AM, Michael Janssen <[email protected]> wrote:
> When converting a UUID from string to bt_uuid_t, prefer using
> the 16-bit version when possible, which should generate shorter
> sequences by increasing the number of 16-bit types.
> ---
> lib/uuid.c | 4 ++++
> unit/test-uuid.c | 22 +++++++++++++++++++---
> 2 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/lib/uuid.c b/lib/uuid.c
> index 5c3f986..d110b5e 100644
> --- a/lib/uuid.c
> +++ b/lib/uuid.c
> @@ -238,6 +238,10 @@ static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string)
> &data3, &data4, &data5) != 6)
> return -EINVAL;
>
> + if (data0 <= 0xFFFF && data1 == 0x0000 && data2 == 0x1000 &&
> + data3 == 0x8000 && data4 == 0x0805f9bL && data5 == 0x34fb)
> + return bt_uuid16_create(uuid, data0 & 0xFFFF);
> +
> data0 = htonl(data0);
> data1 = htons(data1);
> data2 = htons(data2);
> diff --git a/unit/test-uuid.c b/unit/test-uuid.c
> index 6c7e9d0..8647af9 100644
> --- a/unit/test-uuid.c
> +++ b/unit/test-uuid.c
> @@ -46,9 +46,9 @@ 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",
> - .binary = uuid_base_binary,
> - .type = BT_UUID128,
> + .str = "0000",
> + .val16 = 0x0000,
> + .type = BT_UUID16,
> .str128 = "00000000-0000-1000-8000-00805f9b34fb",
> .binary128 = uuid_base_binary,
> };
> @@ -93,6 +93,18 @@ static struct uuid_test_data uuid_32_2 = {
> .binary128 = uuid_32_binary,
> };
>
> +static unsigned char uuid_128_binary[] = {
> + 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
> + 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb };
> +
> +static struct uuid_test_data uuid_128 = {
> + .str = "F0000000-0000-1000-8000-00805f9b34fb",
> + .binary = uuid_128_binary,
> + .type = BT_UUID128,
> + .str128 = "F0000000-0000-1000-8000-00805f9b34fb",
> + .binary128 = uuid_128_binary,
> +};
> +
> static void test_uuid(gconstpointer data)
> {
> const struct uuid_test_data *test_data = data;
> @@ -216,6 +228,10 @@ int main(int argc, char *argv[])
> g_test_add_data_func("/uuid/thritytwo2/str", &uuid_32_2, test_str);
> g_test_add_data_func("/uuid/thirtytwo2/cmp", &uuid_32_2, test_cmp);
>
> + g_test_add_data_func("/uuid/onetwentyeight", &uuid_128, test_uuid);
> + g_test_add_data_func("/uuid/onetwentyeight/str", &uuid_128, test_str);
> + g_test_add_data_func("/uuid/onetwentyeight/cmp", &uuid_128, test_cmp);
> +
> for (i = 0; malformed[i]; i++) {
> char *testpath;
>
> --
> 2.2.0.rc0.207.ga3a616c
I have skip this one since it perhaps better to call it
bt_string_to_uuid if in fact this could end up as uuid16, but then
apparently it does not pass the unit tests:
bt_gatt_server:Read By Grp Type - start: 0x0001 end: 0xffff
GATT: > 11 14 10 f0 15 f0 fb 34 9b 5f 80 00 00 80 00 10 .......4._......
GATT: 00 00 00 18 00 00 ......
**
ERROR:unit/test-gatt.c:268:test_handler: assertion failed (len ==
pdu->size): (22 == 14)
(MSG: ERROR:unit/test-gatt.c:268:test_handler: assertion failed (len
== pdu->size): (22 == 14))
--
Luiz Augusto von Dentz
This patch adds the first of a set of databases which are specified by
the Bluetooth GATT Test Specification document.
It is specifically the "small test database" constructed carefully to
fit the first requirement.
It satisfies the following requirements in section 3.3.2 of the GATT TS:
1. One small test database whose services fit into a single minimum
sized PDU, with only 16-biy UUIDs
3. At least one of those has a Primary Service at the MAX handle
8. All have some services that are simple, and some that include other
services
9. Each has at last one instance where the handle of an included service
is before the handle of the including service
11. Each has instances of simple characteristics (no descriptors) and
complex characteristics (multiple descriptors)
12. Each has instances of complex characteristics with 16-bit and
128-bit characteristic descriptor UUIDs, and these are in no
particular order.
---
unit/test-gatt.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 146 insertions(+), 1 deletion(-)
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 0b190b2..d131f0f 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -147,6 +147,17 @@ struct context {
raw_pdu(0x04, 0x08, 0x00, 0x08, 0x00), \
raw_pdu(0x05, 0x01, 0x08, 0x00, 0x01, 0x29)
+#define PRIMARY_DISC_SMALL_DB \
+ raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28), \
+ raw_pdu(0x11, 0x06, 0x10, 0xF0, 0x15, 0xF0, 0x00, 0x18, \
+ 0xFF, 0xFF, 0xFF, 0xFF, 0x0a, 0x18)
+
+#define SECONDARY_DISC_SMALL_DB \
+ raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28), \
+ raw_pdu(0x11, 0x06, 0x01, 0x00, 0x0F, 0x00, 0x0a, 0x18),\
+ raw_pdu(0x10, 0x10, 0x00, 0xff, 0xff, 0x01, 0x28), \
+ raw_pdu(0x01, 0x10, 0x10, 0x00, 0x0a)
+
#define SERVER_MTU_EXCHANGE_PDU raw_pdu(0x02, 0x17, 0x00)
static bt_uuid_t uuid_16 = {
@@ -647,6 +658,28 @@ static struct gatt_db_attribute *add_char_with_value(struct gatt_db *db,
return attrib;
}
+static struct gatt_db_attribute *add_ccc(struct gatt_db_attribute *chrc_att,
+ bool writable)
+{
+ struct gatt_db_attribute *desc_att;
+ bt_uuid_t uuid;
+ uint32_t permissions = BT_ATT_PERM_READ;
+ uint16_t tmp;
+
+ if (writable)
+ permissions |= BT_ATT_PERM_WRITE;
+
+ bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
+ desc_att = gatt_db_service_add_descriptor(chrc_att, &uuid, permissions,
+ NULL, NULL, NULL);
+
+ tmp = 0x0000;
+ gatt_db_attribute_write(desc_att, 0, (uint8_t *)&tmp, sizeof(uint16_t),
+ 0x00, NULL, att_write_cb, NULL);
+
+ return desc_att;
+}
+
static struct gatt_db_attribute *
add_user_description(struct gatt_db_attribute *chrc_att, const char *desc,
bool writable)
@@ -674,6 +707,34 @@ typedef struct gatt_db_attribute (*add_service_func) (struct gatt_db *db,
bool primary,
uint16_t extra_handles);
+static struct gatt_db_attribute *
+add_device_information_service(struct gatt_db *db, uint16_t handle,
+ bool primary, uint16_t extra_handles)
+{
+ bt_uuid_t uuid;
+ struct gatt_db_attribute *serv_att;
+
+ bt_string_to_uuid(&uuid, DEVICE_INFORMATION_UUID);
+ serv_att = gatt_db_insert_service(db, handle, &uuid, primary,
+ 1 + extra_handles);
+
+ return serv_att;
+}
+
+static struct gatt_db_attribute *add_gap(struct gatt_db *db, uint16_t handle,
+ bool primary,
+ uint16_t extra_handles)
+{
+ bt_uuid_t uuid;
+ struct gatt_db_attribute *serv_att;
+
+ bt_string_to_uuid(&uuid, GAP_UUID);
+ serv_att = gatt_db_insert_service(db, handle, &uuid, primary,
+ 1 + extra_handles);
+
+ return serv_att;
+}
+
static struct gatt_db *make_service_data_1_db(void)
{
struct gatt_db *db = gatt_db_new();
@@ -707,6 +768,79 @@ static struct gatt_db *make_service_data_1_db(void)
return db;
}
+/*
+ * Defined Test database 1:
+ * Tiny database fits into a single minimum sized-pdu.
+ * Satisfies:
+ * 3. At least one primary seervice at the MAX handle
+ * For each / all databases:
+ * X 7. at least one service uuid with multiple instances
+ * X 8. Some simple services, some with included services
+ * X 9. an instance where handle of included service comes before the including
+ * service
+ * X 11. Simple characteristics (no desc) and complex characteristics
+ * (multiple descriptors)
+ * X 12. Instances of complex chars with 16-bit and 128-bit uuids
+ * (although not in scrambled order)
+ */
+
+static struct gatt_db *make_test_spec_small_db(void)
+{
+ struct gatt_db *db;
+ struct gatt_db_attribute *serv_att, *dis_att;
+ bt_uuid_t uuid;
+ const char *manuf_device_string = "BlueZ";
+ const char *device_name_string = "BlueZ Unit Tester";
+ const char *user_desc_manuf_name = "Manufacturer Name";
+ uint16_t u16_value;
+ uint8_t u8_value;
+
+ db = gatt_db_new();
+
+ dis_att = add_device_information_service(db, 0x0001, false, 15);
+
+ bt_uuid16_create(&uuid, GATT_CHARAC_MANUFACTURER_NAME_STRING);
+ add_char_with_value(db, dis_att, &uuid, BT_ATT_PERM_READ,
+ BT_GATT_CHRC_PROP_READ,
+ manuf_device_string,
+ strlen(manuf_device_string));
+ add_ccc(dis_att, false);
+ add_user_description(dis_att, user_desc_manuf_name, false);
+
+ gatt_db_service_set_active(dis_att, true);
+
+ serv_att = add_gap(db, 0xF010, true, 5);
+
+ gatt_db_service_add_included(serv_att, dis_att);
+
+ bt_uuid16_create(&uuid, GATT_CHARAC_DEVICE_NAME);
+ add_char_with_value(db, serv_att, &uuid, BT_ATT_PERM_READ,
+ BT_GATT_CHRC_PROP_READ,
+ device_name_string,
+ strlen(device_name_string));
+
+ bt_string_to_uuid(&uuid, "0000B009-0000-0000-0123-456789abcdef");
+ u8_value = 0x09;
+ add_char_with_value(db, serv_att, &uuid, BT_ATT_PERM_READ,
+ BT_GATT_CHRC_PROP_READ,
+ &u8_value, sizeof(uint8_t));
+
+ gatt_db_service_set_active(serv_att, true);
+
+ u16_value = 0x0000; /* "Unknown" Appearance */
+ bt_uuid16_create(&uuid, GATT_CHARAC_APPEARANCE);
+ add_char_with_value(db, serv_att, &uuid, BT_ATT_PERM_READ,
+ BT_GATT_CHRC_PROP_READ, &u16_value,
+ sizeof(uint16_t));
+
+
+ serv_att = add_device_information_service(db, 0xFFFF, true, 0);
+
+ gatt_db_service_set_active(serv_att, true);
+
+ return db;
+}
+
static void test_client(gconstpointer data)
{
struct context *context = create_context(512, data);
@@ -928,11 +1062,12 @@ static void test_read_by_type(gconstpointer data)
int main(int argc, char *argv[])
{
- struct gatt_db *service_db_1;
+ struct gatt_db *service_db_1, *ts_small_db;
g_test_init(&argc, &argv, NULL);
service_db_1 = make_service_data_1_db();
+ ts_small_db = make_test_spec_small_db();
/*
* Server Configuration
@@ -969,6 +1104,11 @@ int main(int argc, char *argv[])
raw_pdu(0x10, 0x97, 0x00, 0xff, 0xff, 0x00, 0x28),
raw_pdu(0x01, 0x10, 0x97, 0x00, 0x0a));
+ define_test_att("/TP/GAD/CL/BV-01-C-small", test_search_primary, NULL,
+ NULL,
+ MTU_EXCHANGE_CLIENT_PDUS,
+ PRIMARY_DISC_SMALL_DB);
+
define_test_server("/TP/GAD/SR/BV-01-C", test_server, service_db_1,
NULL,
raw_pdu(0x03, 0x00, 0x02),
@@ -978,6 +1118,11 @@ int main(int argc, char *argv[])
raw_pdu(0x10, 0x06, 0x00, 0xff, 0xff, 0x00, 0x28),
raw_pdu(0x01, 0x10, 0x06, 0x00, 0x0a));
+ define_test_server("/TP/GAD/SR/BV-01-C-small", test_server, ts_small_db,
+ NULL,
+ raw_pdu(0x03, 0x00, 0x02),
+ PRIMARY_DISC_SMALL_DB);
+
define_test_att("/TP/GAD/CL/BV-02-C-1", test_search_primary, &uuid_16,
NULL,
MTU_EXCHANGE_CLIENT_PDUS,
--
2.2.0.rc0.207.ga3a616c
The MTU PDUs are repeated many times in the code, add a define for them.
Also use "PDUS" instead of "PDU" because these macros contain multiples.
---
unit/test-gatt.c | 57 +++++++++++++++++++++++++-------------------------------
1 file changed, 25 insertions(+), 32 deletions(-)
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 3ce3d80..78e47df 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -114,9 +114,12 @@ struct context {
#define define_test_server(name, function, source_db, test_step, args...)\
define_test(name, function, SERVER, NULL, source_db, test_step, args)
-#define SERVICE_DATA_1_PDU \
+#define MTU_EXCHANGE_CLIENT_PDUS \
raw_pdu(0x02, 0x00, 0x02), \
- raw_pdu(0x03, 0x00, 0x02), \
+ raw_pdu(0x03, 0x00, 0x02)
+
+#define SERVICE_DATA_1_PDUS \
+ MTU_EXCHANGE_CLIENT_PDUS, \
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), \
@@ -1015,8 +1018,7 @@ int main(int argc, char *argv[])
define_test_att("/TP/GAD/CL/BV-02-C-1", test_search_primary, &uuid_16,
NULL,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x06, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28, 0x00,
0x18),
raw_pdu(0x07, 0x01, 0x00, 0x07, 0x00),
@@ -1026,8 +1028,7 @@ int main(int argc, char *argv[])
define_test_att("/TP/GAD/CL/BV-02-C-2", test_search_primary, &uuid_128,
NULL,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(06, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28, 0xfb,
0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00,
0x80, 0x00, 0x10, 0x00, 0x00, 0x0d,
@@ -1041,8 +1042,7 @@ int main(int argc, char *argv[])
define_test_att("/TP/GAD/CL/BV-03-C", test_search_included, NULL,
NULL,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x02, 0x28),
raw_pdu(0x09, 0x08, 0x02, 0x00, 0x10, 0x00, 0x1f, 0x00,
0x0f, 0x18),
@@ -1065,8 +1065,7 @@ int main(int argc, char *argv[])
define_test_att("/TP/GAD/CL/BV-04-C", test_search_chars, NULL,
NULL,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x08, 0x10, 0x00, 0x20, 0x00, 0x03, 0x28),
raw_pdu(0x09, 0x07, 0x11, 0x00, 02, 0x12, 0x00, 0x25,
0x2a),
@@ -1079,8 +1078,7 @@ int main(int argc, char *argv[])
raw_pdu(0x01, 0x08, 0x12, 0x00, 0x0a));
define_test_att("/TP/GAD/CL/BV-06-C", test_search_descs, NULL, NULL,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x04, 0x13, 0x00, 0x16, 0x00),
raw_pdu(0x05, 0x01, 0x13, 0x00, 0x02, 0x29, 0x14, 0x00,
0x03, 0x29),
@@ -1090,25 +1088,25 @@ int main(int argc, char *argv[])
define_test_client("/TP/GAR/CL/BV-01-C", test_client, service_db_1,
&test_read_1,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0a, 0x03, 0x00),
raw_pdu(0x0b, 0x01, 0x02, 0x03));
define_test_client("/TP/GAR/CL/BI-01-C", test_client, service_db_1,
&test_read_2,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0a, 0x00, 0x00),
raw_pdu(0x01, 0x0a, 0x00, 0x00, 0x01));
define_test_client("/TP/GAR/CL/BI-02-C", test_client, service_db_1,
&test_read_3,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0a, 0x03, 0x00),
raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x02));
define_test_client("/TP/GAR/CL/BI-03-C", test_client, service_db_1,
&test_read_4,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0a, 0x03, 0x00),
raw_pdu(0x01, 0x0a, 0x03, 0x00, 0x08));
@@ -1138,72 +1136,67 @@ int main(int argc, char *argv[])
define_test_att("/TP/GAR/CL/BI-06-C", test_read_by_type, &uuid_char_16,
&test_read_by_type_2,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
raw_pdu(0x01, 0x08, 0x0b, 0x00, 0x02));
define_test_att("/TP/GAR/CL/BI-07-C", test_read_by_type, &uuid_char_16,
&test_read_by_type_3,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
raw_pdu(0x01, 0x08, 0x0b, 0x00, 0x0a));
define_test_att("/TP/GAR/CL/BI-09-C", test_read_by_type, &uuid_char_16,
&test_read_by_type_4,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
raw_pdu(0x01, 0x08, 0x0b, 0x00, 0x08));
define_test_att("/TP/GAR/CL/BI-10-C", test_read_by_type, &uuid_char_16,
&test_read_by_type_5,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
raw_pdu(0x01, 0x08, 0x0b, 0x00, 0x05));
define_test_att("/TP/GAR/CL/BI-11-C", test_read_by_type, &uuid_char_16,
&test_read_by_type_6,
- raw_pdu(0x02, 0x00, 0x02),
- raw_pdu(0x03, 0x00, 0x02),
+ MTU_EXCHANGE_CLIENT_PDUS,
raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x0d, 0x2a),
raw_pdu(0x01, 0x08, 0x0b, 0x00, 0x0c));
define_test_client("/TP/GAR/CL/BV-05-C", test_client, service_db_1,
&test_multiple_read_1,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
raw_pdu(0x0f, 0x01, 0x02, 0x03));
define_test_client("/TP/GAR/CL/BI-18-C", test_client, service_db_1,
&test_multiple_read_2,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
raw_pdu(0x01, 0x0e, 0x03, 0x00, 0x02));
define_test_client("/TP/GAR/CL/BI-19-C", test_client, service_db_1,
&test_multiple_read_3,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
raw_pdu(0x01, 0x0e, 0x03, 0x00, 0x01));
define_test_client("/TP/GAR/CL/BI-20-C", test_client, service_db_1,
&test_multiple_read_4,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
raw_pdu(0x01, 0x0e, 0x03, 0x00, 0x08));
define_test_client("/TP/GAR/CL/BI-21-C", test_client, service_db_1,
&test_multiple_read_5,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
raw_pdu(0x01, 0x0e, 0x03, 0x00, 0x05));
define_test_client("/TP/GAR/CL/BI-21-C", test_client, service_db_1,
&test_multiple_read_6,
- SERVICE_DATA_1_PDU,
+ SERVICE_DATA_1_PDUS,
raw_pdu(0x0e, 0x03, 0x00, 0x07, 0x00),
raw_pdu(0x01, 0x0e, 0x03, 0x00, 0x0c));
--
2.2.0.rc0.207.ga3a616c
---
unit/test-gatt.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index d131f0f..da86bb2 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -1136,12 +1136,12 @@ int main(int argc, char *argv[])
define_test_att("/TP/GAD/CL/BV-02-C-2", test_search_primary, &uuid_128,
NULL,
MTU_EXCHANGE_CLIENT_PDUS,
- raw_pdu(06, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28, 0xfb,
+ raw_pdu(0x06, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28, 0xfb,
0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00,
0x80, 0x00, 0x10, 0x00, 0x00, 0x0d,
0x18, 0x00, 0x00),
raw_pdu(0x07, 0x10, 0x00, 0x17, 0x00),
- raw_pdu(06, 0x18, 0x00, 0xff, 0xff, 0x00, 0x28, 0xfb,
+ raw_pdu(0x06, 0x18, 0x00, 0xff, 0xff, 0x00, 0x28, 0xfb,
0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00,
0x80, 0x00, 0x10, 0x00, 0x00, 0x0d,
0x18, 0x00, 0x00),
--
2.2.0.rc0.207.ga3a616c
When converting a UUID from string to bt_uuid_t, prefer using
the 16-bit version when possible, which should generate shorter
sequences by increasing the number of 16-bit types.
---
lib/uuid.c | 4 ++++
unit/test-uuid.c | 22 +++++++++++++++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/lib/uuid.c b/lib/uuid.c
index 5c3f986..d110b5e 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -238,6 +238,10 @@ static int bt_string_to_uuid128(bt_uuid_t *uuid, const char *string)
&data3, &data4, &data5) != 6)
return -EINVAL;
+ if (data0 <= 0xFFFF && data1 == 0x0000 && data2 == 0x1000 &&
+ data3 == 0x8000 && data4 == 0x0805f9bL && data5 == 0x34fb)
+ return bt_uuid16_create(uuid, data0 & 0xFFFF);
+
data0 = htonl(data0);
data1 = htons(data1);
data2 = htons(data2);
diff --git a/unit/test-uuid.c b/unit/test-uuid.c
index 6c7e9d0..8647af9 100644
--- a/unit/test-uuid.c
+++ b/unit/test-uuid.c
@@ -46,9 +46,9 @@ 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",
- .binary = uuid_base_binary,
- .type = BT_UUID128,
+ .str = "0000",
+ .val16 = 0x0000,
+ .type = BT_UUID16,
.str128 = "00000000-0000-1000-8000-00805f9b34fb",
.binary128 = uuid_base_binary,
};
@@ -93,6 +93,18 @@ static struct uuid_test_data uuid_32_2 = {
.binary128 = uuid_32_binary,
};
+static unsigned char uuid_128_binary[] = {
+ 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
+ 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb };
+
+static struct uuid_test_data uuid_128 = {
+ .str = "F0000000-0000-1000-8000-00805f9b34fb",
+ .binary = uuid_128_binary,
+ .type = BT_UUID128,
+ .str128 = "F0000000-0000-1000-8000-00805f9b34fb",
+ .binary128 = uuid_128_binary,
+};
+
static void test_uuid(gconstpointer data)
{
const struct uuid_test_data *test_data = data;
@@ -216,6 +228,10 @@ int main(int argc, char *argv[])
g_test_add_data_func("/uuid/thritytwo2/str", &uuid_32_2, test_str);
g_test_add_data_func("/uuid/thirtytwo2/cmp", &uuid_32_2, test_cmp);
+ g_test_add_data_func("/uuid/onetwentyeight", &uuid_128, test_uuid);
+ g_test_add_data_func("/uuid/onetwentyeight/str", &uuid_128, test_str);
+ g_test_add_data_func("/uuid/onetwentyeight/cmp", &uuid_128, test_cmp);
+
for (i = 0; malformed[i]; i++) {
char *testpath;
--
2.2.0.rc0.207.ga3a616c
Use the passed-in gatt_db for server tests instead of populating
with the same db every time.
---
unit/test-gatt.c | 70 +++++++++++++-------------------------------------------
1 file changed, 16 insertions(+), 54 deletions(-)
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 78e47df..0b190b2 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -450,42 +450,6 @@ static void client_ready_cb(bool success, uint8_t att_ecode, void *user_data)
context_quit(context);
}
-static void populate_db(struct context *context)
-{
- struct gatt_db *db = context->server_db;
- struct gatt_db_attribute *attr;
- bt_uuid_t uuid;
- uint128_t u128 = {
- .data = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }
- };
-
- /* Service 1 */
- bt_uuid16_create(&uuid, 0x1800);
- attr = gatt_db_add_service(db, &uuid, true, 5);
- gatt_db_service_set_active(attr, true);
-
- /* Service 2 */
- bt_uuid16_create(&uuid, 0x1801);
- attr = gatt_db_add_service(db, &uuid, true, 3);
- gatt_db_service_set_active(attr, true);
-
- /* Service 3 */
- bt_uuid16_create(&uuid, 0x180f);
- attr = gatt_db_add_service(db, &uuid, false, 5);
- gatt_db_service_set_active(attr, true);
-
- /* Service 4 */
- bt_uuid16_create(&uuid, 0x180d);
- attr = gatt_db_add_service(db, &uuid, true, 8);
- gatt_db_service_set_active(attr, true);
-
- /* Service 5 */
- bt_uuid128_create(&uuid, u128);
- attr = gatt_db_add_service(db, &uuid, true, 1);
- gatt_db_service_set_active(attr, true);
-}
-
static struct context *create_context(uint16_t mtu, gconstpointer data)
{
struct context *context = g_new0(struct context, 1);
@@ -514,15 +478,13 @@ static struct context *create_context(uint16_t mtu, gconstpointer data)
bt_gatt_exchange_mtu(context->att, mtu, NULL, NULL, NULL);
break;
case SERVER:
- context->server_db = gatt_db_new();
+ context->server_db = gatt_db_ref(test_data->source_db);
g_assert(context->server_db);
context->server = bt_gatt_server_new(context->server_db, att,
mtu);
g_assert(context->server);
- populate_db(context);
-
if (g_test_verbose())
bt_gatt_server_set_debug(context->server, print_debug,
"bt_gatt_server:", NULL);
@@ -718,7 +680,7 @@ static struct gatt_db *make_service_data_1_db(void)
struct gatt_db_attribute *serv_att, *chrc_att;
bt_uuid_t uuid;
- bt_string_to_uuid(&uuid, GATT_UUID);
+ bt_uuid16_create(&uuid, 0x1801);
serv_att = gatt_db_insert_service(db, 0x0001, &uuid, true, 4);
bt_uuid16_create(&uuid, GATT_CHARAC_DEVICE_NAME);
@@ -727,7 +689,9 @@ static struct gatt_db *make_service_data_1_db(void)
add_user_description(chrc_att, "Device Name", false);
- bt_string_to_uuid(&uuid, HEART_RATE_UUID);
+ gatt_db_service_set_active(serv_att, true);
+
+ bt_uuid16_create(&uuid, 0x180d);
serv_att = gatt_db_insert_service(db, 0x0005, &uuid, true, 4);
bt_uuid16_create(&uuid, GATT_CHARAC_MANUFACTURER_NAME_STRING);
@@ -738,6 +702,8 @@ static struct gatt_db *make_service_data_1_db(void)
add_user_description(chrc_att, "Manufacturer Name", false);
+ gatt_db_service_set_active(serv_att, true);
+
return db;
}
@@ -978,8 +944,9 @@ int main(int argc, char *argv[])
define_test_client("/TP/GAC/CL/BV-01-C", test_client, NULL, NULL,
raw_pdu(0x02, 0x00, 0x02));
- define_test_server("/TP/GAC/SR/BV-01-C", test_server, NULL, NULL,
- raw_pdu(0x03, 0x00, 0x02));
+ define_test_server("/TP/GAC/SR/BV-01-C", test_server, service_db_1,
+ NULL,
+ raw_pdu(0x03, 0x00, 0x02));
/*
* Discovery
@@ -1002,19 +969,14 @@ int main(int argc, char *argv[])
raw_pdu(0x10, 0x97, 0x00, 0xff, 0xff, 0x00, 0x28),
raw_pdu(0x01, 0x10, 0x97, 0x00, 0x0a));
- define_test_server("/TP/GAD/SR/BV-01-C", test_server, NULL, NULL,
+ define_test_server("/TP/GAD/SR/BV-01-C", test_server, service_db_1,
+ NULL,
raw_pdu(0x03, 0x00, 0x02),
raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x06, 0x01, 0x00, 0x05, 0x00, 0x00, 0x18,
- 0x06, 0x00, 0x08, 0x00, 0x01, 0x18,
- 0x0e, 0x00, 0x15, 0x00, 0x0d, 0x18),
- raw_pdu(0x10, 0x16, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x11, 0x14, 0x16, 0x00, 0x16, 0x00, 0x0f,
- 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09,
- 0x08, 0x07, 0x06, 0x05, 0x04, 0x03,
- 0x02, 0x01, 0x00),
- raw_pdu(0x10, 0x17, 0x00, 0xff, 0xff, 0x00, 0x28),
- raw_pdu(0x01, 0x10, 0x17, 0x00, 0x0a));
+ raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x01, 0x18,
+ 0x05, 0x00, 0x08, 0x00, 0x0d, 0x18),
+ raw_pdu(0x10, 0x06, 0x00, 0xff, 0xff, 0x00, 0x28),
+ raw_pdu(0x01, 0x10, 0x06, 0x00, 0x0a));
define_test_att("/TP/GAD/CL/BV-02-C-1", test_search_primary, &uuid_16,
NULL,
--
2.2.0.rc0.207.ga3a616c