You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by na...@apache.org on 2019/09/13 13:32:30 UTC
[mynewt-nimble] branch master updated (e6d9db0 -> 7340e6c)
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git.
from e6d9db0 porting: Add missing include in linux example
new d9caef7 apps/bttester: Add support for sending segmented buffers
new fa013c8 apps/bttester: Add support for sending GATT includes
new 814f73d apps/bttester: Fix GATT Get attribute value
new 2321a87 apps/bttester: Fix search attribute by handle
new 0c8f1b6 apps/bttester: Refactor Get Attrs and Get Attr Value
new 2ad14e7 apps/bttester: Delete code related to db offset calculation
new 5c68cca apps/bttester: Fix using mbufs
new 472485a apps/bttester: Improve add attributes and set value
new d9f28de apps/bttester: Remove write_long workaround
new c07adb5 apps/bttester: Fix find attribute by handle
new 309b93e apps/bttester: Add a dummy CCC descriptor definition
new 3fbe69b apps/bttester: Move descriptor definition for easier testing
new da51e2e apps/bttester: Change included service order
new 409c5a3 apps/bttester: Add Connection Parameter Update implementation
new 7ca817b apps/bttester: Add support for directed advertising
new ea6ef73 apps/bttester: Change default syscfg values to fit on nRF52DK
new 212a3e4 apps/bttester: Do not use atomics in gap.c
new 951abc9 apps/bttester: Add missing return buf check
new 7baafa0 apps/bttester: Add support for Security Level Changed event
new 7d75025 apps/bttester: Fix setting adv parameters for directed advertising
new e02b841 apps/bttester: Fix get_attributes infinite loop
new 1d9f377 apps/bttester: Add encryption key size logging
new d13afd4 apps/bttester: Fix Connection Parameter Update functionality
new 0c91f03 apps/bttester: Fix GATT Attribute permission mapping
new 29d3a15 apps/bttester: Modify gatt database
new 095c98e apps/bttester: Fix min key size
new fc6e29a apps/bttester: Fix gatt svr access callbacks
new 2344704 apps/bttester: Fix change_database
new eacaa48 apps/bttester: Add Attribute Value Changed event
new 90cd415 apps/bttester: Fix notification logic
new fc113f1 apps/bttester: Add Include Service
new 7340e6c apps/bttester: Fix mbuf handling in Mesh
The 32 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
apps/bttester/src/bttester.c | 17 +-
apps/bttester/src/bttester.h | 47 +
apps/bttester/src/bttester_pipe.h | 1 +
apps/bttester/src/gap.c | 295 +++-
apps/bttester/src/gatt.c | 2718 ++++++++++++++++---------------------
apps/bttester/src/mesh.c | 17 +-
apps/bttester/src/uart_pipe.c | 25 +
apps/bttester/syscfg.yml | 19 +-
8 files changed, 1479 insertions(+), 1660 deletions(-)
[mynewt-nimble] 15/32: apps/bttester: Add support for directed
advertising
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 7ca817b2adc32570dbd8910464464dbd32353b99
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Fri Jul 12 15:39:24 2019 +0200
apps/bttester: Add support for directed advertising
---
apps/bttester/src/bttester.h | 7 +++++++
apps/bttester/src/gap.c | 32 ++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index 9e41f57..cdfc50f 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -274,6 +274,13 @@ struct gap_passkey_confirm_cmd {
u8_t match;
} __packed;
+#define GAP_START_DIRECT_ADV 0x15
+struct gap_start_direct_adv_cmd {
+ u8_t address_type;
+ u8_t address[6];
+ u8_t high_duty;
+} __packed;
+
#define GAP_CONN_PARAM_UPDATE 0x16
struct gap_conn_param_update_cmd {
u8_t address_type;
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index 19bd72d..6c243bf 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -1254,6 +1254,35 @@ rsp:
status);
}
+static void start_direct_adv(const u8_t *data, u16_t len)
+{
+ const struct gap_start_direct_adv_cmd *cmd = (void *) data;
+ struct gap_start_advertising_rp rp;
+ int err;
+
+ SYS_LOG_DBG("");
+
+ adv_params.high_duty_cycle = cmd->high_duty;
+
+ err = ble_gap_adv_start(own_addr_type, (ble_addr_t *)data,
+ BLE_HS_FOREVER, &adv_params,
+ gap_event_cb, NULL);
+ if (err) {
+ SYS_LOG_ERR("Advertising failed: err %d", err);
+ goto fail;
+ }
+
+ atomic_set_bit(¤t_settings, GAP_SETTINGS_ADVERTISING);
+ rp.current_settings = sys_cpu_to_le32(current_settings);
+
+ tester_send(BTP_SERVICE_ID_GAP, GAP_START_DIRECT_ADV, CONTROLLER_INDEX,
+ (u8_t *) &rp, sizeof(rp));
+ return;
+fail:
+ tester_rsp(BTP_SERVICE_ID_GAP, GAP_START_DIRECT_ADV, CONTROLLER_INDEX,
+ BTP_STATUS_FAILED);
+}
+
static void conn_param_update_cb(uint16_t conn_handle, int status, void *arg)
{
u8_t btp_status;
@@ -1415,6 +1444,9 @@ void tester_handle_gap(u8_t opcode, u8_t index, u8_t *data,
case GAP_PASSKEY_CONFIRM:
passkey_confirm(data, len);
return;
+ case GAP_START_DIRECT_ADV:
+ start_direct_adv(data, len);
+ return;
case GAP_CONN_PARAM_UPDATE:
conn_param_update(data, len);
return;
[mynewt-nimble] 22/32: apps/bttester: Add encryption key size
logging
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 1d9f377d95b8ca854105f4ab966aa75a1d10cc1b
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu May 30 16:20:48 2019 +0200
apps/bttester: Add encryption key size logging
---
apps/bttester/src/gap.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index 38bbf73..a835ec8 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -918,9 +918,10 @@ static void print_conn_desc(const struct ble_gap_conn_desc *desc)
desc->peer_id_addr.type);
print_addr(desc->peer_id_addr.val);
console_printf(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "
- "encrypted=%d authenticated=%d bonded=%d\n",
+ "key_sz=%d encrypted=%d authenticated=%d bonded=%d\n",
desc->conn_itvl, desc->conn_latency,
desc->supervision_timeout,
+ desc->sec_state.key_size,
desc->sec_state.encrypted,
desc->sec_state.authenticated,
desc->sec_state.bonded);
[mynewt-nimble] 13/32: apps/bttester: Change included service order
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit da51e2ef1464f75f3e2bf7624cbf3892d93af7d1
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu May 16 01:08:09 2019 +0200
apps/bttester: Change included service order
---
apps/bttester/src/gatt.c | 65 ++++++++++++++++++++++++------------------------
1 file changed, 32 insertions(+), 33 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 28eda3a..dba4442 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -158,11 +158,39 @@ static int gatt_svr_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg);
+
+static const struct ble_gatt_svc_def gatt_svr_inc_svcs[] = {
+ {
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid = PTS_UUID_DECLARE(PTS_INC_SVC),
+ .characteristics = (struct ble_gatt_chr_def[]) {{
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ALT),
+ .access_cb = gatt_svr_access_cb,
+ .flags = BLE_GATT_CHR_F_READ |
+ BLE_GATT_CHR_F_WRITE,
+ .arg = &gatt_values[13],
+ .val_handle = &gatt_values[13].val_handle,
+ }, {
+ 0,
+ } },
+ },
+
+ {
+ 0, /* No more services. */
+ },
+};
+
+static const struct ble_gatt_svc_def *inc_svcs[] = {
+ &gatt_svr_inc_svcs[0],
+ NULL,
+};
+
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: PTS test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = PTS_UUID_DECLARE(PTS_SVC),
+ .includes = inc_svcs,
.characteristics = (struct ble_gatt_chr_def[]) { {
.uuid = PTS_UUID_DECLARE(PTS_CHR_NO_PERM),
.access_cb = gatt_svr_access_cb,
@@ -277,35 +305,6 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
},
};
-static const struct ble_gatt_svc_def *inc_svcs[] = {
- &gatt_svr_svcs[0],
- NULL,
-};
-
-static const struct ble_gatt_svc_def gatt_svr_inc_svcs[] = {
- {
- .type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = PTS_UUID_DECLARE(PTS_INC_SVC),
- .includes = inc_svcs,
- .characteristics = (struct ble_gatt_chr_def[]) {{
- .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ALT),
- .access_cb = gatt_svr_access_cb,
- .flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_WRITE,
- .arg = &gatt_values[13],
- .val_handle = &gatt_values[13].val_handle,
- },
- {
- 0,
- },
- },
- },
-
- {
- 0, /* No more services. */
- },
-};
-
static void init_gatt_values(void)
{
int i = 0;
@@ -2186,22 +2185,22 @@ int gatt_svr_init(void)
{
int rc;
- rc = ble_gatts_count_cfg(gatt_svr_svcs);
+ rc = ble_gatts_count_cfg(gatt_svr_inc_svcs);
if (rc != 0) {
return rc;
}
- rc = ble_gatts_add_svcs(gatt_svr_svcs);
+ rc = ble_gatts_add_svcs(gatt_svr_inc_svcs);
if (rc != 0) {
return rc;
}
- rc = ble_gatts_count_cfg(gatt_svr_inc_svcs);
+ rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
return rc;
}
- rc = ble_gatts_add_svcs(gatt_svr_inc_svcs);
+ rc = ble_gatts_add_svcs(gatt_svr_svcs);
if (rc != 0) {
return rc;
}
[mynewt-nimble] 02/32: apps/bttester: Add support for sending GATT
includes
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit fa013c8121a9b6e53a83fd42e0f7c76548b89a29
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Apr 3 16:07:53 2019 +0200
apps/bttester: Add support for sending GATT includes
---
apps/bttester/src/gatt.c | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 939aa0d..c1712bf 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -49,6 +49,8 @@ static const ble_uuid_t *uuid_pri =
BLE_UUID16_DECLARE(BLE_ATT_UUID_PRIMARY_SERVICE);
static const ble_uuid_t *uuid_sec =
BLE_UUID16_DECLARE(BLE_ATT_UUID_SECONDARY_SERVICE);
+static const ble_uuid_t *uuid_inc =
+ BLE_UUID16_DECLARE(BLE_ATT_UUID_INCLUDE);
static const ble_uuid_t *uuid_chr =
BLE_UUID16_DECLARE(BLE_ATT_UUID_CHARACTERISTIC);
static const ble_uuid_t *uuid_ccc =
@@ -1947,6 +1949,7 @@ static void get_attrs_cb(const struct ble_gatt_svc_def *svc,
void *arg)
{
struct get_attrs_foreach_data *foreach = arg;
+ const struct ble_gatt_svc_def **includes;
const struct ble_gatt_chr_def *chr;
const struct ble_gatt_dsc_def *dsc;
@@ -1959,31 +1962,39 @@ static void get_attrs_cb(const struct ble_gatt_svc_def *svc,
foreach_get_attrs(handle, BTP_GATT_PERM_READ,
uuid_sec, foreach);
}
+ handle += 1;
- /* TODO: iterate over included services*/
+ if (svc->includes) {
+ for (includes = &svc->includes[0];
+ *includes != NULL; ++includes) {
+ foreach_get_attrs(handle, BTP_GATT_PERM_READ,
+ uuid_inc, foreach);
+ handle += 1;
+ }
+ }
for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
- handle += 1;
foreach_get_attrs(handle, BTP_GATT_PERM_READ,
uuid_chr, foreach);
handle += 1;
+
foreach_get_attrs(handle, flags2perm(chr->flags, true),
chr->uuid, foreach);
+ handle += 1;
if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
(chr->flags & BLE_GATT_CHR_F_INDICATE)) {
- handle += 1;
-
foreach_get_attrs(handle,
flags2perm(BLE_ATT_F_READ |
BLE_ATT_F_WRITE,
false), uuid_ccc, foreach);
+ handle += 1;
}
for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
- handle += 1;
foreach_get_attrs(handle, flags2perm(chr->flags, false),
dsc->uuid, foreach);
+ handle += 1;
}
}
}
@@ -2032,8 +2043,8 @@ static void get_attrs(u8_t *data, u16_t len)
rp = (void *) net_buf_simple_push(buf, sizeof(*rp));
rp->attrs_count = foreach.count;
- tester_send(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTES, CONTROLLER_INDEX,
- buf->om_data, buf->om_len);
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTES,
+ CONTROLLER_INDEX, buf);
goto free;
fail:
[mynewt-nimble] 06/32: apps/bttester: Delete code related to db
offset calculation
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 2ad14e7207bcd3241b59728e2d349f00111c4e14
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Fri Apr 19 16:52:39 2019 +0200
apps/bttester: Delete code related to db offset calculation
GATT Start Server params are deprecated.
---
apps/bttester/src/gatt.c | 113 +----------------------------------------------
1 file changed, 2 insertions(+), 111 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 55c9cf2..8bd04f9 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -69,9 +69,6 @@ static int gatt_dsc_perm_map[] = {
/* GATT server context */
#define SERVER_MAX_VALUES 14
-static u16_t db_attr_min = 0xffff;
-static u16_t db_attr_max = 0x0000;
-
struct gatt_value {
struct os_mbuf *buf;
u8_t enc_key_size;
@@ -823,8 +820,8 @@ static void start_server(u8_t *data, u16_t len)
ble_svc_gatt_changed(0x0001, 0xffff);
- rp.db_attr_off = db_attr_min;
- rp.db_attr_cnt = (u8_t) (db_attr_max - db_attr_min + 1);
+ rp.db_attr_off = 0;
+ rp.db_attr_cnt = 0;
tester_send(BTP_SERVICE_ID_GATT, GATT_START_SERVER, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
@@ -2055,80 +2052,6 @@ void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
}
}
-static bool gatt_svr_svc_exists(const struct ble_gatt_svc_def *svc_def)
-{
- const struct ble_gatt_svc_def *svc;
-
- for (svc = &gatt_svr_svcs[0]; svc && svc->uuid; svc++) {
- if (svc == svc_def) {
- return true;
- }
- }
-
- for (svc = &gatt_svr_inc_svcs[0]; svc && svc->uuid; svc++) {
- if (svc == svc_def) {
- return true;
- }
- }
-
- return false;
-}
-
-static bool gatt_svr_chr_exists(const struct ble_gatt_chr_def *chr_def)
-{
- const struct ble_gatt_svc_def *svc;
- const struct ble_gatt_chr_def *chr;
-
- for (svc = &gatt_svr_svcs[0]; svc && svc->uuid; svc++) {
- for (chr = &svc->characteristics[0]; chr && chr->uuid; chr++) {
- if (chr == chr_def) {
- return true;
- }
- }
- }
-
- for (svc = &gatt_svr_inc_svcs[0]; svc && svc->uuid; svc++) {
- for (chr = &svc->characteristics[0]; chr && chr->uuid; chr++) {
- if (chr == chr_def) {
- return true;
- }
- }
- }
-
- return false;
-}
-
-static bool gatt_svr_dsc_exists(const struct ble_gatt_dsc_def *dsc_def)
-{
- const struct ble_gatt_svc_def *svc;
- const struct ble_gatt_chr_def *chr;
- const struct ble_gatt_dsc_def *dsc;
-
- for (svc = &gatt_svr_svcs[0]; svc && svc->uuid; svc++) {
- for (chr = &svc->characteristics[0]; chr && chr->uuid; chr++) {
- for (dsc = &chr->descriptors[0];
- dsc && dsc->uuid; dsc++) {
- if (dsc == dsc_def) {
- return true;
- }
- }
- }
- }
-
- for (svc = &gatt_svr_inc_svcs[0]; svc && svc->uuid; svc++) {
- for (chr = &svc->characteristics[0]; chr && chr->uuid; chr++) {
- for (dsc = &chr->descriptors[0];
- dsc && dsc->uuid; dsc++) {
- if (dsc == dsc_def) {
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
{
char buf[BLE_UUID_STR_LEN];
@@ -2140,14 +2063,6 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
ble_uuid_to_str(ctxt->svc.svc_def->uuid,
buf),
ctxt->svc.handle);
- if (gatt_svr_svc_exists(ctxt->svc.svc_def)) {
- if (ctxt->svc.handle < db_attr_min) {
- db_attr_min = ctxt->svc.handle;
- }
- if (ctxt->svc.handle > db_attr_max) {
- db_attr_max = ctxt->svc.handle;
- }
- }
break;
case BLE_GATT_REGISTER_OP_CHR:
@@ -2157,20 +2072,6 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
buf),
ctxt->chr.def_handle,
ctxt->chr.val_handle);
- if (gatt_svr_chr_exists(ctxt->chr.chr_def)) {
- if (ctxt->chr.def_handle < db_attr_min) {
- db_attr_min = ctxt->chr.def_handle;
- }
- if (ctxt->chr.val_handle < db_attr_min) {
- db_attr_min = ctxt->chr.val_handle;
- }
- if (ctxt->chr.def_handle > db_attr_max) {
- db_attr_max = ctxt->chr.def_handle;
- }
- if (ctxt->chr.val_handle > db_attr_max) {
- db_attr_max = ctxt->chr.val_handle;
- }
- }
break;
case BLE_GATT_REGISTER_OP_DSC:
@@ -2178,18 +2079,8 @@ void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
"registering descriptor %s with handle=%d\n",
ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
ctxt->dsc.handle);
- if (gatt_svr_dsc_exists(ctxt->dsc.dsc_def)) {
- if (ctxt->dsc.handle < db_attr_min) {
- db_attr_min = ctxt->dsc.handle;
- }
- if (ctxt->dsc.handle > db_attr_max) {
- db_attr_max = ctxt->dsc.handle;
- }
- }
break;
- /* FIXME: handle incldued services*/
-
default:
assert(0);
break;
[mynewt-nimble] 19/32: apps/bttester: Add support for Security
Level Changed event
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 7baafa080fee60f349d2184aece8ed2b8eb05170
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Jul 31 14:35:13 2019 +0200
apps/bttester: Add support for Security Level Changed event
---
apps/bttester/src/bttester.h | 7 +++++++
apps/bttester/src/gap.c | 33 ++++++++++++++++++++++++++++-----
2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index cdfc50f..f9780ca 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -363,6 +363,13 @@ struct gap_conn_param_update_ev {
u16_t supervision_timeout;
} __packed;
+#define GAP_EV_SEC_LEVEL_CHANGED 0x89
+struct gap_sec_level_changed_ev {
+ u8_t address_type;
+ u8_t address[6];
+ u8_t level;
+} __packed;
+
/* GATT Service */
/* commands */
#define GATT_READ_SUPPORTED_COMMANDS 0x01
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index 7c27e76..bd67f8d 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -824,11 +824,6 @@ static void le_identity_resolved(u16_t conn_handle)
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
}
-static void le_encryption_changed(struct ble_gap_conn_desc *desc)
-{
- encrypted = (bool) desc->sec_state.encrypted;
-}
-
static void le_conn_param_update(struct ble_gap_conn_desc *desc)
{
struct gap_conn_param_update_ev ev;
@@ -846,6 +841,34 @@ static void le_conn_param_update(struct ble_gap_conn_desc *desc)
CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
}
+static void le_encryption_changed(struct ble_gap_conn_desc *desc)
+{
+ struct gap_sec_level_changed_ev ev;
+
+ SYS_LOG_DBG("");
+
+ encrypted = (bool) desc->sec_state.encrypted;
+
+ ev.address_type = desc->peer_ota_addr.type;
+ memcpy(ev.address, desc->peer_ota_addr.val, sizeof(ev.address));
+ ev.level = 0;
+
+ if (desc->sec_state.encrypted) {
+ if (desc->sec_state.authenticated) {
+ if (desc->sec_state.key_size == 16) {
+ ev.level = 3;
+ } else {
+ ev.level = 2;
+ }
+ } else {
+ ev.level = 1;
+ }
+ }
+
+ tester_send(BTP_SERVICE_ID_GAP, GAP_EV_SEC_LEVEL_CHANGED,
+ CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
+}
+
static void print_bytes(const uint8_t *bytes, int len)
{
int i;
[mynewt-nimble] 26/32: apps/bttester: Fix min key size
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 095c98efb04773c4228e2fc5857425f5a3158318
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Fri Aug 23 15:46:10 2019 +0200
apps/bttester: Fix min key size
---
apps/bttester/src/gatt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 72a7831..22da3fe 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -187,7 +187,7 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
BLE_GATT_CHR_F_READ |
BLE_GATT_CHR_F_WRITE |
BLE_GATT_CHR_F_WRITE_ENC,
- .min_key_size = 0x16,
+ .min_key_size = 16,
}, {
.uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE),
.access_cb = gatt_svr_read_write_long_test,
[mynewt-nimble] 12/32: apps/bttester: Move descriptor definition
for easier testing
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 3fbe69ba7c22f1b6b12e2432bc5d360bec8e2bd3
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Mon May 27 13:56:55 2019 +0200
apps/bttester: Move descriptor definition for easier testing
This is helpful for BTP Tester application.
---
apps/bttester/src/gatt.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 6209154..28eda3a 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -200,6 +200,14 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
BLE_GATT_CHR_F_INDICATE,
.arg = &gatt_values[4],
.val_handle = &gatt_values[4].val_handle,
+ .descriptors = (struct ble_gatt_dsc_def[]) { {
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE),
+ .access_cb = gatt_svr_access_cb,
+ .att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
+ .arg = &gatt_values[5],
+ }, {
+ 0
+ } }
}, {
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ENC),
.access_cb = gatt_svr_access_cb,
@@ -208,8 +216,8 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
BLE_GATT_CHR_F_WRITE |
BLE_GATT_CHR_F_WRITE_ENC,
.min_key_size = 0x0f,
- .arg = &gatt_values[5],
- .val_handle = &gatt_values[5].val_handle,
+ .arg = &gatt_values[6],
+ .val_handle = &gatt_values[6].val_handle,
}, {
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_AUTHEN),
.access_cb = gatt_svr_access_cb,
@@ -217,8 +225,8 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
BLE_GATT_CHR_F_READ_AUTHEN |
BLE_GATT_CHR_F_WRITE |
BLE_GATT_CHR_F_WRITE_AUTHEN,
- .arg = &gatt_values[6],
- .val_handle = &gatt_values[6].val_handle,
+ .arg = &gatt_values[7],
+ .val_handle = &gatt_values[7].val_handle,
}, {
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_AUTHOR),
.access_cb = gatt_svr_access_cb,
@@ -226,23 +234,18 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
BLE_GATT_CHR_F_READ_AUTHOR |
BLE_GATT_CHR_F_WRITE |
BLE_GATT_CHR_F_WRITE_AUTHOR,
- .arg = &gatt_values[7],
- .val_handle = &gatt_values[7].val_handle,
+ .arg = &gatt_values[8],
+ .val_handle = &gatt_values[8].val_handle,
.descriptors = (struct ble_gatt_dsc_def[]){ {
.uuid = PTS_UUID_DECLARE(PTS_DSC_READ),
.access_cb = gatt_svr_access_cb,
.att_flags = BLE_ATT_F_READ,
- .arg = &gatt_values[8],
+ .arg = &gatt_values[9],
}, {
.uuid = PTS_UUID_DECLARE(PTS_DSC_WRITE),
.access_cb = gatt_svr_access_cb,
.att_flags = BLE_ATT_F_WRITE,
- .arg = &gatt_values[9],
- }, {
- .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE),
- .access_cb = gatt_svr_access_cb,
- .att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
.arg = &gatt_values[10],
}, {
.uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_ENC),
[mynewt-nimble] 10/32: apps/bttester: Fix find attribute by handle
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit c07adb5c5a478b3bc143f75aec0ccd2826d6ca43
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Mon May 27 13:53:52 2019 +0200
apps/bttester: Fix find attribute by handle
There was a typo that caused wrong interpretation of returned
pointer to a structure with a descriptor definition.
---
apps/bttester/src/gatt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index cba662d..c6f7fd4 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -511,7 +511,7 @@ static void find_attr_by_handle_cb(const struct ble_gatt_svc_def *svc,
for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
if (handle == foreach->handle) {
- foreach->attr_type = BLE_GATT_ATTR_CHR;
+ foreach->attr_type = BLE_GATT_ATTR_DSC;
foreach->ptr = (void *) dsc;
return;
}
[mynewt-nimble] 17/32: apps/bttester: Do not use atomics in gap.c
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 212a3e467ec78ad225862242880439f0c647c825
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Jul 24 15:46:31 2019 +0200
apps/bttester: Do not use atomics in gap.c
This is so we can compile app without BLE_MESH.
---
apps/bttester/src/gap.c | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index 6c243bf..7c27e76 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -33,7 +33,6 @@
#include "../../../nimble/host/src/ble_hs_hci_priv.h"
#include "../../../nimble/host/src/ble_sm_priv.h"
-#include "atomic.h"
#include "bttester.h"
#define CONTROLLER_INDEX 0
@@ -47,7 +46,7 @@ const uint8_t irk[16] = {
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
};
-static atomic_t current_settings;
+static uint16_t current_settings;
u8_t own_addr_type;
static ble_addr_t peer_id_addr;
static ble_addr_t peer_ota_addr;
@@ -167,7 +166,7 @@ static void controller_info(u8_t *data, u16_t len)
} else {
own_addr_type = BLE_OWN_ADDR_RPA_RANDOM_DEFAULT;
}
- atomic_set_bit(¤t_settings, GAP_SETTINGS_PRIVACY);
+ current_settings |= BIT(GAP_SETTINGS_PRIVACY);
supported_settings |= BIT(GAP_SETTINGS_PRIVACY);
memcpy(rp.address, addr.val, sizeof(rp.address));
} else {
@@ -175,8 +174,7 @@ static void controller_info(u8_t *data, u16_t len)
own_addr_type = BLE_OWN_ADDR_RANDOM;
memcpy(rp.address, addr.val, sizeof(rp.address));
supported_settings |= BIT(GAP_SETTINGS_STATIC_ADDRESS);
- atomic_set_bit(¤t_settings,
- GAP_SETTINGS_STATIC_ADDRESS);
+ current_settings |= BIT(GAP_SETTINGS_STATIC_ADDRESS);
} else {
own_addr_type = BLE_OWN_ADDR_PUBLIC;
memcpy(rp.address, MYNEWT_VAL(BLE_PUBLIC_DEV_ADDR),
@@ -214,10 +212,10 @@ static void set_connectable(u8_t *data, u16_t len)
SYS_LOG_DBG("");
if (cmd->connectable) {
- atomic_set_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE);
+ current_settings |= BIT(GAP_SETTINGS_CONNECTABLE);
adv_params.conn_mode = BLE_GAP_CONN_MODE_UND;
} else {
- atomic_clear_bit(¤t_settings, GAP_SETTINGS_CONNECTABLE);
+ current_settings &= ~BIT(GAP_SETTINGS_CONNECTABLE);
adv_params.conn_mode = BLE_GAP_CONN_MODE_NON;
}
@@ -240,19 +238,19 @@ static void set_discoverable(u8_t *data, u16_t len)
case GAP_NON_DISCOVERABLE:
ad_flags &= ~(BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_DISC_LTD);
adv_params.disc_mode = BLE_GAP_DISC_MODE_NON;
- atomic_clear_bit(¤t_settings, GAP_SETTINGS_DISCOVERABLE);
+ current_settings &= ~BIT(GAP_SETTINGS_DISCOVERABLE);
break;
case GAP_GENERAL_DISCOVERABLE:
ad_flags &= ~BLE_HS_ADV_F_DISC_LTD;
ad_flags |= BLE_HS_ADV_F_DISC_GEN;
adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN;
- atomic_set_bit(¤t_settings, GAP_SETTINGS_DISCOVERABLE);
+ current_settings |= BIT(GAP_SETTINGS_DISCOVERABLE);
break;
case GAP_LIMITED_DISCOVERABLE:
ad_flags &= ~BLE_HS_ADV_F_DISC_GEN;
ad_flags |= BLE_HS_ADV_F_DISC_LTD;
adv_params.disc_mode = BLE_GAP_DISC_MODE_LTD;
- atomic_set_bit(¤t_settings, GAP_SETTINGS_DISCOVERABLE);
+ current_settings |= BIT(GAP_SETTINGS_DISCOVERABLE);
break;
default:
tester_rsp(BTP_SERVICE_ID_GAP, GAP_SET_DISCOVERABLE,
@@ -363,7 +361,7 @@ static void start_advertising(const u8_t *data, u16_t len)
goto fail;
}
- atomic_set_bit(¤t_settings, GAP_SETTINGS_ADVERTISING);
+ current_settings |= BIT(GAP_SETTINGS_ADVERTISING);
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_START_ADVERTISING, CONTROLLER_INDEX,
@@ -386,7 +384,7 @@ static void stop_advertising(const u8_t *data, u16_t len)
return;
}
- atomic_clear_bit(¤t_settings, GAP_SETTINGS_ADVERTISING);
+ current_settings &= ~BIT(GAP_SETTINGS_ADVERTISING);
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_STOP_ADVERTISING, CONTROLLER_INDEX,
@@ -909,7 +907,7 @@ static void adv_complete(void)
{
struct gap_new_settings_ev ev;
- atomic_clear_bit(¤t_settings, GAP_SETTINGS_ADVERTISING);
+ current_settings &= ~BIT(GAP_SETTINGS_ADVERTISING);
ev.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_NEW_SETTINGS, CONTROLLER_INDEX,
@@ -1272,7 +1270,7 @@ static void start_direct_adv(const u8_t *data, u16_t len)
goto fail;
}
- atomic_set_bit(¤t_settings, GAP_SETTINGS_ADVERTISING);
+ current_settings |= BIT(GAP_SETTINGS_ADVERTISING);
rp.current_settings = sys_cpu_to_le32(current_settings);
tester_send(BTP_SERVICE_ID_GAP, GAP_START_DIRECT_ADV, CONTROLLER_INDEX,
@@ -1465,10 +1463,10 @@ static void tester_init_gap_cb(int err)
return;
}
- atomic_clear(¤t_settings);
- atomic_set_bit(¤t_settings, GAP_SETTINGS_POWERED);
- atomic_set_bit(¤t_settings, GAP_SETTINGS_BONDABLE);
- atomic_set_bit(¤t_settings, GAP_SETTINGS_LE);
+ current_settings = 0;
+ current_settings |= BIT(GAP_SETTINGS_POWERED);
+ current_settings |= BIT(GAP_SETTINGS_BONDABLE);
+ current_settings |= BIT(GAP_SETTINGS_LE);
tester_rsp(BTP_SERVICE_ID_CORE, CORE_REGISTER_SERVICE, BTP_INDEX_NONE,
BTP_STATUS_SUCCESS);
[mynewt-nimble] 31/32: apps/bttester: Add Include Service
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit fc113f13d41fa051ca9003093df0721de3f25df0
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Fri Aug 30 15:47:17 2019 +0200
apps/bttester: Add Include Service
---
apps/bttester/src/gatt.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 79fc47f..6f2cdc5 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -135,12 +135,36 @@ gatt_svr_dsc_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg);
+static const struct ble_gatt_svc_def gatt_svr_inc_svcs[] = {
+ {
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid = PTS_UUID_DECLARE(PTS_INC_SVC),
+ .characteristics = (struct ble_gatt_chr_def[]) {{
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ALT),
+ .access_cb = gatt_svr_read_write_test,
+ .flags = BLE_GATT_CHR_F_WRITE |
+ BLE_GATT_CHR_F_READ,
+ }, {
+ 0,
+ } },
+ },
+
+ {
+ 0, /* No more services. */
+ },
+};
+
+static const struct ble_gatt_svc_def *inc_svcs[] = {
+ &gatt_svr_inc_svcs[0],
+ NULL,
+};
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: PTS test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = PTS_UUID_DECLARE(PTS_SVC),
+ .includes = inc_svcs,
.characteristics = (struct ble_gatt_chr_def[]) { {
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE),
.access_cb = gatt_svr_read_write_test,
@@ -295,6 +319,7 @@ gatt_svr_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_CHR_READ_WRITE:
+ case PTS_CHR_READ_WRITE_ALT:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
rc = gatt_svr_chr_write(conn_handle, attr_handle,
ctxt->om, 0,
@@ -1995,6 +2020,16 @@ int gatt_svr_init(void)
{
int rc;
+ rc = ble_gatts_count_cfg(gatt_svr_inc_svcs);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_gatts_add_svcs(gatt_svr_inc_svcs);
+ if (rc != 0) {
+ return rc;
+ }
+
rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
return rc;
[mynewt-nimble] 03/32: apps/bttester: Fix GATT Get attribute value
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 814f73de88a1af54da74d245fc7eca575de24e42
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Apr 3 16:57:16 2019 +0200
apps/bttester: Fix GATT Get attribute value
---
apps/bttester/src/gatt.c | 61 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 43 insertions(+), 18 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index c1712bf..4afeb1d 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -2063,9 +2063,26 @@ static int access_svc(uint16_t conn_handle, uint16_t attr_handle,
net_buf_simple_add_le16(ctxt->om,
BLE_UUID16(svc->uuid)->value);
} else {
- os_mbuf_append(ctxt->om,
- BLE_UUID128(svc->uuid)->value,
- 16);
+ net_buf_simple_add_mem(ctxt->om,
+ BLE_UUID128(svc->uuid)->value,
+ 16);
+ }
+
+ return 0;
+}
+
+static int access_incl_svc(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt, void *arg)
+{
+ const struct ble_gatt_svc_def *svc = arg;
+
+ /* TODO: Get included service handle and end group handle */
+ net_buf_simple_add_le16(ctxt->om, 0xffff);
+ net_buf_simple_add_le16(ctxt->om, 0xffff);
+
+ if (svc->uuid->type == BLE_UUID_TYPE_16) {
+ net_buf_simple_add_le16(ctxt->om,
+ BLE_UUID16(svc->uuid)->value);
}
return 0;
@@ -2083,9 +2100,9 @@ static int access_chr(uint16_t conn_handle, uint16_t attr_handle,
net_buf_simple_add_le16(ctxt->om,
BLE_UUID16(chr->uuid)->value);
} else {
- os_mbuf_append(ctxt->om,
- BLE_UUID128(chr->uuid)->value,
- 16);
+ net_buf_simple_add_mem(ctxt->om,
+ BLE_UUID128(chr->uuid)->value,
+ 16);
}
return 0;
@@ -2113,17 +2130,12 @@ static int foreach_get_attr_val(u16_t handle,
return 0;
}
- SYS_LOG_DBG("handle=%d", handle);
-
rp = net_buf_simple_add(ctxt->om, sizeof(*rp));
-
- SYS_LOG_DBG("len=%d", ctxt->om->om_len);
hdr_len = ctxt->om->om_len;
rc = access_cb(1, handle, ctxt, arg);
rp->att_response = (uint8_t) rc;
- SYS_LOG_DBG("len=%d", ctxt->om->om_len);
rp->value_length = ctxt->om->om_len - hdr_len;
return BLE_HS_EDONE;
@@ -2136,6 +2148,7 @@ static void get_attr_val_cb(const struct ble_gatt_svc_def *svc,
struct get_attrs_foreach_data *foreach = arg;
struct os_mbuf *buf = foreach->buf;
struct ble_gatt_access_ctxt ctxt;
+ const struct ble_gatt_svc_def **includes;
const struct ble_gatt_chr_def *chr;
const struct ble_gatt_dsc_def *dsc;
int rc;
@@ -2150,10 +2163,20 @@ static void get_attr_val_cb(const struct ble_gatt_svc_def *svc,
return;
}
- /* TODO: iterate over included services*/
+ handle += 1;
+
+ if (svc->includes) {
+ for (includes = &svc->includes[0];
+ *includes != NULL; ++includes) {
+ svc = *includes;
+ foreach_get_attr_val(handle, access_incl_svc,
+ (void *) svc, &ctxt,
+ foreach->start_handle);
+ handle += 1;
+ }
+ }
for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
- handle += 1;
rc = foreach_get_attr_val(handle, access_chr, (void *) chr,
&ctxt, foreach->start_handle);
if (rc == BLE_HS_EDONE) {
@@ -2161,6 +2184,7 @@ static void get_attr_val_cb(const struct ble_gatt_svc_def *svc,
}
handle += 1;
+
ctxt.op = BLE_GATT_ACCESS_OP_READ_CHR;
ctxt.chr = chr;
@@ -2171,9 +2195,10 @@ static void get_attr_val_cb(const struct ble_gatt_svc_def *svc,
return;
}
+ handle += 1;
+
if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
(chr->flags & BLE_GATT_CHR_F_INDICATE)) {
- handle += 1;
ctxt.op = BLE_GATT_ACCESS_OP_READ_CHR;
rc = foreach_get_attr_val(handle,
@@ -2182,11 +2207,11 @@ static void get_attr_val_cb(const struct ble_gatt_svc_def *svc,
if (rc == BLE_HS_EDONE) {
return;
}
- }
- for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
handle += 1;
+ }
+ for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
ctxt.op = BLE_GATT_ACCESS_OP_READ_DSC;
ctxt.dsc = dsc;
@@ -2196,6 +2221,8 @@ static void get_attr_val_cb(const struct ble_gatt_svc_def *svc,
if (rc == BLE_HS_EDONE) {
return;
}
+
+ handle += 1;
}
}
}
@@ -2207,8 +2234,6 @@ static void get_attr_val(u8_t *data, u16_t len)
struct get_attrs_foreach_data foreach;
u16_t handle = sys_cpu_to_le16(cmd->handle);
- SYS_LOG_DBG("handle=%d", handle);
-
memset(&foreach, 0, sizeof(foreach));
net_buf_simple_init(buf, 0);
[mynewt-nimble] 20/32: apps/bttester: Fix setting adv parameters
for directed advertising
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 7d7502598e220c19f551dcb6547e7556a60b0290
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu Aug 1 15:46:54 2019 +0200
apps/bttester: Fix setting adv parameters for directed advertising
---
apps/bttester/src/gap.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index bd67f8d..38bbf73 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -1279,6 +1279,9 @@ static void start_direct_adv(const u8_t *data, u16_t len)
{
const struct gap_start_direct_adv_cmd *cmd = (void *) data;
struct gap_start_advertising_rp rp;
+ static struct ble_gap_adv_params adv_params = {
+ .conn_mode = BLE_GAP_CONN_MODE_DIR,
+ };
int err;
SYS_LOG_DBG("");
[mynewt-nimble] 25/32: apps/bttester: Modify gatt database
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 29d3a155c3c5b12aff9ffbca49514a9dfcb61b46
Author: Szymon Czapracki <sz...@gmail.com>
AuthorDate: Fri Aug 2 15:01:04 2019 +0200
apps/bttester: Modify gatt database
Slim down overall number of gatt services, characteristics etc.
Make database static, remove functions for adding or deleting values.
---
apps/bttester/src/bttester.c | 1 -
apps/bttester/src/bttester.h | 9 +
apps/bttester/src/gatt.c | 2449 +++++++++++++++++++-----------------------
3 files changed, 1115 insertions(+), 1344 deletions(-)
diff --git a/apps/bttester/src/bttester.c b/apps/bttester/src/bttester.c
index 02021d0..54b14da 100644
--- a/apps/bttester/src/bttester.c
+++ b/apps/bttester/src/bttester.c
@@ -254,7 +254,6 @@ static u8_t *recv_cb(u8_t *buf, size_t *off)
len = sys_le16_to_cpu(cmd->len);
if (len > BTP_MTU - sizeof(*cmd)) {
- SYS_LOG_ERR("BT tester: invalid packet length");
*off = 0;
return buf;
}
diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index f9780ca..d3d4f73 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -651,6 +651,8 @@ struct gatt_attr {
#define GATT_GET_ATTRIBUTE_VALUE 0x1d
struct gatt_get_attribute_value_cmd {
+ u8_t address_type;
+ u8_t address[6];
u16_t handle;
} __packed;
struct gatt_get_attribute_value_rp {
@@ -659,6 +661,13 @@ struct gatt_get_attribute_value_rp {
u8_t value[0];
} __packed;
+#define GATT_CHANGE_DATABASE 0x1e
+struct gatt_change_database {
+ u16_t start_handle;
+ u16_t end_handle;
+ u8_t visibility;
+} __packed;
+
/* GATT events */
#define GATT_EV_NOTIFICATION 0x80
struct gatt_notification_ev {
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index fe24275..72a7831 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1,13 +1,13 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
+ * with the License. You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
@@ -41,855 +41,504 @@
#define CONTROLLER_INDEX 0
#define MAX_BUFFER_SIZE 2048
-static const ble_uuid_t *uuid_ccc =
- BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16);
-
-static int gatt_chr_perm_map[] = {
- BLE_GATT_CHR_F_READ,
- BLE_GATT_CHR_F_WRITE,
- BLE_GATT_CHR_F_READ_ENC,
- BLE_GATT_CHR_F_WRITE_ENC,
- BLE_GATT_CHR_F_READ_AUTHEN,
- BLE_GATT_CHR_F_WRITE_AUTHEN,
- BLE_GATT_CHR_F_READ_AUTHOR,
- BLE_GATT_CHR_F_WRITE_AUTHOR,
-};
-
-static int gatt_dsc_perm_map[] = {
- BLE_ATT_F_READ,
- BLE_ATT_F_WRITE,
- BLE_ATT_F_READ_ENC,
- BLE_ATT_F_WRITE_ENC,
- BLE_ATT_F_READ_AUTHEN,
- BLE_ATT_F_WRITE_AUTHEN,
- BLE_ATT_F_READ_AUTHOR,
- BLE_ATT_F_WRITE_AUTHOR,
-};
-
-/* GATT server context */
-#define SERVER_MAX_VALUES 14
-
-struct gatt_value {
- struct os_mbuf *buf;
- u8_t enc_key_size;
- u8_t flags[1];
- u16_t val_handle;
- u8_t type;
- void *ptr;
-};
-
-enum {
- GATT_VALUE_TYPE_CHR,
- GATT_VALUE_TYPE_DSC,
-};
-
-static struct gatt_value gatt_values[SERVER_MAX_VALUES];
-
/* 0000xxxx-8c26-476f-89a7-a108033a69c7 */
-#define PTS_UUID_DECLARE(uuid16) \
+#define PTS_UUID_DECLARE(uuid16) \
((const ble_uuid_t *) (&(ble_uuid128_t) BLE_UUID128_INIT( \
- 0xc7, 0x69, 0x3a, 0x03, 0x08, 0xa1, 0xa7, 0x89, \
- 0x6f, 0x47, 0x26, 0x8c, uuid16, uuid16 >> 8, 0x00, 0x00 \
+ 0xc7, 0x69, 0x3a, 0x03, 0x08, 0xa1, 0xa7, 0x89, \
+ 0x6f, 0x47, 0x26, 0x8c, uuid16, uuid16 >> 8, 0x00, 0x00 \
)))
-#define PTS_SVC 0x0001
-#define PTS_CHR_NO_PERM 0x0002
-#define PTS_CHR_READ 0x0003
-#define PTS_CHR_RELIABLE_WRITE 0x0004
-#define PTS_CHR_WRITE_NO_RSP 0x0005
-#define PTS_CHR_READ_WRITE 0x0006
-#define PTS_CHR_READ_WRITE_ENC 0x0007
-#define PTS_CHR_READ_WRITE_AUTHEN 0x0008
-#define PTS_CHR_READ_WRITE_AUTHOR 0x0009
-#define PTS_DSC_READ 0x000a
-#define PTS_DSC_WRITE 0x000b
-#define PTS_DSC_READ_WRITE 0x000c
-#define PTS_DSC_READ_WRITE_ENC 0x000d
-#define PTS_DSC_READ_WRITE_AUTHEN 0x000e
-#define PTS_INC_SVC 0x000f
-#define PTS_CHR_READ_WRITE_ALT 0x0010
-
-/*
- * gatt_buf - cache used by a gatt client (to cache data read/discovered)
- * and gatt server (to store attribute user_data).
- * It is not intended to be used by client and server at the same time.
- */
-static struct {
- u16_t len;
- u8_t buf[MAX_BUFFER_SIZE];
-} gatt_buf;
-
-static void *gatt_buf_add(const void *data, size_t len)
-{
- void *ptr = gatt_buf.buf + gatt_buf.len;
+/* 0000xxxx-8c26-476f-89a7-a108033a69c6 */
+#define PTS_UUID_DECLARE_ALT(uuid16) \
+ ((const ble_uuid_t *) (&(ble_uuid128_t) BLE_UUID128_INIT( \
+ 0xc6, 0x69, 0x3a, 0x03, 0x08, 0xa1, 0xa7, 0x89, \
+ 0x6f, 0x47, 0x26, 0x8c, uuid16, uuid16 >> 8, 0x00, 0x00 \
+ )))
- if ((len + gatt_buf.len) > MAX_BUFFER_SIZE) {
- return NULL;
- }
+#define PTS_SVC 0x0001
+#define PTS_CHR_READ 0x0002
+#define PTS_CHR_WRITE 0x0003
+#define PTS_CHR_RELIABLE_WRITE 0x0004
+#define PTS_CHR_WRITE_NO_RSP 0x0005
+#define PTS_CHR_READ_WRITE 0x0006
+#define PTS_CHR_READ_WRITE_ENC 0x0007
+#define PTS_CHR_READ_WRITE_AUTHEN 0x0008
+#define PTS_DSC_READ 0x0009
+#define PTS_DSC_WRITE 0x000a
+#define PTS_DSC_READ_WRITE 0x000b
+#define PTS_CHR_NOTIFY 0x0025
+#define PTS_LONG_CHR_READ_WRITE 0x0015
+#define PTS_LONG_CHR_READ_WRITE_ALT 0x0016
+#define PTS_LONG_DSC_READ_WRITE 0x001b
+#define PTS_INC_SVC 0x001e
+#define PTS_CHR_READ_WRITE_ALT 0x001f
+
+static uint8_t gatt_svr_pts_static_long_val[300];
+static uint8_t gatt_svr_pts_static_val[30];
+static uint8_t gatt_svr_pts_static_short_val;
+static bool notify_state;
+static uint16_t myconn_handle;
+static struct os_callout notify_tx_timer;
+uint16_t notify_handle;
- if (data) {
- memcpy(ptr, data, len);
- } else {
- (void)memset(ptr, 0, len);
- }
+struct find_attr_data {
+ ble_uuid_any_t *uuid;
+ int attr_type;
+ void *ptr;
+ uint16_t handle;
+};
- gatt_buf.len += len;
+static int
+gatt_svr_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
- SYS_LOG_DBG("%d/%d used", gatt_buf.len, MAX_BUFFER_SIZE);
+static int
+gatt_svr_read_write_auth_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
- return ptr;
-}
+static int
+gatt_svr_read_write_enc_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
-static const struct ble_gatt_dsc_def cccd_def = {
- .att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
-};
+static int
+gatt_svr_dsc_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
-static void *gatt_buf_reserve(size_t len)
-{
- return gatt_buf_add(NULL, len);
-}
+static int
+gatt_svr_write_no_rsp_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
-static void gatt_buf_clear(void)
-{
- (void)memset(&gatt_buf, 0, sizeof(gatt_buf));
-}
+static int
+gatt_svr_rel_write_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
-static int gatt_svr_access_cb(uint16_t conn_handle, uint16_t attr_handle,
+static int
+gatt_svr_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg);
+static int
+gatt_svr_dsc_read_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
-static const struct ble_gatt_svc_def gatt_svr_inc_svcs[] = {
- {
- .type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = PTS_UUID_DECLARE(PTS_INC_SVC),
- .characteristics = (struct ble_gatt_chr_def[]) {{
- .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ALT),
- .access_cb = gatt_svr_access_cb,
- .flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_WRITE,
- .arg = &gatt_values[13],
- .val_handle = &gatt_values[13].val_handle,
- }, {
- 0,
- } },
- },
-
- {
- 0, /* No more services. */
- },
-};
+static int
+gatt_svr_dsc_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg);
-static const struct ble_gatt_svc_def *inc_svcs[] = {
- &gatt_svr_inc_svcs[0],
- NULL,
-};
static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
{
/*** Service: PTS test. */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = PTS_UUID_DECLARE(PTS_SVC),
- .includes = inc_svcs,
.characteristics = (struct ble_gatt_chr_def[]) { {
- .uuid = PTS_UUID_DECLARE(PTS_CHR_NO_PERM),
- .access_cb = gatt_svr_access_cb,
- .flags = 0,
- .arg = &gatt_values[0],
- .val_handle = &gatt_values[0].val_handle,
- }, {
- .uuid = PTS_UUID_DECLARE(PTS_CHR_READ),
- .access_cb = gatt_svr_access_cb,
- .flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_NOTIFY |
- BLE_GATT_CHR_F_INDICATE,
- .arg = &gatt_values[1],
- .val_handle = &gatt_values[1].val_handle,
- }, {
- .uuid = PTS_UUID_DECLARE(PTS_CHR_RELIABLE_WRITE),
- .access_cb = gatt_svr_access_cb,
- .flags = BLE_GATT_CHR_F_WRITE |
- BLE_GATT_CHR_F_RELIABLE_WRITE,
- .arg = &gatt_values[2],
- .val_handle = &gatt_values[2].val_handle,
- }, {
- .uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE_NO_RSP),
- .access_cb = gatt_svr_access_cb,
- .flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_WRITE_NO_RSP,
- .arg = &gatt_values[3],
- .val_handle = &gatt_values[3].val_handle,
- }, {
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE),
- .access_cb = gatt_svr_access_cb,
+ .access_cb = gatt_svr_read_write_test,
.flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_WRITE |
- BLE_GATT_CHR_F_NOTIFY |
- BLE_GATT_CHR_F_INDICATE,
- .arg = &gatt_values[4],
- .val_handle = &gatt_values[4].val_handle,
+ BLE_GATT_CHR_F_WRITE,
.descriptors = (struct ble_gatt_dsc_def[]) { {
- .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE),
- .access_cb = gatt_svr_access_cb,
- .att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
- .arg = &gatt_values[5],
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE),
+ .access_cb = gatt_svr_dsc_read_write_test,
+ .att_flags = BLE_ATT_F_READ |
+ BLE_ATT_F_WRITE,
+ }, {
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_DSC_READ_WRITE),
+ .access_cb = gatt_svr_dsc_read_write_long_test,
+ .att_flags = BLE_ATT_F_READ |
+ BLE_ATT_F_WRITE,
}, {
- 0
+ .uuid = PTS_UUID_DECLARE(PTS_DSC_READ),
+ .access_cb = gatt_svr_dsc_read_test,
+ .att_flags = BLE_ATT_F_READ,
+ }, {
+ 0, /* No more descriptors in this characteristic */
} }
}, {
- .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ENC),
- .access_cb = gatt_svr_access_cb,
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_WRITE_NO_RSP),
+ .access_cb = gatt_svr_write_no_rsp_test,
.flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_READ_ENC |
BLE_GATT_CHR_F_WRITE |
- BLE_GATT_CHR_F_WRITE_ENC,
- .min_key_size = 0x0f,
- .arg = &gatt_values[6],
- .val_handle = &gatt_values[6].val_handle,
+ BLE_GATT_CHR_F_WRITE_NO_RSP,
}, {
.uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_AUTHEN),
- .access_cb = gatt_svr_access_cb,
- .flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_READ_AUTHEN |
+ .access_cb = gatt_svr_read_write_auth_test,
+ .flags = BLE_GATT_CHR_F_READ_AUTHEN |
+ BLE_GATT_CHR_F_READ |
+ BLE_GATT_CHR_F_WRITE_AUTHEN |
BLE_GATT_CHR_F_WRITE |
BLE_GATT_CHR_F_WRITE_AUTHEN,
- .arg = &gatt_values[7],
- .val_handle = &gatt_values[7].val_handle,
}, {
- .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_AUTHOR),
- .access_cb = gatt_svr_access_cb,
- .flags = BLE_GATT_CHR_F_READ |
- BLE_GATT_CHR_F_READ_AUTHOR |
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_RELIABLE_WRITE),
+ .access_cb = gatt_svr_rel_write_test,
+ .flags = BLE_GATT_CHR_F_WRITE |
+ BLE_GATT_CHR_F_RELIABLE_WRITE,
+ }, {
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_READ_WRITE_ENC),
+ .access_cb = gatt_svr_read_write_enc_test,
+ .flags = BLE_GATT_CHR_F_READ_ENC |
+ BLE_GATT_CHR_F_READ |
BLE_GATT_CHR_F_WRITE |
- BLE_GATT_CHR_F_WRITE_AUTHOR,
- .arg = &gatt_values[8],
- .val_handle = &gatt_values[8].val_handle,
-
- .descriptors = (struct ble_gatt_dsc_def[]){ {
- .uuid = PTS_UUID_DECLARE(PTS_DSC_READ),
- .access_cb = gatt_svr_access_cb,
- .att_flags = BLE_ATT_F_READ,
- .arg = &gatt_values[9],
- }, {
- .uuid = PTS_UUID_DECLARE(PTS_DSC_WRITE),
- .access_cb = gatt_svr_access_cb,
- .att_flags = BLE_ATT_F_WRITE,
- .arg = &gatt_values[10],
- }, {
- .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_ENC),
- .access_cb = gatt_svr_access_cb,
- .att_flags = BLE_ATT_F_READ |
- BLE_ATT_F_READ_ENC |
- BLE_ATT_F_WRITE |
- BLE_ATT_F_WRITE_ENC,
- .min_key_size = 0x0f,
- .arg = &gatt_values[11],
- }, {
- .uuid = PTS_UUID_DECLARE(PTS_DSC_READ_WRITE_AUTHEN),
- .access_cb = gatt_svr_access_cb,
- .att_flags = BLE_ATT_F_READ |
- BLE_ATT_F_READ_AUTHEN |
- BLE_ATT_F_WRITE |
- BLE_ATT_F_WRITE_AUTHEN,
- .arg = &gatt_values[12],
- }, {
- 0, /* No more descriptors in this characteristic. */
- } }
+ BLE_GATT_CHR_F_WRITE_ENC,
+ .min_key_size = 0x16,
+ }, {
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE),
+ .access_cb = gatt_svr_read_write_long_test,
+ .flags = BLE_GATT_CHR_F_WRITE |
+ BLE_GATT_CHR_F_READ,
+ }, {
+ .uuid = PTS_UUID_DECLARE(PTS_LONG_CHR_READ_WRITE_ALT),
+ .access_cb = gatt_svr_read_write_long_test,
+ .flags = BLE_GATT_CHR_F_WRITE |
+ BLE_GATT_CHR_F_READ,
+ }, {
+ .uuid = PTS_UUID_DECLARE(PTS_CHR_NOTIFY),
+ .access_cb = gatt_svr_read_write_test,
+ .val_handle = ¬ify_handle,
+ .flags = BLE_GATT_CHR_F_NOTIFY |
+ BLE_GATT_CHR_F_INDICATE,
}, {
0, /* No more characteristics in this service. */
} },
},
{
+ .type = BLE_GATT_SVC_TYPE_PRIMARY,
+ .uuid = PTS_UUID_DECLARE_ALT(PTS_SVC),
+ .characteristics = (struct ble_gatt_chr_def[]) { {
+ .uuid = PTS_UUID_DECLARE_ALT(PTS_CHR_READ_WRITE),
+ .access_cb = gatt_svr_read_write_test,
+ .flags = BLE_GATT_CHR_F_WRITE |
+ BLE_GATT_CHR_F_READ,
+ }, {
+ 0, /* No more characteristics in this service */
+ } },
+ },
+
+ {
0, /* No more services. */
},
};
-static void init_gatt_values(void)
+static int
+gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
+ void *dst, uint16_t *len)
{
- int i = 0;
- const struct ble_gatt_svc_def *svc;
- const struct ble_gatt_chr_def *chr;
- const struct ble_gatt_dsc_def *dsc;
-
- /* GATT/SR/GAR/BV-05-C fails when a characteristic value is empty */
-
- for (svc = gatt_svr_svcs; svc && svc->uuid; svc++) {
- for (chr = svc->characteristics; chr && chr->uuid; chr++) {
- assert(i < SERVER_MAX_VALUES);
- gatt_values[i].type = GATT_VALUE_TYPE_CHR;
- gatt_values[i].ptr = (void *)chr;
- gatt_values[i].buf = os_msys_get(0, 0);
- os_mbuf_extend(gatt_values[i].buf, 1);
- ++i;
-
- for (dsc = chr->descriptors; dsc && dsc->uuid; dsc++) {
- assert(i < SERVER_MAX_VALUES);
- gatt_values[i].type = GATT_VALUE_TYPE_DSC;
- gatt_values[i].ptr = (void *)dsc;
- gatt_values[i].buf = os_msys_get(0, 0);
- os_mbuf_extend(gatt_values[i].buf, 1);
- ++i;
- }
- }
- }
+ uint16_t om_len;
+ int rc;
- for (svc = gatt_svr_inc_svcs; svc && svc->uuid; svc++) {
- for (chr = svc->characteristics; chr && chr->uuid; chr++) {
- assert(i < SERVER_MAX_VALUES);
- gatt_values[i].type = GATT_VALUE_TYPE_CHR;
- gatt_values[i].ptr = (void *)chr;
- gatt_values[i].buf = os_msys_get(0, 0);
- os_mbuf_extend(gatt_values[i].buf, 1);
- ++i;
-
- for (dsc = chr->descriptors; dsc && dsc->uuid; dsc++) {
- assert(i < SERVER_MAX_VALUES);
- gatt_values[i].type = GATT_VALUE_TYPE_DSC;
- gatt_values[i].ptr = (void *)dsc;
- gatt_values[i].buf = os_msys_get(0, 0);
- os_mbuf_extend(gatt_values[i].buf, 1);
- ++i;
- }
- }
+ om_len = OS_MBUF_PKTLEN(om);
+ if (om_len < min_len || om_len > max_len) {
+ return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
-}
-/* Convert UUID from BTP command to bt_uuid */
-static u8_t btp2bt_uuid(const u8_t *uuid, u8_t len,
- ble_uuid_any_t *bt_uuid)
-{
- u16_t le16;
-
- switch (len) {
- case 0x02: /* UUID 16 */
- bt_uuid->u.type = BLE_UUID_TYPE_16;
- memcpy(&le16, uuid, sizeof(le16));
- BLE_UUID16(bt_uuid)->value = sys_le16_to_cpu(le16);
- break;
- case 0x10: /* UUID 128*/
- bt_uuid->u.type = BLE_UUID_TYPE_128;
- memcpy(BLE_UUID128(bt_uuid)->value, uuid, 16);
- break;
- default:
- return BTP_STATUS_FAILED;
+ rc = ble_hs_mbuf_to_flat(om, dst, max_len, len);
+ if (rc != 0) {
+ return BLE_ATT_ERR_UNLIKELY;
}
- return BTP_STATUS_SUCCESS;
+ return 0;
}
-static void supported_commands(u8_t *data, u16_t len)
+static uint16_t
+extract_uuid16_from_pts_uuid128(const ble_uuid_t *uuid)
{
- u8_t cmds[4];
- struct gatt_read_supported_commands_rp *rp = (void *) cmds;
-
- SYS_LOG_DBG("");
-
- memset(cmds, 0, sizeof(cmds));
-
- tester_set_bit(cmds, GATT_READ_SUPPORTED_COMMANDS);
- tester_set_bit(cmds, GATT_ADD_SERVICE);
- tester_set_bit(cmds, GATT_ADD_CHARACTERISTIC);
- tester_set_bit(cmds, GATT_ADD_DESCRIPTOR);
- tester_set_bit(cmds, GATT_ADD_INCLUDED_SERVICE);
- tester_set_bit(cmds, GATT_SET_VALUE);
- tester_set_bit(cmds, GATT_START_SERVER);
- tester_set_bit(cmds, GATT_SET_ENC_KEY_SIZE);
- tester_set_bit(cmds, GATT_EXCHANGE_MTU);
- tester_set_bit(cmds, GATT_DISC_ALL_PRIM_SVCS);
- tester_set_bit(cmds, GATT_DISC_PRIM_UUID);
- tester_set_bit(cmds, GATT_FIND_INCLUDED);
- tester_set_bit(cmds, GATT_DISC_ALL_CHRC);
- tester_set_bit(cmds, GATT_DISC_CHRC_UUID);
- tester_set_bit(cmds, GATT_DISC_ALL_DESC);
- tester_set_bit(cmds, GATT_READ);
- tester_set_bit(cmds, GATT_READ_LONG);
- tester_set_bit(cmds, GATT_READ_MULTIPLE);
- tester_set_bit(cmds, GATT_WRITE_WITHOUT_RSP);
-#if 0
- tester_set_bit(cmds, GATT_SIGNED_WRITE_WITHOUT_RSP);
-#endif
- tester_set_bit(cmds, GATT_WRITE);
- tester_set_bit(cmds, GATT_WRITE_LONG);
- tester_set_bit(cmds, GATT_CFG_NOTIFY);
- tester_set_bit(cmds, GATT_CFG_INDICATE);
- tester_set_bit(cmds, GATT_GET_ATTRIBUTES);
- tester_set_bit(cmds, GATT_GET_ATTRIBUTE_VALUE);
+ const uint8_t *u8ptr;
+ uint16_t uuid16;
- tester_send(BTP_SERVICE_ID_GATT, GATT_READ_SUPPORTED_COMMANDS,
- CONTROLLER_INDEX, (u8_t *) rp, sizeof(cmds));
+ u8ptr = BLE_UUID128(uuid)->value;
+ uuid16 = u8ptr[12];
+ uuid16 |= (uint16_t)u8ptr[13] << 8;
+ return uuid16;
}
-enum attr_type {
- BLE_GATT_ATTR_SVC = 0,
- BLE_GATT_ATTR_CHR,
- BLE_GATT_ATTR_DSC,
-};
-
-struct find_attr_data {
- ble_uuid_any_t *uuid;
- int attr_type;
- void *ptr;
- uint16_t handle;
-};
-
-static void find_attr_by_uuid_cb(const struct ble_gatt_svc_def *svc,
- uint16_t handle, uint16_t end_group_handle,
- void *arg)
+static int
+gatt_svr_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- struct find_attr_data *foreach = arg;
- const struct ble_gatt_svc_def **includes;
- const struct ble_gatt_chr_def *chr;
- const struct ble_gatt_dsc_def *dsc;
+ uint16_t uuid16;
+ int rc;
- SYS_LOG_DBG("");
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
- if (foreach->attr_type == BLE_GATT_ATTR_SVC &&
- ble_uuid_cmp(&foreach->uuid->u, svc->uuid) == 0) {
- foreach->ptr = (void *) svc;
- foreach->handle = handle;
- return;
- }
- handle += 1;
-
- if (svc->includes) {
- for (includes = &svc->includes[0];
- *includes != NULL; ++includes) {
- handle += 1;
- }
+ switch (uuid16) {
+ case PTS_CHR_READ_WRITE:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_short_val,
+ &gatt_svr_pts_static_short_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_short_val,
+ sizeof gatt_svr_pts_static_short_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
-
- for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
- if (foreach->attr_type == BLE_GATT_ATTR_CHR &&
- ble_uuid_cmp(&foreach->uuid->u, chr->uuid) == 0) {
- foreach->ptr = (void *) chr;
- foreach->handle = handle;
- return;
- }
- handle += 2;
-
- if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
- (chr->flags & BLE_GATT_CHR_F_INDICATE)) {
- if (foreach->attr_type == BLE_GATT_ATTR_DSC &&
- ble_uuid_cmp(&foreach->uuid->u, uuid_ccc) == 0) {
- foreach->ptr = (void *) &cccd_def;
- foreach->handle = handle;
- }
- handle += 1;
- }
-
- for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
- if (foreach->attr_type == BLE_GATT_ATTR_DSC &&
- ble_uuid_cmp(&foreach->uuid->u, dsc->uuid) == 0) {
- foreach->ptr = (void *) dsc;
- foreach->handle = handle;
- return;
- }
- handle += 1;
- }
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
}
-static void find_attr_by_handle_cb(const struct ble_gatt_svc_def *svc,
- uint16_t handle, uint16_t end_group_handle,
- void *arg)
+static int
+gatt_svr_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- struct find_attr_data *foreach = arg;
- const struct ble_gatt_svc_def **includes;
- const struct ble_gatt_chr_def *chr;
- const struct ble_gatt_dsc_def *dsc;
-
- SYS_LOG_DBG("");
+ uint16_t uuid16;
+ int rc;
- handle += 1;
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
- if (svc->includes) {
- for (includes = &svc->includes[0];
- *includes != NULL; ++includes) {
- handle += 1;
- }
+ switch (uuid16) {
+ case PTS_LONG_CHR_READ_WRITE:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_long_val,
+ &gatt_svr_pts_static_long_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
+ sizeof gatt_svr_pts_static_long_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
+ case PTS_LONG_CHR_READ_WRITE_ALT:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_long_val,
+ &gatt_svr_pts_static_long_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
+ sizeof gatt_svr_pts_static_long_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
-
- for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
- if (handle == foreach->handle) {
- foreach->attr_type = BLE_GATT_ATTR_CHR;
- foreach->ptr = (void *) chr;
- return;
- }
- handle += 2;
-
- if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
- (chr->flags & BLE_GATT_CHR_F_INDICATE)) {
- handle += 1;
- }
-
- for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
- if (handle == foreach->handle) {
- foreach->attr_type = BLE_GATT_ATTR_DSC;
- foreach->ptr = (void *) dsc;
- return;
- }
- handle += 1;
- }
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
}
-static void add_service(u8_t *data, u16_t len)
+static int
+gatt_svr_read_write_auth_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- const struct gatt_add_service_cmd *cmd = (void *) data;
- struct gatt_add_service_rp rp;
- const struct ble_gatt_svc_def *svc;
- struct find_attr_data find_data;
- ble_uuid_any_t uuid;
- int type;
-
- SYS_LOG_DBG("");
+ uint16_t uuid16;
+ int rc;
- if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
- SYS_LOG_ERR("Invalid service UUID");
- goto fail;
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
+
+ switch (uuid16) {
+ case PTS_CHR_READ_WRITE_AUTHEN:
+ if (ctxt->op == BLE_GATT_CHR_F_WRITE_AUTHEN) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_val,
+ &gatt_svr_pts_static_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_CHR_F_READ_AUTHEN) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
+ sizeof gatt_svr_pts_static_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ } else if (BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_val,
+ &gatt_svr_pts_static_val, NULL);
+ return rc;
+ } else if (BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
+ sizeof gatt_svr_pts_static_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
-
- switch (cmd->type) {
- case GATT_SERVICE_PRIMARY:
- type = BLE_GATT_SVC_TYPE_PRIMARY;
- break;
- case GATT_SERVICE_SECONDARY:
- type = BLE_GATT_SVC_TYPE_SECONDARY;
- break;
default:
- SYS_LOG_ERR("Invalid service type");
- goto fail;
- }
-
- memset(&find_data, 0, sizeof(find_data));
-
- find_data.uuid = &uuid;
- find_data.attr_type = BLE_GATT_ATTR_SVC;
-
- ble_gatts_lcl_svc_foreach(find_attr_by_uuid_cb, &find_data);
-
- svc = find_data.ptr;
- if (svc == NULL) {
- SYS_LOG_ERR("Could not find service");
- goto fail;
- }
-
- if (type != svc->type) {
- SYS_LOG_ERR("Service type mismatch");
- goto fail;
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
-
- rp.svc_id = find_data.handle;
-
- tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_SERVICE, CONTROLLER_INDEX,
- (u8_t *) &rp, sizeof(rp));
-
- return;
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_ADD_SERVICE, CONTROLLER_INDEX,
- BTP_STATUS_FAILED);
}
-static size_t read_value(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt,
- void *arg)
+static int
+gatt_svr_read_write_enc_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- const struct gatt_value *value = arg;
- char str[BLE_UUID_STR_LEN];
+ uint16_t uuid16;
int rc;
- SYS_LOG_DBG("");
-
- memset(str, '\0', sizeof(str));
-
- if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
- if (ctxt->chr->flags & BLE_GATT_CHR_F_READ_AUTHOR) {
- return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
- }
-
- ble_uuid_to_str(ctxt->chr->uuid, str);
- } else {
- if (ctxt->dsc->att_flags & BLE_ATT_F_READ_AUTHOR) {
- return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
- }
-
- ble_uuid_to_str(ctxt->dsc->uuid, str);
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
+
+ switch (uuid16) {
+ case PTS_CHR_READ_WRITE_ENC:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
+ sizeof gatt_svr_pts_static_val);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_CHR_F_READ_ENC) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
+ sizeof gatt_svr_pts_static_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_val,
+ &gatt_svr_pts_static_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_CHR_F_WRITE_ENC) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_val,
+ &gatt_svr_pts_static_val, NULL);
+ return rc;
+ }
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
-
- rc = os_mbuf_appendfrom(ctxt->om, value->buf,
- 0, os_mbuf_len(value->buf));
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
-}
-
-static void attr_value_changed_ev(u16_t handle, struct os_mbuf *data)
-{
- struct gatt_attr_value_changed_ev *ev;
- struct os_mbuf *buf = os_msys_get(0, 0);
-
- SYS_LOG_DBG("");
-
- net_buf_simple_init(buf, 0);
- ev = net_buf_simple_add(buf, sizeof(*ev));
-
- ev->handle = sys_cpu_to_le16(handle);
- ev->data_length = sys_cpu_to_le16(os_mbuf_len(data));
- os_mbuf_appendfrom(buf, data, 0, os_mbuf_len(data));
-
- tester_send_buf(BTP_SERVICE_ID_GATT, GATT_EV_ATTR_VALUE_CHANGED,
- CONTROLLER_INDEX, buf);
}
-static size_t write_value(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt,
- void *arg)
+static int
+gatt_svr_dsc_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- struct gatt_value *value = arg;
- uint16_t write_len, current_len;
+ uint16_t uuid16;
int rc;
- SYS_LOG_DBG("");
-
- if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- if (ctxt->chr->flags & BLE_GATT_CHR_F_WRITE_AUTHOR) {
- return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
- }
- } else {
- if (ctxt->dsc->att_flags & BLE_ATT_F_WRITE_AUTHOR) {
- return BLE_ATT_ERR_INSUFFICIENT_AUTHOR;
- }
- }
-
- write_len = os_mbuf_len(ctxt->om);
- current_len = os_mbuf_len(value->buf);
-
- SYS_LOG_DBG("current_len = %d", current_len);
- SYS_LOG_DBG("write_len = %d", write_len);
- if (write_len > current_len) {
- return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
+
+ switch (uuid16) {
+ case PTS_DSC_READ_WRITE:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_short_val,
+ &gatt_svr_pts_static_short_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_short_val,
+ sizeof gatt_svr_pts_static_short_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
-
- os_mbuf_adj(value->buf, -current_len);
- rc = os_mbuf_appendfrom(value->buf, ctxt->om, 0, write_len);
- if (rc != 0) {
+ default:
+ assert(0);
return BLE_ATT_ERR_UNLIKELY;
}
-
- attr_value_changed_ev(attr_handle, value->buf);
-
- return 0;
}
-
-static int gatt_svr_access_cb(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt,
- void *arg)
-{
- SYS_LOG_DBG("");
-
- switch (ctxt->op) {
- case BLE_GATT_ACCESS_OP_READ_CHR:
- case BLE_GATT_ACCESS_OP_READ_DSC:
- return read_value(conn_handle, attr_handle,
- ctxt, arg);
- case BLE_GATT_ACCESS_OP_WRITE_CHR:
- case BLE_GATT_ACCESS_OP_WRITE_DSC:
- return write_value(conn_handle, attr_handle,
- ctxt, arg);
- default:
- assert(0);
- return BLE_ATT_ERR_UNLIKELY;
- }
-
- /* Unknown characteristic; the nimble stack should not have called this
- * function.
- */
- assert(0);
- return BLE_ATT_ERR_UNLIKELY;
-}
-
-static void add_characteristic(u8_t *data, u16_t len)
+static int
+gatt_svr_dsc_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- const struct gatt_add_characteristic_cmd *cmd = (void *) data;
- struct gatt_add_characteristic_rp rp;
- const struct ble_gatt_chr_def *chr;
- struct find_attr_data find_data;
- ble_uuid_any_t uuid;
- uint16_t flags = 0;
- int i;
-
- SYS_LOG_DBG("");
-
- if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
- SYS_LOG_ERR("Invalid characteristic UUID");
- goto fail;
- }
-
- if (cmd->svc_id) {
- SYS_LOG_ERR("Characteristic must be added sequentially");
- goto fail;
- }
-
- memset(&find_data, 0, sizeof(find_data));
-
- find_data.uuid = &uuid;
- find_data.attr_type = BLE_GATT_ATTR_CHR;
-
- ble_gatts_lcl_svc_foreach(find_attr_by_uuid_cb, &find_data);
+ uint16_t uuid16;
+ int rc;
- chr = find_data.ptr;
- if (chr == NULL) {
- SYS_LOG_ERR("Could not find characteristic");
- goto fail;
- }
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
- for (i = 0; i < 8; ++i) {
- if (cmd->permissions & BIT(i)) {
- flags |= gatt_chr_perm_map[i];
- }
+ switch (uuid16) {
+ case PTS_LONG_DSC_READ_WRITE:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_long_val,
+ &gatt_svr_pts_static_long_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
+ sizeof gatt_svr_pts_static_long_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
-
- if ((chr->flags > 0) && ((flags & chr->flags) == 0)) {
- SYS_LOG_ERR("Invalid flags");
- goto fail;
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
-
- rp.char_id = find_data.handle;
-
- tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_CHARACTERISTIC,
- CONTROLLER_INDEX, (u8_t *) &rp, sizeof(rp));
- return;
-
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_ADD_CHARACTERISTIC,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
-static void add_descriptor(u8_t *data, u16_t len)
+static int
+gatt_svr_dsc_read_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- const struct gatt_add_descriptor_cmd *cmd = (void *) data;
- struct gatt_add_descriptor_rp rp;
- const struct ble_gatt_dsc_def *dsc;
- struct find_attr_data find_data;
- ble_uuid_any_t uuid;
- uint16_t att_flags = 0;
- int i;
-
- SYS_LOG_DBG("");
-
- if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
- SYS_LOG_ERR("Invalid descriptor UUID");
- goto fail;
- }
-
- if (cmd->char_id) {
- SYS_LOG_ERR("Descriptor must be added sequentially");
- goto fail;
- }
-
- memset(&find_data, 0, sizeof(find_data));
-
- find_data.uuid = &uuid;
- find_data.attr_type = BLE_GATT_ATTR_DSC;
-
- ble_gatts_lcl_svc_foreach(find_attr_by_uuid_cb, &find_data);
-
- dsc = find_data.ptr;
- if (dsc == NULL) {
- SYS_LOG_ERR("Could not find descriptor");
- goto fail;
- }
+ uint16_t uuid16;
+ int rc;
- att_flags = cmd->permissions;
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
- for (i = 0; i < 8; ++i) {
- if (cmd->permissions & BIT(i)) {
- att_flags |= gatt_dsc_perm_map[i];
- }
+ switch (uuid16) {
+ case PTS_DSC_READ:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
+ sizeof gatt_svr_pts_static_long_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
-
- if ((att_flags & dsc->att_flags) == 0) {
- SYS_LOG_ERR("Invalid flags");
- goto fail;
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
-
- rp.desc_id = find_data.handle;
-
- tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_DESCRIPTOR, CONTROLLER_INDEX,
- (u8_t *) &rp, sizeof(rp));
- return;
-
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_ADD_DESCRIPTOR,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
-static void add_included(u8_t *data, u16_t len)
+static int
+gatt_svr_write_no_rsp_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- const struct gatt_add_included_service_cmd *cmd = (void *) data;
- struct gatt_add_included_service_rp rp;
- u16_t included_service_id = 0;
-
- included_service_id = cmd->svc_id;
+ uint16_t uuid16;
+ int rc;
- rp.included_service_id = sys_cpu_to_le16(included_service_id);
- tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_INCLUDED_SERVICE,
- CONTROLLER_INDEX, (u8_t *) &rp, sizeof(rp));
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
+
+ switch (uuid16) {
+ case PTS_CHR_WRITE_NO_RSP:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_short_val,
+ &gatt_svr_pts_static_short_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_short_val,
+ sizeof gatt_svr_pts_static_short_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
+ }
}
-static void set_value(u8_t *data, u16_t len)
+static int
+gatt_svr_rel_write_test(uint16_t conn_handle, uint16_t attr_handle,
+ struct ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- const struct gatt_set_value_cmd *cmd = (void *) data;
- const struct ble_gatt_chr_def *chr;
- struct find_attr_data find_data;
- struct gatt_value *gatt_value = NULL;
- u16_t value_len;
- const u8_t *value;
-
- SYS_LOG_DBG("%d id", cmd->attr_id);
-
- memset(&find_data, 0, sizeof(find_data));
-
- find_data.handle = sys_le16_to_cpu(cmd->attr_id);
-
- ble_gatts_lcl_svc_foreach(find_attr_by_handle_cb, &find_data);
+ uint16_t uuid16;
+ int rc;
- if (find_data.ptr == NULL) {
- SYS_LOG_ERR("Could not find attribute");
- goto fail;
- }
+ uuid16 = extract_uuid16_from_pts_uuid128(ctxt->chr->uuid);
+ assert(uuid16 != 0);
- if (find_data.attr_type == BLE_GATT_ATTR_CHR) {
- gatt_value = ((struct ble_gatt_chr_def *)find_data.ptr)->arg;
- } else if (find_data.attr_type == BLE_GATT_ATTR_DSC) {
- gatt_value = ((struct ble_gatt_dsc_def *)find_data.ptr)->arg;
+ switch (uuid16) {
+ case PTS_CHR_RELIABLE_WRITE:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_val,
+ &gatt_svr_pts_static_val, NULL);
+ return rc;
}
- assert(gatt_value != NULL);
-
- value_len = sys_le16_to_cpu(cmd->len);
- value = cmd->value;
-
- os_mbuf_adj(gatt_value->buf, - os_mbuf_len(gatt_value->buf));
- os_mbuf_append(gatt_value->buf, value, value_len);
-
- SYS_LOG_DBG("os_mbuf_len = %d", os_mbuf_len(gatt_value->buf));
-
- if (gatt_value->type == GATT_VALUE_TYPE_CHR) {
- chr = gatt_value->ptr;
- if (chr->flags & BLE_GATT_CHR_F_INDICATE ||
- chr->flags & BLE_GATT_CHR_F_NOTIFY) {
- ble_gatts_chr_updated(*chr->val_handle);
- }
+ default:
+ assert(0);
+ return BLE_ATT_ERR_UNLIKELY;
}
-
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_VALUE, CONTROLLER_INDEX,
- BTP_STATUS_SUCCESS);
- return;
-
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_VALUE,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
static void start_server(u8_t *data, u16_t len)
@@ -909,79 +558,115 @@ static void start_server(u8_t *data, u16_t len)
(u8_t *) &rp, sizeof(rp));
}
-static void set_enc_key_size(u8_t *data, u16_t len)
+/* Convert UUID from BTP command to bt_uuid */
+static u8_t btp2bt_uuid(const u8_t *uuid, u8_t len,
+ ble_uuid_any_t *bt_uuid)
{
- const struct gatt_set_enc_key_size_cmd *cmd = (void *) data;
- struct find_attr_data find_data;
- struct gatt_value *val = NULL;
- u8_t status = BTP_STATUS_SUCCESS;
+ u16_t le16;
- /* Fail if requested key size is invalid */
- if (cmd->key_size < 0x07 || cmd->key_size > 0x0f) {
- status = BTP_STATUS_FAILED;
- goto done;
+ switch (len) {
+ case 0x02: /* UUID 16 */
+ bt_uuid->u.type = BLE_UUID_TYPE_16;
+ memcpy(&le16, uuid, sizeof(le16));
+ BLE_UUID16(bt_uuid)->value = sys_le16_to_cpu(le16);
+ break;
+ case 0x10: /* UUID 128*/
+ bt_uuid->u.type = BLE_UUID_TYPE_128;
+ memcpy(BLE_UUID128(bt_uuid)->value, uuid, 16);
+ break;
+ default:
+ return BTP_STATUS_FAILED;
}
+ return BTP_STATUS_SUCCESS;
+}
- memset(&find_data, 0, sizeof(find_data));
-
- find_data.handle = sys_le16_to_cpu(cmd->attr_id);
+/*
+ * gatt_buf - cache used by a gatt client (to cache data read/discovered)
+ * and gatt server (to store attribute user_data).
+ * It is not intended to be used by client and server at the same time.
+ */
+static struct {
+ u16_t len;
+ u8_t buf[MAX_BUFFER_SIZE];
+} gatt_buf;
- ble_gatts_lcl_svc_foreach(find_attr_by_handle_cb, &find_data);
+static void *gatt_buf_add(const void *data, size_t len)
+{
+ void *ptr = gatt_buf.buf + gatt_buf.len;
- if (find_data.ptr == NULL) {
- SYS_LOG_ERR("Could not find attribute");
- status = BTP_STATUS_FAILED;
- goto done;
+ if ((len + gatt_buf.len) > MAX_BUFFER_SIZE) {
+ return NULL;
}
- if (find_data.attr_type == BLE_GATT_ATTR_CHR) {
- val = ((struct ble_gatt_chr_def *)find_data.ptr)->arg;
- } else if (find_data.attr_type == BLE_GATT_ATTR_DSC) {
- val = ((struct ble_gatt_dsc_def *)find_data.ptr)->arg;
+ if (data) {
+ memcpy(ptr, data, len);
+ } else {
+ (void)memset(ptr, 0, len);
}
- assert(val != NULL);
- assert(val->ptr != NULL);
+ gatt_buf.len += len;
- switch(val->type) {
- case GATT_VALUE_TYPE_CHR:
- ((struct ble_gatt_chr_def *) val->ptr)->min_key_size =
- cmd->key_size;
- break;
- case GATT_VALUE_TYPE_DSC:
- ((struct ble_gatt_dsc_def *) val->ptr)->min_key_size =
- cmd->key_size;
- break;
- default:
- break;
- }
+ SYS_LOG_DBG("%d/%d used", gatt_buf.len, MAX_BUFFER_SIZE);
-done:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_ENC_KEY_SIZE, CONTROLLER_INDEX,
- status);
+ return ptr;
}
-static int exchange_func(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- uint16_t mtu, void *arg)
+static void *gatt_buf_reserve(size_t len)
{
- SYS_LOG_DBG("");
+ return gatt_buf_add(NULL, len);
+}
+
+static void gatt_buf_clear(void)
+{
+ (void)memset(&gatt_buf, 0, sizeof(gatt_buf));
+}
+
+static void discover_destroy(void)
+{
+ gatt_buf_clear();
+}
+
+static void read_destroy()
+{
+ gatt_buf_clear();
+}
+
+static int read_cb(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ struct ble_gatt_attr *attr,
+ void *arg)
+{
+ struct gatt_read_rp *rp = (void *) gatt_buf.buf;
+ u8_t btp_opcode = (uint8_t) (int) arg;
+
+ SYS_LOG_DBG("status=%d", error->status);
- if (error->status) {
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ if (error->status != 0 && error->status != BLE_HS_EDONE) {
+ rp->att_response = (uint8_t) BLE_HS_ATT_ERR(error->status);
+ tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
+ read_destroy();
+ return 0;
+}
+ if (!gatt_buf_add(attr->om->om_data, attr->om->om_len)) {
+ tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ read_destroy();
return 0;
}
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU, CONTROLLER_INDEX,
- BTP_STATUS_SUCCESS);
+ rp->data_length += attr->om->om_len;
+ tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
+ read_destroy();
return 0;
}
-static void exchange_mtu(u8_t *data, u16_t len)
+static void read(u8_t *data, u16_t len)
{
+ const struct gatt_read_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
int rc;
@@ -992,72 +677,63 @@ static void exchange_mtu(u8_t *data, u16_t len)
goto fail;
}
- if (ble_gattc_exchange_mtu(conn.conn_handle, exchange_func, NULL)) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
goto fail;
}
- return;
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
-}
+ if (ble_gattc_read(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
+ read_cb, (void *)GATT_READ)) {
+ discover_destroy();
+ goto fail;
+ }
+ return;
-static void discover_destroy(void)
-{
- gatt_buf_clear();
+fail:
+tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ, CONTROLLER_INDEX,
+ BTP_STATUS_FAILED);
}
-static int disc_prim_uuid_cb(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- const struct ble_gatt_svc *gatt_svc, void *arg)
+static int read_long_cb(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ struct ble_gatt_attr *attr,
+ void *arg)
{
- struct gatt_disc_prim_uuid_rp *rp = (void *) gatt_buf.buf;
- struct gatt_service *service;
- const ble_uuid_any_t *uuid;
- u8_t uuid_length;
- u8_t opcode = (u8_t) (int) arg;
+ struct gatt_read_rp *rp = (void *) gatt_buf.buf;
+ u8_t btp_opcode = (uint8_t) (int) arg;
- SYS_LOG_DBG("");
+ SYS_LOG_DBG("status=%d", error->status);
- if (error->status != 0) {
- tester_send(BTP_SERVICE_ID_GATT, opcode,
+ if (error->status != 0 && error->status != BLE_HS_EDONE) {
+ rp->att_response = (uint8_t) BLE_HS_ATT_ERR(error->status);
+ tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
- discover_destroy();
+ read_destroy();
return 0;
}
- uuid = &gatt_svc->uuid;
- uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
-
- service = gatt_buf_reserve(sizeof(*service) + uuid_length);
- if (!service) {
- tester_rsp(BTP_SERVICE_ID_GATT, opcode,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
- discover_destroy();
- return BLE_HS_EDONE;
+ if (error->status == BLE_HS_EDONE) {
+ tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
+ read_destroy();
+ return 0;
}
- service->start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
- service->end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
- service->uuid_length = uuid_length;
-
- if (uuid->u.type == BLE_UUID_TYPE_16) {
- u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
-
- memcpy(service->uuid, &u16, uuid_length);
- } else {
- memcpy(service->uuid, BLE_UUID128(uuid)->value,
- uuid_length);
+ if (gatt_buf_add(attr->om->om_data, attr->om->om_len) == NULL) {
+ tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ read_destroy();
+ return 0;
}
- rp->services_count++;
+ rp->data_length += attr->om->om_len;
return 0;
}
-static void disc_all_prim_svcs(u8_t *data, u16_t len)
+static void read_long(u8_t *data, u16_t len)
{
+ const struct gatt_read_long_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
int rc;
@@ -1068,13 +744,14 @@ static void disc_all_prim_svcs(u8_t *data, u16_t len)
goto fail;
}
- if (!gatt_buf_reserve(sizeof(struct gatt_disc_all_prim_svcs_rp))) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
goto fail;
}
- if (ble_gattc_disc_all_svcs(conn.conn_handle,
- disc_prim_uuid_cb,
- (void *) GATT_DISC_ALL_PRIM_SVCS)) {
+ if (ble_gattc_read_long(conn.conn_handle,
+ sys_le16_to_cpu(cmd->handle),
+ sys_le16_to_cpu(cmd->offset),
+ read_long_cb, (void *)GATT_READ_LONG)) {
discover_destroy();
goto fail;
}
@@ -1082,104 +759,88 @@ static void disc_all_prim_svcs(u8_t *data, u16_t len)
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_PRIM_SVCS,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_LONG, CONTROLLER_INDEX,
+ BTP_STATUS_FAILED);
}
-static void disc_prim_uuid(u8_t *data, u16_t len)
+static void read_multiple(u8_t *data, u16_t len)
{
- const struct gatt_disc_prim_uuid_cmd *cmd = (void *) data;
+ const struct gatt_read_multiple_cmd *cmd = (void *) data;
+ u16_t handles[cmd->handles_count];
struct ble_gap_conn_desc conn;
- ble_uuid_any_t uuid;
- int rc;
+ int rc, i;
SYS_LOG_DBG("");
- rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
- if (rc) {
- goto fail;
+ for (i = 0; i < ARRAY_SIZE(handles); i++) {
+ handles[i] = sys_le16_to_cpu(cmd->handles[i]);
}
- if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
+ rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
+ if (rc) {
goto fail;
}
- if (!gatt_buf_reserve(sizeof(struct gatt_disc_prim_uuid_rp))) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
goto fail;
}
- if (ble_gattc_disc_svc_by_uuid(conn.conn_handle,
- &uuid.u, disc_prim_uuid_cb,
- (void *) GATT_DISC_PRIM_UUID)) {
+ if (ble_gattc_read_mult(conn.conn_handle, handles,
+ cmd->handles_count, read_cb, (void *)GATT_READ_MULTIPLE)) {
discover_destroy();
goto fail;
- }
+}
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_PRIM_UUID, CONTROLLER_INDEX,
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_MULTIPLE, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static int find_included_cb(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- const struct ble_gatt_svc *gatt_svc, void *arg)
+static void write_without_rsp(u8_t *data, u16_t len, u8_t op, bool sign)
{
- struct gatt_find_included_rp *rp = (void *) gatt_buf.buf;
- struct gatt_included *included;
- const ble_uuid_any_t *uuid;
- int service_handle = (int) arg;
- u8_t uuid_length;
+ const struct gatt_write_without_rsp_cmd *cmd = (void *) data;
+ struct ble_gap_conn_desc conn;
+ u8_t status = BTP_STATUS_SUCCESS;
+ int rc;
SYS_LOG_DBG("");
- if (error->status != 0) {
- tester_send(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED,
- CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
- discover_destroy();
- return 0;
+ rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
+ if (rc) {
+ status = BTP_STATUS_FAILED;
+ goto rsp;
}
- uuid = &gatt_svc->uuid;
- uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
-
-
- included = gatt_buf_reserve(sizeof(*included) + uuid_length);
- if (!included) {
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
- discover_destroy();
- return BLE_HS_EDONE;
+ if (ble_gattc_write_no_rsp_flat(conn.conn_handle,
+ sys_le16_to_cpu(cmd->handle), cmd->data,
+ sys_le16_to_cpu(cmd->data_length))) {
+ status = BTP_STATUS_FAILED;
}
- /* FIXME */
- included->included_handle = sys_cpu_to_le16(service_handle + 1 +
- rp->services_count);
- included->service.start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
- included->service.end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
- included->service.uuid_length = uuid_length;
-
- if (uuid->u.type == BLE_UUID_TYPE_16) {
- u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
+rsp:
+ tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status);
+}
- memcpy(included->service.uuid, &u16, uuid_length);
- } else {
- memcpy(included->service.uuid, BLE_UUID128(uuid)->value,
- uuid_length);
- }
+static int write_rsp(uint16_t conn_handle, const struct ble_gatt_error *error,
+ struct ble_gatt_attr *attr,
+ void *arg)
+{
+ uint8_t err = (uint8_t) error->status;
+ u8_t btp_opcode = (uint8_t) (int) arg;
- rp->services_count++;
+ SYS_LOG_DBG("");
+ tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, &err, sizeof(err));
return 0;
}
-static void find_included(u8_t *data, u16_t len)
+static void write(u8_t *data, u16_t len)
{
- const struct gatt_find_included_cmd *cmd = (void *) data;
+ const struct gatt_write_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
- uint16_t start_handle, end_handle;
- int service_handle_arg;
int rc;
SYS_LOG_DBG("");
@@ -1189,119 +850,121 @@ static void find_included(u8_t *data, u16_t len)
goto fail;
}
- if (!gatt_buf_reserve(sizeof(struct gatt_find_included_rp))) {
- goto fail;
- }
-
- start_handle = sys_le16_to_cpu(cmd->start_handle);
- end_handle = sys_le16_to_cpu(cmd->end_handle);
- service_handle_arg = start_handle;
-
- if (ble_gattc_find_inc_svcs(conn.conn_handle, start_handle, end_handle,
- find_included_cb,
- (void *)service_handle_arg)) {
- discover_destroy();
+ if (ble_gattc_write_flat(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
+ cmd->data, sys_le16_to_cpu(cmd->data_length),
+ write_rsp, (void *) GATT_WRITE)) {
goto fail;
}
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED, CONTROLLER_INDEX,
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static int disc_chrc_cb(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- const struct ble_gatt_chr *gatt_chr, void *arg)
+static void write_long(u8_t *data, u16_t len)
{
- struct gatt_disc_chrc_rp *rp = (void *) gatt_buf.buf;
- struct gatt_characteristic *chrc;
- const ble_uuid_any_t *uuid;
- u8_t btp_opcode = (uint8_t) (int) arg;
- u8_t uuid_length;
+ const struct gatt_write_long_cmd *cmd = (void *) data;
+ struct ble_gap_conn_desc conn;
+ struct os_mbuf *om = NULL;
+ int rc;
SYS_LOG_DBG("");
- if (error->status != 0) {
- tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
- CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
- discover_destroy();
- return 0;
+ rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
+ if (rc) {
+ goto fail;
}
- uuid = &gatt_chr->uuid;
- uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
+ om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
- chrc = gatt_buf_reserve(sizeof(*chrc) + uuid_length);
- if (!chrc) {
- tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
- discover_destroy();
- return BLE_HS_EDONE;
+ if (!om) {
+ SYS_LOG_ERR("Insufficient resources");
+ goto fail;
}
- chrc->characteristic_handle = sys_cpu_to_le16(gatt_chr->def_handle);
- chrc->properties = gatt_chr->properties;
- chrc->value_handle = sys_cpu_to_le16(gatt_chr->val_handle);
- chrc->uuid_length = uuid_length;
+ if (ble_gattc_write_long(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
+ sys_le16_to_cpu(cmd->offset), om, write_rsp,
+ (void *) GATT_WRITE_LONG)) {
+ goto fail;
+}
- if (uuid->u.type == BLE_UUID_TYPE_16) {
- u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
+ return;
- memcpy(chrc->uuid, &u16, uuid_length);
- } else {
- memcpy(chrc->uuid, BLE_UUID128(uuid)->value,
- uuid_length);
- }
+fail:
+ os_mbuf_free_chain(om);
- rp->characteristics_count++;
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE_LONG, CONTROLLER_INDEX,
+ BTP_STATUS_FAILED);
+}
+
+static int reliable_write_rsp(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ struct ble_gatt_attr *attrs,
+ uint8_t num_attrs,
+ void *arg)
+{
+ uint8_t err = (uint8_t) error->status;
+ SYS_LOG_DBG("Reliable write status %d", err);
+
+ tester_send(BTP_SERVICE_ID_GATT, GATT_RELIABLE_WRITE,
+ CONTROLLER_INDEX, &err, sizeof(err));
return 0;
}
-static void disc_all_chrc(u8_t *data, u16_t len)
+static void reliable_write(u8_t *data, u16_t len)
{
- const struct gatt_disc_all_chrc_cmd *cmd = (void *) data;
+ const struct gatt_reliable_write_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
- uint16_t start_handle, end_handle;
+ struct ble_gatt_attr attr;
+ struct os_mbuf *om = NULL;
int rc;
SYS_LOG_DBG("");
rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
if (rc) {
- SYS_LOG_DBG("Conn find failed");
goto fail;
}
- if (!gatt_buf_reserve(sizeof(struct gatt_disc_chrc_rp))) {
- SYS_LOG_DBG("Buf reserve failed");
+ om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
+ /* This is required, because Nimble checks if
+ * the data is longer than offset
+ */
+ if (os_mbuf_extend(om, sys_le16_to_cpu(cmd->offset) + 1) == NULL) {
goto fail;
}
- start_handle = sys_le16_to_cpu(cmd->start_handle);
- end_handle = sys_le16_to_cpu(cmd->end_handle);
+ attr.handle = sys_le16_to_cpu(cmd->handle);
+ attr.offset = sys_le16_to_cpu(cmd->offset);
+ attr.om = om;
- rc = ble_gattc_disc_all_chrs(conn.conn_handle, start_handle, end_handle,
- disc_chrc_cb, (void *)GATT_DISC_ALL_CHRC);
- if (rc) {
- discover_destroy();
+ if (ble_gattc_write_reliable(conn.conn_handle, &attr, 1,
+ reliable_write_rsp, NULL)) {
goto fail;
}
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_CHRC, CONTROLLER_INDEX,
+ os_mbuf_free_chain(om);
+
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE_LONG, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static void disc_chrc_uuid(u8_t *data, u16_t len)
+static struct bt_gatt_subscribe_params {
+ u16_t ccc_handle;
+ u16_t value;
+ u16_t value_handle;
+} subscribe_params;
+
+static void read_uuid(u8_t *data, u16_t len)
{
- const struct gatt_disc_chrc_uuid_cmd *cmd = (void *) data;
+ const struct gatt_read_uuid_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
- uint16_t start_handle, end_handle;
ble_uuid_any_t uuid;
int rc;
@@ -1316,16 +979,14 @@ static void disc_chrc_uuid(u8_t *data, u16_t len)
goto fail;
}
- if (!gatt_buf_reserve(sizeof(struct gatt_disc_chrc_rp))) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
goto fail;
}
- start_handle = sys_le16_to_cpu(cmd->start_handle);
- end_handle = sys_le16_to_cpu(cmd->end_handle);
-
- if (ble_gattc_disc_chrs_by_uuid(conn.conn_handle, start_handle,
- end_handle, &uuid.u, disc_chrc_cb,
- (void *)GATT_DISC_CHRC_UUID)) {
+ if (ble_gattc_read_by_uuid(conn.conn_handle,
+ sys_le16_to_cpu(cmd->start_handle),
+ sys_le16_to_cpu(cmd->end_handle), &uuid.u,
+ read_long_cb, (void *)GATT_READ_UUID)) {
discover_destroy();
goto fail;
}
@@ -1333,207 +994,106 @@ static void disc_chrc_uuid(u8_t *data, u16_t len)
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_CHRC_UUID, CONTROLLER_INDEX,
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static int disc_all_desc_cb(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- uint16_t chr_val_handle,
- const struct ble_gatt_dsc *gatt_dsc,
- void *arg)
+static int disc_prim_uuid_cb(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ const struct ble_gatt_svc *gatt_svc, void *arg)
{
- struct gatt_disc_all_desc_rp *rp = (void *) gatt_buf.buf;
- struct gatt_descriptor *dsc;
+ struct gatt_disc_prim_uuid_rp *rp = (void *) gatt_buf.buf;
+ struct gatt_service *service;
const ble_uuid_any_t *uuid;
u8_t uuid_length;
+ u8_t opcode = (u8_t) (int) arg;
SYS_LOG_DBG("");
if (error->status != 0) {
- tester_send(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC,
- CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
+ tester_send(BTP_SERVICE_ID_GATT, opcode,
+ CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
discover_destroy();
return 0;
}
- uuid = &gatt_dsc->uuid;
+ uuid = &gatt_svc->uuid;
uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
- dsc = gatt_buf_reserve(sizeof(*dsc) + uuid_length);
- if (!dsc) {
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ service = gatt_buf_reserve(sizeof(*service) + uuid_length);
+ if (!service) {
+ tester_rsp(BTP_SERVICE_ID_GATT, opcode,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
discover_destroy();
return BLE_HS_EDONE;
}
- dsc->descriptor_handle = sys_cpu_to_le16(gatt_dsc->handle);
- dsc->uuid_length = uuid_length;
+ service->start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
+ service->end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
+ service->uuid_length = uuid_length;
if (uuid->u.type == BLE_UUID_TYPE_16) {
u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
-
- memcpy(dsc->uuid, &u16, uuid_length);
+ memcpy(service->uuid, &u16, uuid_length);
} else {
- memcpy(dsc->uuid, BLE_UUID128(uuid)->value,
- uuid_length);
+ memcpy(service->uuid, BLE_UUID128(uuid)->value,
+ uuid_length);
}
- rp->descriptors_count++;
+ rp->services_count++;
return 0;
}
-static void disc_all_desc(u8_t *data, u16_t len)
+static int disc_all_desc_cb(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ uint16_t chr_val_handle,
+ const struct ble_gatt_dsc *gatt_dsc,
+ void *arg)
{
- const struct gatt_disc_all_desc_cmd *cmd = (void *) data;
- struct ble_gap_conn_desc conn;
- uint16_t start_handle, end_handle;
- int rc;
+ struct gatt_disc_all_desc_rp *rp = (void *) gatt_buf.buf;
+ struct gatt_descriptor *dsc;
+ const ble_uuid_any_t *uuid;
+ u8_t uuid_length;
SYS_LOG_DBG("");
- rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
- if (rc) {
- goto fail;
- }
-
- if (!gatt_buf_reserve(sizeof(struct gatt_disc_all_desc_rp))) {
- goto fail;
- }
-
- start_handle = sys_le16_to_cpu(cmd->start_handle) - 1;
- end_handle = sys_le16_to_cpu(cmd->end_handle);
-
- rc = ble_gattc_disc_all_dscs(conn.conn_handle, start_handle, end_handle,
- disc_all_desc_cb, NULL);
-
- SYS_LOG_DBG("rc=%d", rc);
-
- if (rc) {
- discover_destroy();
- goto fail;
- }
-
- return;
-
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC, CONTROLLER_INDEX,
- BTP_STATUS_FAILED);
-}
-
-static void read_destroy(void)
-{
- gatt_buf_clear();
-}
-
-static int read_cb(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- struct ble_gatt_attr *attr,
- void *arg)
-{
- struct gatt_read_rp *rp = (void *) gatt_buf.buf;
- u8_t btp_opcode = (uint8_t) (int) arg;
-
- SYS_LOG_DBG("status=%d", error->status);
-
- if (error->status != 0 && error->status != BLE_HS_EDONE) {
- rp->att_response = (uint8_t) BLE_HS_ATT_ERR(error->status);
- tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
- CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
- read_destroy();
- return 0;
- }
-
- if (!gatt_buf_add(attr->om->om_data, attr->om->om_len)) {
- tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
- read_destroy();
- return 0;
- }
-
- rp->data_length += attr->om->om_len;
-
- tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
- CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
- read_destroy();
-
- return 0;
-}
-
-static int read_long_cb(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- struct ble_gatt_attr *attr,
- void *arg)
-{
- struct gatt_read_rp *rp = (void *) gatt_buf.buf;
- u8_t btp_opcode = (uint8_t) (int) arg;
-
- SYS_LOG_DBG("status=%d", error->status);
-
- if (error->status != 0 && error->status != BLE_HS_EDONE) {
- rp->att_response = (uint8_t) BLE_HS_ATT_ERR(error->status);
- tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
+ if (error->status != 0) {
+ tester_send(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC,
CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
- read_destroy();
+ discover_destroy();
return 0;
}
- if (error->status == BLE_HS_EDONE) {
- tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
- CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
- read_destroy();
- return 0;
- }
+ uuid = &gatt_dsc->uuid;
+ uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
- if (gatt_buf_add(attr->om->om_data, attr->om->om_len) == NULL) {
- tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode,
+ dsc = gatt_buf_reserve(sizeof(*dsc) + uuid_length);
+ if (!dsc) {
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC,
CONTROLLER_INDEX, BTP_STATUS_FAILED);
- read_destroy();
- return 0;
- }
-
- rp->data_length += attr->om->om_len;
-
- return 0;
-}
-
-static void read(u8_t *data, u16_t len)
-{
- const struct gatt_read_cmd *cmd = (void *) data;
- struct ble_gap_conn_desc conn;
- int rc;
-
- SYS_LOG_DBG("");
-
- rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
- if (rc) {
- goto fail;
+ discover_destroy();
+ return BLE_HS_EDONE;
}
- if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
- goto fail;
- }
+ dsc->descriptor_handle = sys_cpu_to_le16(gatt_dsc->handle);
+ dsc->uuid_length = uuid_length;
- if (ble_gattc_read(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
- read_cb, (void *)GATT_READ)) {
- discover_destroy();
- goto fail;
+ if (uuid->u.type == BLE_UUID_TYPE_16) {
+ u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
+ memcpy(dsc->uuid, &u16, uuid_length);
+ } else {
+ memcpy(dsc->uuid, BLE_UUID128(uuid)->value, uuid_length);
}
- return;
+ rp->descriptors_count++;
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ, CONTROLLER_INDEX,
- BTP_STATUS_FAILED);
+ return 0;
}
-static void read_uuid(u8_t *data, u16_t len)
+static void disc_all_prim_svcs(u8_t *data, u16_t len)
{
- const struct gatt_read_uuid_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
- ble_uuid_any_t uuid;
int rc;
SYS_LOG_DBG("");
@@ -1543,19 +1103,12 @@ static void read_uuid(u8_t *data, u16_t len)
goto fail;
}
- if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
- goto fail;
- }
-
- if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_disc_all_prim_svcs_rp))) {
goto fail;
}
- if (ble_gattc_read_by_uuid(conn.conn_handle,
- sys_le16_to_cpu(cmd->start_handle),
- sys_le16_to_cpu(cmd->end_handle),
- &uuid.u,
- read_long_cb, (void *)GATT_READ_UUID)) {
+ if (ble_gattc_disc_all_svcs(conn.conn_handle, disc_prim_uuid_cb,
+ (void *) GATT_DISC_ALL_PRIM_SVCS)) {
discover_destroy();
goto fail;
}
@@ -1563,14 +1116,15 @@ static void read_uuid(u8_t *data, u16_t len)
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ, CONTROLLER_INDEX,
- BTP_STATUS_FAILED);
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_PRIM_SVCS,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
-static void read_long(u8_t *data, u16_t len)
+static void disc_all_desc(u8_t *data, u16_t len)
{
- const struct gatt_read_long_cmd *cmd = (void *) data;
+ const struct gatt_disc_all_desc_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
+ uint16_t start_handle, end_handle;
int rc;
SYS_LOG_DBG("");
@@ -1580,14 +1134,19 @@ static void read_long(u8_t *data, u16_t len)
goto fail;
}
- if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_disc_all_desc_rp))) {
goto fail;
}
- if (ble_gattc_read_long(conn.conn_handle,
- sys_le16_to_cpu(cmd->handle),
- sys_le16_to_cpu(cmd->offset),
- read_long_cb, (void *)GATT_READ_LONG)) {
+ start_handle = sys_le16_to_cpu(cmd->start_handle) - 1;
+ end_handle = sys_le16_to_cpu(cmd->end_handle);
+
+ rc = ble_gattc_disc_all_dscs(conn.conn_handle, start_handle, end_handle,
+ disc_all_desc_cb, NULL);
+
+ SYS_LOG_DBG("rc=%d", rc);
+
+ if (rc) {
discover_destroy();
goto fail;
}
@@ -1595,93 +1154,115 @@ static void read_long(u8_t *data, u16_t len)
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_LONG, CONTROLLER_INDEX,
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_DESC, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static void read_multiple(u8_t *data, u16_t len)
+static int find_included_cb(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ const struct ble_gatt_svc *gatt_svc, void *arg)
{
- const struct gatt_read_multiple_cmd *cmd = (void *) data;
- u16_t handles[cmd->handles_count];
- struct ble_gap_conn_desc conn;
- int rc, i;
+ struct gatt_find_included_rp *rp = (void *) gatt_buf.buf;
+ struct gatt_included *included;
+ const ble_uuid_any_t *uuid;
+ int service_handle = (int) arg;
+ u8_t uuid_length;
SYS_LOG_DBG("");
- for (i = 0; i < ARRAY_SIZE(handles); i++) {
- handles[i] = sys_le16_to_cpu(cmd->handles[i]);
+ if (error->status != 0) {
+ tester_send(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED,
+ CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
+ discover_destroy();
+ return 0;
}
- rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
- if (rc) {
- goto fail;
- }
+ uuid = &gatt_svc->uuid;
+ uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
- if (!gatt_buf_reserve(sizeof(struct gatt_read_rp))) {
- goto fail;
- }
- if (ble_gattc_read_mult(conn.conn_handle, handles,
- cmd->handles_count, read_cb,
- (void *)GATT_READ_MULTIPLE)) {
+ included = gatt_buf_reserve(sizeof(*included) + uuid_length);
+ if (!included) {
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
discover_destroy();
- goto fail;
+ return BLE_HS_EDONE;
}
- return;
+ /* FIXME */
+ included->included_handle = sys_cpu_to_le16(service_handle + 1 +
+ rp->services_count);
+ included->service.start_handle = sys_cpu_to_le16(gatt_svc->start_handle);
+ included->service.end_handle = sys_cpu_to_le16(gatt_svc->end_handle);
+ included->service.uuid_length = uuid_length;
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_READ_MULTIPLE, CONTROLLER_INDEX,
- BTP_STATUS_FAILED);
+ if (uuid->u.type == BLE_UUID_TYPE_16) {
+ u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
+ memcpy(included->service.uuid, &u16, uuid_length);
+ } else {
+ memcpy(included->service.uuid, BLE_UUID128(uuid)->value,
+ uuid_length);
+ }
+
+ rp->services_count++;
+
+ return 0;
}
-static void write_without_rsp(u8_t *data, u16_t len, u8_t op,
- bool sign)
+static int disc_chrc_cb(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ const struct ble_gatt_chr *gatt_chr, void *arg)
{
- const struct gatt_write_without_rsp_cmd *cmd = (void *) data;
- struct ble_gap_conn_desc conn;
- u8_t status = BTP_STATUS_SUCCESS;
- int rc;
+ struct gatt_disc_chrc_rp *rp = (void *) gatt_buf.buf;
+ struct gatt_characteristic *chrc;
+ const ble_uuid_any_t *uuid;
+ u8_t btp_opcode = (uint8_t) (int) arg;
+ u8_t uuid_length;
SYS_LOG_DBG("");
- rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
- if (rc) {
- status = BTP_STATUS_FAILED;
- goto rsp;
+ if (error->status != 0) {
+ tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, gatt_buf.buf, gatt_buf.len);
+ discover_destroy();
+ return 0;
}
- if (ble_gattc_write_no_rsp_flat(conn.conn_handle,
- sys_le16_to_cpu(cmd->handle),
- cmd->data,
- sys_le16_to_cpu(cmd->data_length))) {
- status = BTP_STATUS_FAILED;
+ uuid = &gatt_chr->uuid;
+ uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
+
+ chrc = gatt_buf_reserve(sizeof(*chrc) + uuid_length);
+ if (!chrc) {
+ tester_rsp(BTP_SERVICE_ID_GATT, btp_opcode,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ discover_destroy();
+ return BLE_HS_EDONE;
}
-rsp:
- tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status);
-}
+ chrc->characteristic_handle = sys_cpu_to_le16(gatt_chr->def_handle);
+ chrc->properties = gatt_chr->properties;
+ chrc->value_handle = sys_cpu_to_le16(gatt_chr->val_handle);
+ chrc->uuid_length = uuid_length;
-static int write_rsp(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- struct ble_gatt_attr *attr,
- void *arg)
-{
- uint8_t err = (uint8_t) error->status;
- u8_t btp_opcode = (uint8_t) (int) arg;
+ if (uuid->u.type == BLE_UUID_TYPE_16) {
+ u16_t u16 = sys_cpu_to_le16(BLE_UUID16(uuid)->value);
+ memcpy(chrc->uuid, &u16, uuid_length);
+ } else {
+ memcpy(chrc->uuid, BLE_UUID128(uuid)->value,
+ uuid_length);
+ }
- SYS_LOG_DBG("");
+ rp->characteristics_count++;
- tester_send(BTP_SERVICE_ID_GATT, btp_opcode,
- CONTROLLER_INDEX, &err,
- sizeof(err));
return 0;
}
-static void write(u8_t *data, u16_t len)
+static void disc_chrc_uuid(u8_t *data, u16_t len)
{
- const struct gatt_write_cmd *cmd = (void *) data;
+ const struct gatt_disc_chrc_uuid_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
+ uint16_t start_handle, end_handle;
+ ble_uuid_any_t uuid;
int rc;
SYS_LOG_DBG("");
@@ -1691,24 +1272,36 @@ static void write(u8_t *data, u16_t len)
goto fail;
}
- if (ble_gattc_write_flat(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
- cmd->data, sys_le16_to_cpu(cmd->data_length),
- write_rsp, (void *) GATT_WRITE)) {
+ if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
+ goto fail;
+ }
+
+ if (!gatt_buf_reserve(sizeof(struct gatt_disc_chrc_rp))) {
+ goto fail;
+ }
+
+ start_handle = sys_le16_to_cpu(cmd->start_handle);
+ end_handle = sys_le16_to_cpu(cmd->end_handle);
+
+ if (ble_gattc_disc_chrs_by_uuid(conn.conn_handle, start_handle,
+ end_handle, &uuid.u, disc_chrc_cb,
+ (void *)GATT_DISC_CHRC_UUID)) {
+ discover_destroy();
goto fail;
}
return;
fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE, CONTROLLER_INDEX,
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_CHRC_UUID, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static void write_long(u8_t *data, u16_t len)
+static void disc_prim_uuid(u8_t *data, u16_t len)
{
- const struct gatt_write_long_cmd *cmd = (void *) data;
+ const struct gatt_disc_prim_uuid_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
- struct os_mbuf *om = NULL;
+ ble_uuid_any_t uuid;
int rc;
SYS_LOG_DBG("");
@@ -1718,150 +1311,141 @@ static void write_long(u8_t *data, u16_t len)
goto fail;
}
- om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
+ if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
+ goto fail;
+ }
- if (!om) {
- SYS_LOG_ERR("Insufficient resources");
+ if (!gatt_buf_reserve(sizeof(struct gatt_disc_prim_uuid_rp))) {
goto fail;
}
- if (ble_gattc_write_long(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
- sys_le16_to_cpu(cmd->offset), om, write_rsp,
- (void *) GATT_WRITE_LONG)) {
+ if (ble_gattc_disc_svc_by_uuid(conn.conn_handle,
+ &uuid.u, disc_prim_uuid_cb,
+ (void *) GATT_DISC_PRIM_UUID)) {
+ discover_destroy();
goto fail;
}
return;
fail:
- os_mbuf_free_chain(om);
-
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE_LONG, CONTROLLER_INDEX,
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_PRIM_UUID, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static int reliable_write_rsp(uint16_t conn_handle,
- const struct ble_gatt_error *error,
- struct ble_gatt_attr *attrs,
- uint8_t num_attrs,
- void *arg)
-{
- uint8_t err = (uint8_t) error->status;
-
- SYS_LOG_DBG("");
-
- tester_send(BTP_SERVICE_ID_GATT, GATT_RELIABLE_WRITE,
- CONTROLLER_INDEX, &err,
- sizeof(err));
- return 0;
-}
-
-static void reliable_write(u8_t *data, u16_t len)
+static void disc_all_chrc(u8_t *data, u16_t len)
{
- const struct gatt_reliable_write_cmd *cmd = (void *) data;
+ const struct gatt_disc_all_chrc_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
- struct ble_gatt_attr attr;
- struct os_mbuf *om = NULL;
+ uint16_t start_handle, end_handle;
int rc;
SYS_LOG_DBG("");
rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
if (rc) {
+ SYS_LOG_DBG("Conn find failed");
goto fail;
}
- om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
- /* This is required, because Nimble checks if
- * the data is longer than offset
- */
- if (os_mbuf_extend(om, sys_le16_to_cpu(cmd->offset) + 1) == NULL) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_disc_chrc_rp))) {
+ SYS_LOG_DBG("Buf reserve failed");
goto fail;
}
- attr.handle = sys_le16_to_cpu(cmd->handle);
- attr.offset = sys_le16_to_cpu(cmd->offset);
- attr.om = om;
+ start_handle = sys_le16_to_cpu(cmd->start_handle);
+ end_handle = sys_le16_to_cpu(cmd->end_handle);
- if (ble_gattc_write_reliable(conn.conn_handle, &attr, 1,
- reliable_write_rsp, NULL)) {
+ rc = ble_gattc_disc_all_chrs(conn.conn_handle, start_handle, end_handle,
+ disc_chrc_cb, (void *)GATT_DISC_ALL_CHRC);
+ if (rc) {
+ discover_destroy();
goto fail;
}
return;
- fail:
- os_mbuf_free_chain(om);
-
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_WRITE_LONG, CONTROLLER_INDEX,
+fail:
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_DISC_ALL_CHRC, CONTROLLER_INDEX,
BTP_STATUS_FAILED);
}
-static struct bt_gatt_subscribe_params {
- u16_t ccc_handle;
- u16_t value;
- u16_t value_handle;
-} subscribe_params;
-
-int tester_gatt_notify_rx_ev(u16_t conn_handle, u16_t attr_handle,
- u8_t indication, struct os_mbuf *om)
+static void find_included(u8_t *data, u16_t len)
{
- struct gatt_notification_ev *ev;
+ const struct gatt_find_included_cmd *cmd = (void *) data;
struct ble_gap_conn_desc conn;
- struct os_mbuf *buf = os_msys_get(0, 0);
- const ble_addr_t *addr;
+ uint16_t start_handle, end_handle;
+ int service_handle_arg;
+ int rc;
SYS_LOG_DBG("");
- if (!subscribe_params.ccc_handle) {
+ rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
+ if (rc) {
goto fail;
}
- if (ble_gap_conn_find(conn_handle, &conn)) {
+ if (!gatt_buf_reserve(sizeof(struct gatt_find_included_rp))) {
goto fail;
}
- net_buf_simple_init(buf, 0);
- ev = net_buf_simple_add(buf, sizeof(*ev));
-
- addr = &conn.peer_ota_addr;
+ start_handle = sys_le16_to_cpu(cmd->start_handle);
+ end_handle = sys_le16_to_cpu(cmd->end_handle);
+ service_handle_arg = start_handle;
- ev->address_type = addr->type;
- memcpy(ev->address, addr->val, sizeof(ev->address));
- ev->type = (u8_t) (indication ? 0x02 : 0x01);
- ev->handle = sys_cpu_to_le16(attr_handle);
- ev->data_length = sys_cpu_to_le16(os_mbuf_len(om));
- os_mbuf_appendfrom(buf, om, 0, os_mbuf_len(om));
+ if (ble_gattc_find_inc_svcs(conn.conn_handle, start_handle, end_handle,
+ find_included_cb,
+ (void *)service_handle_arg)) {
+ discover_destroy();
+ goto fail;
+ }
- tester_send_buf(BTP_SERVICE_ID_GATT, GATT_EV_NOTIFICATION,
- CONTROLLER_INDEX, buf);
+ return;
fail:
- os_mbuf_free_chain(buf);
- return 0;
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_FIND_INCLUDED, CONTROLLER_INDEX,
+ BTP_STATUS_FAILED);
}
-int tester_gatt_subscribe_ev(u16_t conn_handle, u16_t attr_handle, u8_t reason,
- u8_t prev_notify, u8_t cur_notify,
- u8_t prev_indicate, u8_t cur_indicate)
+static int exchange_func(uint16_t conn_handle,
+ const struct ble_gatt_error *error,
+ uint16_t mtu, void *arg)
{
SYS_LOG_DBG("");
- if (cur_notify == 0 && cur_indicate == 0) {
- SYS_LOG_INF("Unsubscribed");
- memset(&subscribe_params, 0, sizeof(subscribe_params));
- return 0;
- }
+ if (error->status) {
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
- if (cur_notify) {
- SYS_LOG_INF("Subscribed to notifications");
+ return 0;
+}
+
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU, CONTROLLER_INDEX,
+ BTP_STATUS_SUCCESS);
+
+ return 0;
+}
+
+static void exchange_mtu(u8_t *data, u16_t len)
+{
+ struct ble_gap_conn_desc conn;
+ int rc;
+
+ SYS_LOG_DBG("");
+
+ rc = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
+ if (rc) {
+ goto fail;
}
- if (cur_indicate) {
- SYS_LOG_INF("Subscribed to indications");
+ if (ble_gattc_exchange_mtu(conn.conn_handle, exchange_func, NULL)) {
+ goto fail;
}
- return 0;
+ return;
+fail:
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_EXCHANGE_MTU,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
static int enable_subscription(u16_t conn_handle, u16_t ccc_handle,
@@ -1871,8 +1455,7 @@ static int enable_subscription(u16_t conn_handle, u16_t ccc_handle,
SYS_LOG_DBG("");
- op = (uint8_t) (value == 0x0001 ? GATT_CFG_NOTIFY :
- GATT_CFG_INDICATE);
+ op = (uint8_t) (value == 0x0001 ? GATT_CFG_NOTIFY : GATT_CFG_INDICATE);
if (ble_gattc_write_flat(conn_handle, ccc_handle,
&value, sizeof(value), NULL, NULL)) {
@@ -2029,7 +1612,7 @@ static void get_attrs(u8_t *data, u16_t len)
if (entry->ha_handle_id < start_handle) {
entry = ble_att_svr_find_by_uuid(entry,
- uuid_ptr, end_handle);
+ uuid_ptr, end_handle);
continue;
}
@@ -2040,12 +1623,12 @@ static void get_attrs(u8_t *data, u16_t len)
if (entry->ha_uuid->type == BLE_UUID_TYPE_16) {
gatt_attr->type_length = 2;
net_buf_simple_add_le16(buf,
- BLE_UUID16(entry->ha_uuid)->value);
+ BLE_UUID16(entry->ha_uuid)->value);
} else {
gatt_attr->type_length = 16;
net_buf_simple_add_mem(buf,
- BLE_UUID128(entry->ha_uuid)->value,
- gatt_attr->type_length);
+ BLE_UUID128(entry->ha_uuid)->value,
+ gatt_attr->type_length);
}
count++;
@@ -2070,56 +1653,129 @@ static void get_attr_val(u8_t *data, u16_t len)
{
const struct gatt_get_attribute_value_cmd *cmd = (void *) data;
struct gatt_get_attribute_value_rp *rp;
+ struct ble_gap_conn_desc conn;
struct os_mbuf *buf = os_msys_get(0, 0);
u16_t handle = sys_cpu_to_le16(cmd->handle);
uint8_t out_att_err;
+ int conn_status;
- SYS_LOG_DBG("");
+ conn_status = ble_gap_conn_find_by_addr((ble_addr_t *)data, &conn);
- net_buf_simple_init(buf, 0);
- rp = net_buf_simple_add(buf, sizeof(*rp));
+ if (conn_status) {
+ net_buf_simple_init(buf, 0);
+ rp = net_buf_simple_add(buf, sizeof(*rp));
- ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
- handle, 0, buf,
- &out_att_err);
+ ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
+ handle, 0, buf,
+ &out_att_err);
- rp->att_response = out_att_err;
- rp->value_length = os_mbuf_len(buf) - sizeof(*rp);
+ rp->att_response = out_att_err;
+ rp->value_length = os_mbuf_len(buf) - sizeof(*rp);
- tester_send_buf(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE,
- CONTROLLER_INDEX, buf);
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE,
+ CONTROLLER_INDEX, buf);
+
+ goto free;
+ } else {
+ net_buf_simple_init(buf, 0);
+ rp = net_buf_simple_add(buf, sizeof(*rp));
+ ble_att_svr_read_handle(conn.conn_handle,
+ handle, 0, buf,
+ &out_att_err);
+
+ rp->att_response = out_att_err;
+ rp->value_length = os_mbuf_len(buf) - sizeof(*rp);
+
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE,
+ CONTROLLER_INDEX, buf);
+
+ goto free;
+ }
+
+free:
os_mbuf_free_chain(buf);
}
+static void change_database(u8_t *data, u16_t len)
+{
+ const struct gatt_change_database *cmd = (void *) data;
+ int rc;
+
+ SYS_LOG_DBG("")
+
+ rc = ble_gatts_svc_set_visibility(cmd->start_handle, cmd->visibility);
+ if (rc) {
+ goto fail;
+ }
+
+ ble_gatts_show_local();
+
+ ble_svc_gatt_changed(cmd->start_handle, cmd->end_handle);
+
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_CHANGE_DATABASE, CONTROLLER_INDEX,
+ BTP_STATUS_SUCCESS);
+
+ return;
+
+fail:
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_CHANGE_DATABASE, CONTROLLER_INDEX,
+ BTP_STATUS_FAILED);
+}
+
+static void supported_commands(u8_t *data, u16_t len)
+{
+ u8_t cmds[4];
+ struct gatt_read_supported_commands_rp *rp = (void *) cmds;
+
+ SYS_LOG_DBG("");
+
+ memset(cmds, 0, sizeof(cmds));
+
+ tester_set_bit(cmds, GATT_READ_SUPPORTED_COMMANDS);
+ tester_set_bit(cmds, GATT_START_SERVER);
+ tester_set_bit(cmds, GATT_EXCHANGE_MTU);
+ tester_set_bit(cmds, GATT_DISC_ALL_PRIM_SVCS);
+ tester_set_bit(cmds, GATT_DISC_PRIM_UUID);
+ tester_set_bit(cmds, GATT_FIND_INCLUDED);
+ tester_set_bit(cmds, GATT_DISC_ALL_CHRC);
+ tester_set_bit(cmds, GATT_DISC_CHRC_UUID);
+ tester_set_bit(cmds, GATT_DISC_ALL_DESC);
+ tester_set_bit(cmds, GATT_READ);
+ tester_set_bit(cmds, GATT_READ_LONG);
+ tester_set_bit(cmds, GATT_READ_MULTIPLE);
+ tester_set_bit(cmds, GATT_WRITE_WITHOUT_RSP);
+#if 0
+ tester_set_bit(cmds, GATT_SIGNED_WRITE_WITHOUT_RSP);
+#endif
+ tester_set_bit(cmds, GATT_WRITE);
+ tester_set_bit(cmds, GATT_WRITE_LONG);
+ tester_set_bit(cmds, GATT_CFG_NOTIFY);
+ tester_set_bit(cmds, GATT_CFG_INDICATE);
+ tester_set_bit(cmds, GATT_GET_ATTRIBUTES);
+ tester_set_bit(cmds, GATT_GET_ATTRIBUTE_VALUE);
+ tester_set_bit(cmds, GATT_CHANGE_DATABASE);
+
+ tester_send(BTP_SERVICE_ID_GATT, GATT_READ_SUPPORTED_COMMANDS,
+ CONTROLLER_INDEX, (u8_t *) rp, sizeof(cmds));
+}
+
+enum attr_type {
+ BLE_GATT_ATTR_SVC = 0,
+ BLE_GATT_ATTR_CHR,
+ BLE_GATT_ATTR_DSC,
+};
+
void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
- u16_t len)
+ u16_t len)
{
switch (opcode) {
case GATT_READ_SUPPORTED_COMMANDS:
supported_commands(data, len);
return;
- case GATT_ADD_SERVICE:
- add_service(data, len);
- return;
- case GATT_ADD_CHARACTERISTIC:
- add_characteristic(data, len);
- return;
- case GATT_ADD_DESCRIPTOR:
- add_descriptor(data, len);
- return;
- case GATT_ADD_INCLUDED_SERVICE:
- add_included(data, len);
- return;
- case GATT_SET_VALUE:
- set_value(data, len);
- return;
case GATT_START_SERVER:
start_server(data, len);
return;
- case GATT_SET_ENC_KEY_SIZE:
- set_enc_key_size(data, len);
- return;
case GATT_EXCHANGE_MTU:
exchange_mtu(data, len);
return;
@@ -2141,6 +1797,9 @@ void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
case GATT_DISC_ALL_DESC:
disc_all_desc(data, len);
return;
+ case GATT_CHANGE_DATABASE:
+ change_database(data, len);
+ return;
case GATT_READ:
read(data, len);
return;
@@ -2183,58 +1842,164 @@ void tester_handle_gatt(u8_t opcode, u8_t index, u8_t *data,
default:
tester_rsp(BTP_SERVICE_ID_GATT, opcode, index,
BTP_STATUS_UNKNOWN_CMD);
- return;
+ return;
}
}
-void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
+int tester_gatt_notify_rx_ev(u16_t conn_handle, u16_t attr_handle,
+ u8_t indication, struct os_mbuf *om)
{
- char buf[BLE_UUID_STR_LEN];
+ struct gatt_notification_ev *ev;
+ struct ble_gap_conn_desc conn;
+ struct os_mbuf *buf = os_msys_get(0, 0);
+ const ble_addr_t *addr;
- switch (ctxt->op) {
- case BLE_GATT_REGISTER_OP_SVC:
- MODLOG_DFLT(DEBUG,
- "registered service %s with handle=%d\n",
- ble_uuid_to_str(ctxt->svc.svc_def->uuid,
- buf),
- ctxt->svc.handle);
- break;
-
- case BLE_GATT_REGISTER_OP_CHR:
- MODLOG_DFLT(DEBUG, "registering characteristic %s with "
- "def_handle=%d val_handle=%d\n",
- ble_uuid_to_str(ctxt->chr.chr_def->uuid,
- buf),
- ctxt->chr.def_handle,
- ctxt->chr.val_handle);
- break;
-
- case BLE_GATT_REGISTER_OP_DSC:
- MODLOG_DFLT(DEBUG,
- "registering descriptor %s with handle=%d\n",
- ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
- ctxt->dsc.handle);
- break;
-
- default:
- assert(0);
- break;
+ SYS_LOG_DBG("");
+
+ if (!subscribe_params.ccc_handle) {
+ goto fail;
+ }
+
+ if (ble_gap_conn_find(conn_handle, &conn)) {
+ goto fail;
}
+
+ net_buf_simple_init(buf, 0);
+ ev = net_buf_simple_add(buf, sizeof(*ev));
+
+ addr = &conn.peer_ota_addr;
+
+ ev->address_type = addr->type;
+ memcpy(ev->address, addr->val, sizeof(ev->address));
+ ev->type = (u8_t) (indication ? 0x02 : 0x01);
+ ev->handle = sys_cpu_to_le16(attr_handle);
+ ev->data_length = sys_cpu_to_le16(os_mbuf_len(om));
+ os_mbuf_appendfrom(buf, om, 0, os_mbuf_len(om));
+
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_EV_NOTIFICATION,
+ CONTROLLER_INDEX, buf);
+
+fail:
+ os_mbuf_free_chain(buf);
+ return 0;
}
-int gatt_svr_init(void)
+void notify_test_stop(void)
+{
+ os_callout_stop(¬ify_tx_timer);
+}
+
+void notify_test_reset(void)
{
int rc;
- rc = ble_gatts_count_cfg(gatt_svr_inc_svcs);
- if (rc != 0) {
- return rc;
+ rc = os_callout_reset(¬ify_tx_timer, OS_TICKS_PER_SEC);
+ assert(rc == 0);
+}
+
+void notify_test(struct os_event *ev)
+{
+ uint8_t notify_value = 90;
+ static uint8_t ntf[1];
+ int rc;
+ struct os_mbuf *om;
+
+ if (!notify_state) {
+ notify_test_stop();
+ notify_value = 90;
+ return;
}
- rc = ble_gatts_add_svcs(gatt_svr_inc_svcs);
- if (rc != 0) {
- return rc;
+ ntf[0] = notify_value;
+
+ notify_value++;
+ if (notify_value == 160) {
+ notify_value = 90;
+ }
+
+ om = ble_hs_mbuf_from_flat(ntf, sizeof(ntf));
+
+ rc = ble_gattc_notify_custom(myconn_handle, notify_handle, om);
+ rc = ble_gattc_indicate_custom(myconn_handle, notify_handle, om);
+
+ assert(rc == 0);
+ notify_test_reset();
+}
+
+int tester_gatt_subscribe_ev(u16_t conn_handle, u16_t attr_handle, u8_t reason,
+ u8_t prev_notify, u8_t cur_notify,
+ u8_t prev_indicate, u8_t cur_indicate)
+{
+ SYS_LOG_DBG("");
+ myconn_handle = conn_handle;
+ os_callout_init(¬ify_tx_timer, os_eventq_dflt_get(), notify_test, NULL);
+
+ if (cur_notify == 0 && cur_indicate == 0) {
+ SYS_LOG_INF("Unsubscribed");
+ memset(&subscribe_params, 0, sizeof(subscribe_params));
+ return 0;
+ }
+
+ if (cur_notify) {
+ SYS_LOG_INF("Subscribed to notifications");
+ if (attr_handle == notify_handle) {
+ notify_state = cur_notify;
+ notify_test_reset();
+ } else if (attr_handle != notify_handle) {
+ notify_state = cur_notify;
+ notify_test_stop();
+ }
+ }
+
+ if (cur_indicate) {
+ SYS_LOG_INF("Subscribed to indications");
+ if (attr_handle == notify_handle) {
+ notify_state = cur_indicate;
+ notify_test_reset();
+ } else if (attr_handle != notify_handle) {
+ notify_state = cur_indicate;
+ notify_test_stop();
+ }
+ }
+
+ return 0;
+}
+
+void
+gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg)
+{
+ char buf[BLE_UUID_STR_LEN];
+
+ switch (ctxt->op) {
+ case BLE_GATT_REGISTER_OP_SVC:
+ MODLOG_DFLT(DEBUG, "registered service %s with handle=%d\n",
+ ble_uuid_to_str(ctxt->svc.svc_def->uuid, buf),
+ ctxt->svc.handle);
+ break;
+
+ case BLE_GATT_REGISTER_OP_CHR:
+ MODLOG_DFLT(DEBUG, "registering characteristic %s with "
+ "def_handle=%d val_handle=%d\n",
+ ble_uuid_to_str(ctxt->chr.chr_def->uuid, buf),
+ ctxt->chr.def_handle,
+ ctxt->chr.val_handle);
+ break;
+
+ case BLE_GATT_REGISTER_OP_DSC:
+ MODLOG_DFLT(DEBUG, "registering descriptor %s with handle=%d\n",
+ ble_uuid_to_str(ctxt->dsc.dsc_def->uuid, buf),
+ ctxt->dsc.handle);
+ break;
+
+ default:
+ assert(0);
+ break;
}
+}
+
+int gatt_svr_init(void)
+{
+ int rc;
rc = ble_gatts_count_cfg(gatt_svr_svcs);
if (rc != 0) {
@@ -2246,8 +2011,6 @@ int gatt_svr_init(void)
return rc;
}
- init_gatt_values();
-
return 0;
}
[mynewt-nimble] 16/32: apps/bttester: Change default syscfg values
to fit on nRF52DK
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit ea6ef736d2d9db9b391a4bd33bbd9aebcf6dbfed
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu Jul 18 14:02:03 2019 +0200
apps/bttester: Change default syscfg values to fit on nRF52DK
---
apps/bttester/syscfg.yml | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/apps/bttester/syscfg.yml b/apps/bttester/syscfg.yml
index 7fbfe34..659cc7b 100644
--- a/apps/bttester/syscfg.yml
+++ b/apps/bttester/syscfg.yml
@@ -61,24 +61,24 @@ syscfg.defs:
BTTESTER_DEBUG:
description: Enable debug logging
- value: 1
+ value: 0
BTTESTER_BTP_LOG:
description: Enable logging BTP traffic
value: 0
syscfg.vals:
- OS_MAIN_STACK_SIZE: 12444
- SHELL_TASK: 1
+ OS_MAIN_STACK_SIZE: 512
+ SHELL_TASK: 0
SHELL_NEWTMGR: 0
- LOG_LEVEL: 0
+ LOG_LEVEL: 12
MSYS_1_BLOCK_COUNT: 48
BLE_MONITOR_RTT: 1
CONSOLE_RTT: 0
- CONSOLE_UART: 1
- RTT_NUM_BUFFERS_UP: 1
- RTT_NUM_BUFFERS_DOWN: 1
+ CONSOLE_UART: 0
+ RTT_NUM_BUFFERS_UP: 0
+ RTT_NUM_BUFFERS_DOWN: 0
BLE_L2CAP_COC_MAX_NUM: 2
# Some testcases require MPS < MTU
@@ -129,8 +129,3 @@ syscfg.vals:
BLE_MESH_DEBUG_FRIEND: 0
BLE_MESH_DEBUG_PROXY: 0
-syscfg.vals.BTTESTER_PIPE_UART:
- CONSOLE_UART: 0
- CONSOLE_RTT: 1
- RTT_TERMINAL_BUFFER_SIZE_UP: 8192
-
[mynewt-nimble] 14/32: apps/bttester: Add Connection Parameter
Update implementation
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 409c5a30b3209eb9bf2bd84d3e712961c33d66cc
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Tue Jul 9 16:26:31 2019 +0200
apps/bttester: Add Connection Parameter Update implementation
---
apps/bttester/src/bttester.h | 22 +++++++
apps/bttester/src/gap.c | 140 ++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 161 insertions(+), 1 deletion(-)
diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index 9e88842..9e41f57 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -274,6 +274,16 @@ struct gap_passkey_confirm_cmd {
u8_t match;
} __packed;
+#define GAP_CONN_PARAM_UPDATE 0x16
+struct gap_conn_param_update_cmd {
+ u8_t address_type;
+ u8_t address[6];
+ u16_t conn_itvl_min;
+ u16_t conn_itvl_max;
+ u16_t conn_latency;
+ u16_t supervision_timeout;
+} __packed;
+
/* events */
#define GAP_EV_NEW_SETTINGS 0x80
struct gap_new_settings_ev {
@@ -298,6 +308,9 @@ struct gap_device_found_ev {
struct gap_device_connected_ev {
u8_t address_type;
u8_t address[6];
+ u16_t conn_itvl;
+ u16_t conn_latency;
+ u16_t supervision_timeout;
} __packed;
#define GAP_EV_DEVICE_DISCONNECTED 0x83
@@ -334,6 +347,15 @@ struct gap_identity_resolved_ev {
u8_t identity_address[6];
} __packed;
+#define GAP_EV_CONN_PARAM_UPDATE 0x88
+struct gap_conn_param_update_ev {
+ u8_t address_type;
+ u8_t address[6];
+ u16_t conn_itvl;
+ u16_t conn_latency;
+ u16_t supervision_timeout;
+} __packed;
+
/* GATT Service */
/* commands */
#define GATT_READ_SUPPORTED_COMMANDS 0x01
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index 719971d..19bd72d 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -25,6 +25,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
+#include <host/ble_gap.h>
#include "host/ble_gap.h"
#include "console/console.h"
@@ -665,7 +666,9 @@ static void le_connected(u16_t conn_handle, int status)
memcpy(ev.address, addr->val, sizeof(ev.address));
ev.address_type = addr->type;
-
+ ev.conn_itvl = desc.conn_itvl;
+ ev.conn_latency = desc.conn_latency;
+ ev.supervision_timeout = desc.supervision_timeout;
#if MYNEWT_VAL(BTTESTER_CONN_PARAM_UPDATE)
if (desc.role == BLE_GAP_ROLE_MASTER) {
@@ -828,6 +831,23 @@ static void le_encryption_changed(struct ble_gap_conn_desc *desc)
encrypted = (bool) desc->sec_state.encrypted;
}
+static void le_conn_param_update(struct ble_gap_conn_desc *desc)
+{
+ struct gap_conn_param_update_ev ev;
+
+ SYS_LOG_DBG("");
+
+ ev.address_type = desc->peer_ota_addr.type;
+ memcpy(ev.address, desc->peer_ota_addr.val, sizeof(ev.address));
+
+ ev.conn_itvl = desc->conn_itvl;
+ ev.conn_latency = desc->conn_latency;
+ ev.supervision_timeout = desc->supervision_timeout;
+
+ tester_send(BTP_SERVICE_ID_GAP, GAP_EV_CONN_PARAM_UPDATE,
+ CONTROLLER_INDEX, (u8_t *) &ev, sizeof(ev));
+}
+
static void print_bytes(const uint8_t *bytes, int len)
{
int i;
@@ -1004,6 +1024,30 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
rc = ble_store_util_delete_peer(&desc.peer_id_addr);
assert(rc == 0);
return BLE_GAP_REPEAT_PAIRING_RETRY;
+ case BLE_GAP_EVENT_CONN_UPDATE:
+ console_printf("connection update event; status=%d ",
+ event->conn_update.status);
+ rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc);
+ assert(rc == 0);
+ print_conn_desc(&desc);
+ le_conn_param_update(&desc);
+ break;
+ case BLE_GAP_EVENT_CONN_UPDATE_REQ:
+ console_printf("connection update request event; "
+ "conn_handle=%d itvl_min=%d itvl_max=%d "
+ "latency=%d supervision_timoeut=%d "
+ "min_ce_len=%d max_ce_len=%d\n",
+ event->conn_update_req.conn_handle,
+ event->conn_update_req.peer_params->itvl_min,
+ event->conn_update_req.peer_params->itvl_max,
+ event->conn_update_req.peer_params->latency,
+ event->conn_update_req.peer_params->supervision_timeout,
+ event->conn_update_req.peer_params->min_ce_len,
+ event->conn_update_req.peer_params->max_ce_len);
+
+ *event->conn_update_req.self_params =
+ *event->conn_update_req.peer_params;
+ break;
default:
break;
}
@@ -1210,6 +1254,97 @@ rsp:
status);
}
+static void conn_param_update_cb(uint16_t conn_handle, int status, void *arg)
+{
+ u8_t btp_status;
+
+ console_printf("conn param update complete; conn_handle=%d status=%d\n",
+ conn_handle, status);
+
+ btp_status = status ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS;
+
+ tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONN_PARAM_UPDATE,
+ CONTROLLER_INDEX, btp_status);
+}
+
+static int conn_param_update_slave(u16_t conn_handle,
+ const struct gap_conn_param_update_cmd *cmd)
+{
+ int rc;
+ struct ble_l2cap_sig_update_params params;
+
+ params.itvl_min = cmd->conn_itvl_min;
+ params.itvl_max = cmd->conn_itvl_max;
+ params.slave_latency = cmd->conn_latency;
+ params.timeout_multiplier = cmd->supervision_timeout;
+
+ rc = ble_l2cap_sig_update(conn_handle, ¶ms,
+ conn_param_update_cb, NULL);
+ if (rc) {
+ tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONN_PARAM_UPDATE,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ }
+
+ return 0;
+}
+
+static int conn_param_update_master(u16_t conn_handle,
+ const struct gap_conn_param_update_cmd *cmd)
+{
+ int rc;
+ struct ble_gap_upd_params params;
+
+ params.itvl_min = cmd->conn_itvl_min;
+ params.itvl_max = cmd->conn_itvl_max;
+ params.latency = cmd->conn_latency;
+ params.supervision_timeout = cmd->supervision_timeout;
+ rc = ble_gap_update_params(conn_handle, ¶ms);
+ if (rc) {
+ SYS_LOG_ERR("Failed to send update params: rc=%d", rc);
+ }
+
+ return rc;
+}
+
+static void conn_param_update(const u8_t *data, u16_t len)
+{
+ const struct gap_conn_param_update_cmd *cmd = (void *) data;
+ struct ble_gap_conn_desc desc;
+ u8_t status = BTP_STATUS_SUCCESS;
+ int rc;
+
+ SYS_LOG_DBG("");
+
+ rc = gap_conn_find_by_addr((ble_addr_t *)data, &desc);
+ if (rc) {
+ status = BTP_STATUS_FAILED;
+ goto rsp;
+ }
+
+ if ((desc.conn_itvl >= cmd->conn_itvl_min) &&
+ (desc.conn_itvl <= cmd->conn_itvl_max) &&
+ (desc.conn_latency == cmd->conn_latency) &&
+ (desc.supervision_timeout == cmd->supervision_timeout)) {
+ goto rsp;
+ }
+
+ if (desc.role == BLE_GAP_ROLE_MASTER) {
+ rc = conn_param_update_master(desc.conn_handle, cmd);
+ } else {
+ rc = conn_param_update_slave(desc.conn_handle, cmd);
+ if (!rc) {
+ /* Response will be sent from callback */
+ return;
+ }
+ }
+
+ status = rc ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS;
+
+rsp:
+ tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONN_PARAM_UPDATE, CONTROLLER_INDEX,
+ status);
+}
+
void tester_handle_gap(u8_t opcode, u8_t index, u8_t *data,
u16_t len)
{
@@ -1280,6 +1415,9 @@ void tester_handle_gap(u8_t opcode, u8_t index, u8_t *data,
case GAP_PASSKEY_CONFIRM:
passkey_confirm(data, len);
return;
+ case GAP_CONN_PARAM_UPDATE:
+ conn_param_update(data, len);
+ return;
default:
tester_rsp(BTP_SERVICE_ID_GAP, opcode, index,
BTP_STATUS_UNKNOWN_CMD);
[mynewt-nimble] 09/32: apps/bttester: Remove write_long workaround
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit d9f28dec9c497fa28b4a3378f606409bf206ee3c
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu Apr 25 16:24:02 2019 +0200
apps/bttester: Remove write_long workaround
This workaround should not be here. It should be
on the AutoPTS side or this issue should be fixed in PTS.
---
apps/bttester/src/gatt.c | 6 ------
1 file changed, 6 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 3a9b587..cba662d 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1705,12 +1705,6 @@ static void write_long(u8_t *data, u16_t len)
}
om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
- /* This is required, because Nimble checks if
- * the data is longer than offset
- */
- if (os_mbuf_extend(om, cmd->offset + 1) == NULL) {
- goto fail;
- }
if (ble_gattc_write_long(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
sys_le16_to_cpu(cmd->offset), om, write_rsp,
[mynewt-nimble] 30/32: apps/bttester: Fix notification logic
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 90cd415b20fb90ecf68379ba4277afaadf920ddd
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Fri Aug 30 15:24:37 2019 +0200
apps/bttester: Fix notification logic
---
apps/bttester/src/gatt.c | 44 +++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 4b389c7..79fc47f 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -76,10 +76,12 @@
static uint8_t gatt_svr_pts_static_long_val[300];
static uint8_t gatt_svr_pts_static_val[30];
static uint8_t gatt_svr_pts_static_short_val;
-static bool notify_state;
+static u8_t notify_state;
+static u8_t indicate_state;
static uint16_t myconn_handle;
static struct os_callout notify_tx_timer;
uint16_t notify_handle;
+uint8_t notify_value = 90;
struct find_attr_data {
ble_uuid_any_t *uuid;
@@ -1890,12 +1892,11 @@ void notify_test_reset(void)
void notify_test(struct os_event *ev)
{
- uint8_t notify_value = 90;
static uint8_t ntf[1];
- int rc;
struct os_mbuf *om;
+ int rc;
- if (!notify_state) {
+ if (!notify_state && !indicate_state) {
notify_test_stop();
notify_value = 90;
return;
@@ -1910,11 +1911,15 @@ void notify_test(struct os_event *ev)
om = ble_hs_mbuf_from_flat(ntf, sizeof(ntf));
- rc = ble_gattc_notify_custom(myconn_handle, notify_handle, om);
- rc = ble_gattc_indicate_custom(myconn_handle, notify_handle, om);
+ if (notify_state) {
+ rc = ble_gattc_notify_custom(myconn_handle, notify_handle, om);
+ assert(rc == 0);
+ }
- assert(rc == 0);
- notify_test_reset();
+ if (indicate_state) {
+ rc = ble_gattc_indicate_custom(myconn_handle, notify_handle, om);
+ assert(rc == 0);
+ }
}
int tester_gatt_subscribe_ev(u16_t conn_handle, u16_t attr_handle, u8_t reason,
@@ -1923,7 +1928,6 @@ int tester_gatt_subscribe_ev(u16_t conn_handle, u16_t attr_handle, u8_t reason,
{
SYS_LOG_DBG("");
myconn_handle = conn_handle;
- os_callout_init(¬ify_tx_timer, os_eventq_dflt_get(), notify_test, NULL);
if (cur_notify == 0 && cur_indicate == 0) {
SYS_LOG_INF("Unsubscribed");
@@ -1932,27 +1936,26 @@ int tester_gatt_subscribe_ev(u16_t conn_handle, u16_t attr_handle, u8_t reason,
}
if (cur_notify) {
- SYS_LOG_INF("Subscribed to notifications");
+ SYS_LOG_INF("Subscribed to notifications");
if (attr_handle == notify_handle) {
notify_state = cur_notify;
- notify_test_reset();
- } else if (attr_handle != notify_handle) {
- notify_state = cur_notify;
- notify_test_stop();
}
}
if (cur_indicate) {
SYS_LOG_INF("Subscribed to indications");
if (attr_handle == notify_handle) {
- notify_state = cur_indicate;
- notify_test_reset();
- } else if (attr_handle != notify_handle) {
- notify_state = cur_indicate;
- notify_test_stop();
+ indicate_state = cur_indicate;
}
}
+
+ if (notify_state || indicate_state) {
+ notify_test_reset();
+ } else {
+ notify_test_stop();
+ }
+
return 0;
}
@@ -2007,6 +2010,9 @@ int gatt_svr_init(void)
u8_t tester_init_gatt(void)
{
+ os_callout_init(¬ify_tx_timer, os_eventq_dflt_get(),
+ notify_test, NULL);
+
return BTP_STATUS_SUCCESS;
}
[mynewt-nimble] 24/32: apps/bttester: Fix GATT Attribute permission
mapping
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 0c91f0383d248bb0b8a65554f80504b3d7dd162a
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Aug 28 11:21:59 2019 +0200
apps/bttester: Fix GATT Attribute permission mapping
BTP uses different values for permissions than Nimble so we have
to convert host flags to BTP permissions.
---
apps/bttester/src/gatt.c | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 2009459..fe24275 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1953,6 +1953,40 @@ static void config_subscription(u8_t *data, u16_t len, u8_t op)
tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status);
}
+#define BTP_PERM_F_READ 0x01
+#define BTP_PERM_F_WRITE 0x02
+#define BTP_PERM_F_READ_ENC 0x04
+#define BTP_PERM_F_WRITE_ENC 0x08
+#define BTP_PERM_F_READ_AUTHEN 0x10
+#define BTP_PERM_F_WRITE_AUTHEN 0x20
+#define BTP_PERM_F_READ_AUTHOR 0x40
+#define BTP_PERM_F_WRITE_AUTHOR 0x80
+
+static int flags_hs2btp_map[] = {
+ BTP_PERM_F_READ,
+ BTP_PERM_F_WRITE,
+ BTP_PERM_F_READ_ENC,
+ BTP_PERM_F_READ_AUTHEN,
+ BTP_PERM_F_READ_AUTHOR,
+ BTP_PERM_F_WRITE_ENC,
+ BTP_PERM_F_WRITE_AUTHEN,
+ BTP_PERM_F_WRITE_AUTHOR,
+};
+
+static u8_t flags_hs2btp(u8_t flags)
+{
+ int i;
+ u8_t ret = 0;
+
+ for (i = 0; i < 8; ++i) {
+ if (flags & BIT(i)) {
+ ret |= flags_hs2btp_map[i];
+ }
+ }
+
+ return ret;
+}
+
static void get_attrs(u8_t *data, u16_t len)
{
const struct gatt_get_attributes_cmd *cmd = (void *) data;
@@ -2001,7 +2035,7 @@ static void get_attrs(u8_t *data, u16_t len)
gatt_attr = net_buf_simple_add(buf, sizeof(*gatt_attr));
gatt_attr->handle = sys_cpu_to_le16(entry->ha_handle_id);
- gatt_attr->permission = entry->ha_flags;
+ gatt_attr->permission = flags_hs2btp(entry->ha_flags);
if (entry->ha_uuid->type == BLE_UUID_TYPE_16) {
gatt_attr->type_length = 2;
[mynewt-nimble] 04/32: apps/bttester: Fix search attribute by handle
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 2321a8790ba54c45f488eae468302605f0bc6eb0
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Mon Apr 8 13:28:38 2019 +0200
apps/bttester: Fix search attribute by handle
---
apps/bttester/src/gatt.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 4afeb1d..ff3f1dd 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1884,7 +1884,7 @@ static u8_t foreach_get_attrs(u16_t handle,
struct gatt_attr *gatt_attr;
char uuid_buf[BLE_UUID_STR_LEN];
- if (handle < foreach->start_handle && handle > foreach->end_handle) {
+ if (handle < foreach->start_handle || handle > foreach->end_handle) {
return 0;
}
[mynewt-nimble] 11/32: apps/bttester: Add a dummy CCC descriptor
definition
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 309b93e66b74f1fb64b01c2b57e00a809e4b813d
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Mon May 27 13:54:56 2019 +0200
apps/bttester: Add a dummy CCC descriptor definition
This is used in add_descriptor method, when verifying that
the descriptor that the Upper Tester wants to add is indeed present
in the GATT database (since we are not able to add attributes dynamically).
---
apps/bttester/src/gatt.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index c6f7fd4..6209154 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -41,6 +41,9 @@
#define CONTROLLER_INDEX 0
#define MAX_BUFFER_SIZE 2048
+static const ble_uuid_t *uuid_ccc =
+ BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16);
+
static int gatt_chr_perm_map[] = {
BLE_GATT_CHR_F_READ,
BLE_GATT_CHR_F_WRITE,
@@ -137,6 +140,10 @@ static void *gatt_buf_add(const void *data, size_t len)
return ptr;
}
+static const struct ble_gatt_dsc_def cccd_def = {
+ .att_flags = BLE_ATT_F_READ | BLE_ATT_F_WRITE,
+};
+
static void *gatt_buf_reserve(size_t len)
{
return gatt_buf_add(NULL, len);
@@ -461,6 +468,11 @@ static void find_attr_by_uuid_cb(const struct ble_gatt_svc_def *svc,
if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
(chr->flags & BLE_GATT_CHR_F_INDICATE)) {
+ if (foreach->attr_type == BLE_GATT_ATTR_DSC &&
+ ble_uuid_cmp(&foreach->uuid->u, uuid_ccc) == 0) {
+ foreach->ptr = (void *) &cccd_def;
+ foreach->handle = handle;
+ }
handle += 1;
}
[mynewt-nimble] 01/32: apps/bttester: Add support for sending
segmented buffers
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit d9caef73fa1fc80aac7a3118330c0a01b3a8f936
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Apr 3 16:06:03 2019 +0200
apps/bttester: Add support for sending segmented buffers
Some messages are so long that mbuf chains have to be used to store them.
This patch adds API to send mbufs. This api handles sending
of all mbufs in a chain.
---
apps/bttester/src/bttester.c | 16 ++++++++++++++++
apps/bttester/src/bttester.h | 2 ++
apps/bttester/src/bttester_pipe.h | 1 +
apps/bttester/src/uart_pipe.c | 25 +++++++++++++++++++++++++
4 files changed, 44 insertions(+)
diff --git a/apps/bttester/src/bttester.c b/apps/bttester/src/bttester.c
index 088b6eb..02021d0 100644
--- a/apps/bttester/src/bttester.c
+++ b/apps/bttester/src/bttester.c
@@ -345,6 +345,22 @@ void tester_send(u8_t service, u8_t opcode, u8_t index, u8_t *data,
}
}
+void tester_send_buf(u8_t service, u8_t opcode, u8_t index,
+ struct os_mbuf *data)
+{
+ struct btp_hdr msg;
+
+ msg.service = service;
+ msg.opcode = opcode;
+ msg.index = index;
+ msg.len = os_mbuf_len(data);
+
+ bttester_pipe_send((u8_t *)&msg, sizeof(msg));
+ if (data && msg.len) {
+ bttester_pipe_send_buf(data);
+ }
+}
+
void tester_rsp(u8_t service, u8_t opcode, u8_t index, u8_t status)
{
struct btp_status s;
diff --git a/apps/bttester/src/bttester.h b/apps/bttester/src/bttester.h
index 34fe9b6..9e88842 100644
--- a/apps/bttester/src/bttester.h
+++ b/apps/bttester/src/bttester.h
@@ -894,6 +894,8 @@ void tester_init(void);
void tester_rsp(u8_t service, u8_t opcode, u8_t index, u8_t status);
void tester_send(u8_t service, u8_t opcode, u8_t index, u8_t *data,
size_t len);
+void tester_send_buf(u8_t service, u8_t opcode, u8_t index,
+ struct os_mbuf *buf);
u8_t tester_init_gap(void);
u8_t tester_unregister_gap(void);
diff --git a/apps/bttester/src/bttester_pipe.h b/apps/bttester/src/bttester_pipe.h
index c3d44a9..c54d42d 100644
--- a/apps/bttester/src/bttester_pipe.h
+++ b/apps/bttester/src/bttester_pipe.h
@@ -30,6 +30,7 @@ extern "C" {
typedef u8_t *(*bttester_pipe_recv_cb)(u8_t *buf, size_t *off);
void bttester_pipe_register(u8_t *buf, size_t len, bttester_pipe_recv_cb cb);
int bttester_pipe_send(const u8_t *data, int len);
+int bttester_pipe_send_buf(struct os_mbuf *buf);
int bttester_pipe_init(void);
#ifdef __cplusplus
diff --git a/apps/bttester/src/uart_pipe.c b/apps/bttester/src/uart_pipe.c
index 63302fb..ecbefa0 100644
--- a/apps/bttester/src/uart_pipe.c
+++ b/apps/bttester/src/uart_pipe.c
@@ -215,6 +215,31 @@ bttester_pipe_send(const u8_t *data, int len)
}
int
+bttester_pipe_send_buf(struct os_mbuf *buf)
+{
+ int i, len;
+ struct os_mbuf *om;
+
+ /* Assure that there is a write cb installed; this enables to debug
+ * code that is faulting before the console was initialized.
+ */
+ if (!write_char_cb) {
+ return -1;
+ }
+
+ for (om = buf; om; om = SLIST_NEXT(om, om_next)) {
+ len = om->om_len;
+ for (i = 0; i < len; ++i) {
+ write_char_cb(uart_dev, om->om_data[i]);
+ }
+ }
+
+ uart_start_tx(uart_dev);
+
+ return 0;
+}
+
+int
bttester_pipe_init(void)
{
struct uart_conf uc = {
[mynewt-nimble] 07/32: apps/bttester: Fix using mbufs
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 5c68cca8d6660fe94d355b0bbe5fb4d49c6c2f9b
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu Apr 25 14:09:10 2019 +0200
apps/bttester: Fix using mbufs
This patch uses send_buf to make sure the whole chain gets
sent, not just the first buffer.
---
apps/bttester/src/gatt.c | 80 +++++++++++++++++++++++++-----------------------
1 file changed, 41 insertions(+), 39 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 8bd04f9..1e53022 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -570,23 +570,27 @@ static size_t read_value(uint16_t conn_handle, uint16_t attr_handle,
ble_uuid_to_str(ctxt->dsc->uuid, str);
}
- rc = os_mbuf_append(ctxt->om, value->buf->om_data, value->buf->om_len);
+ rc = os_mbuf_appendfrom(ctxt->om, value->buf,
+ 0, os_mbuf_len(value->buf));
return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
}
-static void attr_value_changed_ev(u16_t handle, const u8_t *value, u16_t len)
+static void attr_value_changed_ev(u16_t handle, struct os_mbuf *data)
{
- u8_t buf[len + sizeof(struct gatt_attr_value_changed_ev)];
- struct gatt_attr_value_changed_ev *ev = (void *) buf;
+ struct gatt_attr_value_changed_ev *ev;
+ struct os_mbuf *buf = os_msys_get(0, 0);
SYS_LOG_DBG("");
+ net_buf_simple_init(buf, 0);
+ ev = net_buf_simple_add(buf, sizeof(*ev));
+
ev->handle = sys_cpu_to_le16(handle);
- ev->data_length = sys_cpu_to_le16(len);
- memcpy(ev->data, value, len);
+ ev->data_length = sys_cpu_to_le16(os_mbuf_len(data));
+ os_mbuf_appendfrom(buf, data, 0, os_mbuf_len(data));
- tester_send(BTP_SERVICE_ID_GATT, GATT_EV_ATTR_VALUE_CHANGED,
- CONTROLLER_INDEX, buf, sizeof(buf));
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_EV_ATTR_VALUE_CHANGED,
+ CONTROLLER_INDEX, buf);
}
static size_t write_value(uint16_t conn_handle, uint16_t attr_handle,
@@ -594,7 +598,7 @@ static size_t write_value(uint16_t conn_handle, uint16_t attr_handle,
void *arg)
{
struct gatt_value *value = arg;
- uint16_t om_len, len;
+ uint16_t write_len, current_len;
int rc;
SYS_LOG_DBG("");
@@ -609,22 +613,22 @@ static size_t write_value(uint16_t conn_handle, uint16_t attr_handle,
}
}
- om_len = OS_MBUF_PKTLEN(ctxt->om);
- if (om_len > value->buf->om_len) {
+ write_len = os_mbuf_len(ctxt->om);
+ current_len = os_mbuf_len(value->buf);
+
+ SYS_LOG_DBG("current_len = %d", current_len);
+ SYS_LOG_DBG("write_len = %d", write_len);
+ if (write_len > current_len) {
return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
}
- rc = ble_hs_mbuf_to_flat(ctxt->om, value->buf->om_data,
- value->buf->om_len, &len);
+ os_mbuf_adj(value->buf, -current_len);
+ rc = os_mbuf_appendfrom(value->buf, ctxt->om, 0, write_len);
if (rc != 0) {
return BLE_ATT_ERR_UNLIKELY;
}
- /* Maximum attribute value size is 512 bytes */
- assert(value->buf->om_len < 512);
-
- attr_value_changed_ev(attr_handle, value->buf->om_data,
- value->buf->om_len);
+ attr_value_changed_ev(attr_handle, value->buf);
return 0;
}
@@ -791,12 +795,10 @@ static void set_value(u8_t *data, u16_t len)
value_len = sys_le16_to_cpu(cmd->len);
value = cmd->value;
- if (value_len > gatt_value->buf->om_len) {
- os_mbuf_extend(gatt_value->buf,
- (value_len - gatt_value->buf->om_len));
- }
+ os_mbuf_adj(gatt_value->buf, - os_mbuf_len(gatt_value->buf));
+ os_mbuf_append(gatt_value->buf, value, value_len);
- memcpy(gatt_value->buf->om_data, value, value_len);
+ SYS_LOG_DBG("os_mbuf_len = %d", os_mbuf_len(gatt_value->buf));
if (gatt_value->type == GATT_VALUE_TYPE_CHR) {
chr = gatt_value->ptr;
@@ -1704,42 +1706,42 @@ static struct bt_gatt_subscribe_params {
u16_t value_handle;
} subscribe_params;
-/* ev header + default MTU_ATT-3 */
-static u8_t ev_buf[33];
-
int tester_gatt_notify_rx_ev(u16_t conn_handle, u16_t attr_handle,
u8_t indication, struct os_mbuf *om)
{
- struct gatt_notification_ev *ev = (void *) ev_buf;
+ struct gatt_notification_ev *ev;
struct ble_gap_conn_desc conn;
+ struct os_mbuf *buf = os_msys_get(0, 0);
const ble_addr_t *addr;
- int rc;
SYS_LOG_DBG("");
if (!subscribe_params.ccc_handle) {
- return 0;
+ goto fail;
}
- rc = ble_gap_conn_find(conn_handle, &conn);
- if (rc) {
- return -1;
+ if (ble_gap_conn_find(conn_handle, &conn)) {
+ goto fail;
}
+ net_buf_simple_init(buf, 0);
+ ev = net_buf_simple_add(buf, sizeof(*ev));
+
addr = &conn.peer_ota_addr;
+ ev->address_type = addr->type;
+ memcpy(ev->address, addr->val, sizeof(ev->address));
ev->type = (u8_t) (indication ? 0x02 : 0x01);
ev->handle = sys_cpu_to_le16(attr_handle);
- ev->data_length = sys_cpu_to_le16(om->om_len);
- memcpy(ev->data, om->om_data, om->om_len);
- memcpy(ev->address, addr->val, sizeof(ev->address));
- ev->address_type = addr->type;
+ ev->data_length = sys_cpu_to_le16(os_mbuf_len(om));
+ os_mbuf_appendfrom(buf, om, 0, os_mbuf_len(om));
- tester_send(BTP_SERVICE_ID_GATT, GATT_EV_NOTIFICATION,
- CONTROLLER_INDEX, ev_buf, sizeof(*ev) + om->om_len);
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_EV_NOTIFICATION,
+ CONTROLLER_INDEX, buf);
+fail:
+ os_mbuf_free_chain(buf);
return 0;
-
}
int tester_gatt_subscribe_ev(u16_t conn_handle, u16_t attr_handle, u8_t reason,
[mynewt-nimble] 05/32: apps/bttester: Refactor Get Attrs and Get
Attr Value
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 0c8f1b6bd562fab23ed586aa4ecdfdb5f0d07c15
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Fri Apr 19 16:20:13 2019 +0200
apps/bttester: Refactor Get Attrs and Get Attr Value
Use internal ATT api to get attributes and their values.
---
apps/bttester/src/gatt.c | 385 ++++++-----------------------------------------
1 file changed, 46 insertions(+), 339 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index ff3f1dd..55c9cf2 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -33,6 +33,7 @@
#include "host/ble_gatt.h"
#include "console/console.h"
#include "services/gatt/ble_svc_gatt.h"
+#include "../../../nimble/host/src/ble_att_priv.h"
#include "../../../nimble/host/src/ble_gatt_priv.h"
#include "bttester.h"
@@ -40,22 +41,9 @@
#define CONTROLLER_INDEX 0
#define MAX_BUFFER_SIZE 2048
-#define BTP_GATT_PERM_READ 0x01
-
static const ble_uuid16_t BT_UUID_GATT_CEP = BLE_UUID16_INIT(0x2900);
static const ble_uuid16_t BT_UUID_GATT_CCC = BLE_UUID16_INIT(0x2902);
-static const ble_uuid_t *uuid_pri =
- BLE_UUID16_DECLARE(BLE_ATT_UUID_PRIMARY_SERVICE);
-static const ble_uuid_t *uuid_sec =
- BLE_UUID16_DECLARE(BLE_ATT_UUID_SECONDARY_SERVICE);
-static const ble_uuid_t *uuid_inc =
- BLE_UUID16_DECLARE(BLE_ATT_UUID_INCLUDE);
-static const ble_uuid_t *uuid_chr =
- BLE_UUID16_DECLARE(BLE_ATT_UUID_CHARACTERISTIC);
-static const ble_uuid_t *uuid_ccc =
- BLE_UUID16_DECLARE(BLE_GATT_DSC_CLT_CFG_UUID16);
-
static int gatt_chr_perm_map[] = {
BLE_GATT_CHR_F_READ,
BLE_GATT_CHR_F_WRITE,
@@ -1869,144 +1857,17 @@ static void config_subscription(u8_t *data, u16_t len, u8_t op)
tester_rsp(BTP_SERVICE_ID_GATT, op, CONTROLLER_INDEX, status);
}
-struct get_attrs_foreach_data {
- ble_uuid_any_t *uuid;
- u16_t start_handle, end_handle;
- struct os_mbuf *buf;
- u8_t count;
-};
-
-static u8_t foreach_get_attrs(u16_t handle,
- u8_t permission,
- const ble_uuid_t *uuid,
- struct get_attrs_foreach_data *foreach)
-{
- struct gatt_attr *gatt_attr;
- char uuid_buf[BLE_UUID_STR_LEN];
-
- if (handle < foreach->start_handle || handle > foreach->end_handle) {
- return 0;
- }
-
- if (foreach->uuid && ble_uuid_cmp(&foreach->uuid->u, uuid)) {
- return 0;
- }
-
- SYS_LOG_DBG("hdl 0x%04x perm 0x%02x uuid %s", handle, permission,
- ble_uuid_to_str(uuid, uuid_buf));
-
- gatt_attr = net_buf_simple_add(foreach->buf, sizeof(*gatt_attr));
- gatt_attr->handle = sys_cpu_to_le16(handle);
- gatt_attr->permission = permission;
-
- if (uuid->type == BLE_UUID_TYPE_16) {
- gatt_attr->type_length = 2;
- net_buf_simple_add_le16(foreach->buf,
- BLE_UUID16(uuid)->value);
- } else {
- gatt_attr->type_length = 16;
- net_buf_simple_add_mem(foreach->buf,
- BLE_UUID128(uuid)->value,
- gatt_attr->type_length);
- }
-
- foreach->count++;
-
- return 0;
-}
-
-static u8_t flags2perm(u16_t flags, bool chr)
-{
- u8_t permission = 0;
- int *flag_arr;
- int flag_arr_len;
- int i;
-
- if (chr) {
- flag_arr = gatt_chr_perm_map;
- flag_arr_len = ARRAY_SIZE(gatt_chr_perm_map);
-
- /* FIXME: Handle WRITE_NO_RSP */
- if (flags & BLE_GATT_CHR_F_WRITE_NO_RSP) {
- permission |= BIT(1);
- }
- } else {
- flag_arr = gatt_dsc_perm_map;
- flag_arr_len = ARRAY_SIZE(gatt_dsc_perm_map);
- }
-
- for (i = 0; i < flag_arr_len; ++i) {
- if (flags & flag_arr[i]) {
- permission |= BIT(i);
- }
- }
-
- return permission;
-}
-
-static void get_attrs_cb(const struct ble_gatt_svc_def *svc,
- uint16_t handle, uint16_t end_group_handle,
- void *arg)
-{
- struct get_attrs_foreach_data *foreach = arg;
- const struct ble_gatt_svc_def **includes;
- const struct ble_gatt_chr_def *chr;
- const struct ble_gatt_dsc_def *dsc;
-
- SYS_LOG_DBG("");
-
- if (svc->type == BLE_GATT_SVC_TYPE_PRIMARY) {
- foreach_get_attrs(handle, BTP_GATT_PERM_READ,
- uuid_pri, foreach);
- } else if (svc->type == BLE_GATT_SVC_TYPE_SECONDARY) {
- foreach_get_attrs(handle, BTP_GATT_PERM_READ,
- uuid_sec, foreach);
- }
- handle += 1;
-
- if (svc->includes) {
- for (includes = &svc->includes[0];
- *includes != NULL; ++includes) {
- foreach_get_attrs(handle, BTP_GATT_PERM_READ,
- uuid_inc, foreach);
- handle += 1;
- }
- }
-
- for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
- foreach_get_attrs(handle, BTP_GATT_PERM_READ,
- uuid_chr, foreach);
- handle += 1;
-
- foreach_get_attrs(handle, flags2perm(chr->flags, true),
- chr->uuid, foreach);
- handle += 1;
-
- if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
- (chr->flags & BLE_GATT_CHR_F_INDICATE)) {
- foreach_get_attrs(handle,
- flags2perm(BLE_ATT_F_READ |
- BLE_ATT_F_WRITE,
- false), uuid_ccc, foreach);
- handle += 1;
- }
-
- for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
- foreach_get_attrs(handle, flags2perm(chr->flags, false),
- dsc->uuid, foreach);
- handle += 1;
- }
- }
-}
-
static void get_attrs(u8_t *data, u16_t len)
{
const struct gatt_get_attributes_cmd *cmd = (void *) data;
struct gatt_get_attributes_rp *rp;
+ struct gatt_attr *gatt_attr;
struct os_mbuf *buf = os_msys_get(0, 0);
- struct get_attrs_foreach_data foreach;
u16_t start_handle, end_handle;
+ struct ble_att_svr_entry *entry = NULL;
ble_uuid_any_t uuid;
+ ble_uuid_t *uuid_ptr = NULL;
+ u8_t count = 0;
char str[BLE_UUID_STR_LEN];
SYS_LOG_DBG("");
@@ -2025,23 +1886,42 @@ static void get_attrs(u8_t *data, u16_t len)
SYS_LOG_DBG("start 0x%04x end 0x%04x, uuid %s", start_handle,
end_handle, str);
- foreach.uuid = &uuid;
+ uuid_ptr = &uuid.u;
} else {
SYS_LOG_DBG("start 0x%04x end 0x%04x", start_handle, end_handle);
- foreach.uuid = NULL;
}
- net_buf_simple_init(buf, sizeof(*rp));
+ net_buf_simple_init(buf, 0);
+ rp = net_buf_simple_add(buf, sizeof(*rp));
- foreach.start_handle = start_handle;
- foreach.end_handle = end_handle;
- foreach.buf = buf;
- foreach.count = 0;
+ entry = ble_att_svr_find_by_uuid(entry, uuid_ptr, end_handle);
+ while (entry) {
- ble_gatts_lcl_svc_foreach(get_attrs_cb, &foreach);
+ if (entry->ha_handle_id < start_handle) {
+ continue;
+ }
+
+ gatt_attr = net_buf_simple_add(buf, sizeof(*gatt_attr));
+ gatt_attr->handle = sys_cpu_to_le16(entry->ha_handle_id);
+ gatt_attr->permission = entry->ha_flags;
+
+ if (entry->ha_uuid->type == BLE_UUID_TYPE_16) {
+ gatt_attr->type_length = 2;
+ net_buf_simple_add_le16(buf,
+ BLE_UUID16(entry->ha_uuid)->value);
+ } else {
+ gatt_attr->type_length = 16;
+ net_buf_simple_add_mem(buf,
+ BLE_UUID128(entry->ha_uuid)->value,
+ gatt_attr->type_length);
+ }
- rp = (void *) net_buf_simple_push(buf, sizeof(*rp));
- rp->attrs_count = foreach.count;
+ count++;
+
+ entry = ble_att_svr_find_by_uuid(entry, uuid_ptr, end_handle);
+ }
+
+ rp->attrs_count = count;
tester_send_buf(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTES,
CONTROLLER_INDEX, buf);
@@ -2054,201 +1934,28 @@ free:
os_mbuf_free_chain(buf);
}
-static int access_svc(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
- const struct ble_gatt_svc_def *svc = arg;
-
- if (svc->uuid->type == BLE_UUID_TYPE_16) {
- net_buf_simple_add_le16(ctxt->om,
- BLE_UUID16(svc->uuid)->value);
- } else {
- net_buf_simple_add_mem(ctxt->om,
- BLE_UUID128(svc->uuid)->value,
- 16);
- }
-
- return 0;
-}
-
-static int access_incl_svc(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
- const struct ble_gatt_svc_def *svc = arg;
-
- /* TODO: Get included service handle and end group handle */
- net_buf_simple_add_le16(ctxt->om, 0xffff);
- net_buf_simple_add_le16(ctxt->om, 0xffff);
-
- if (svc->uuid->type == BLE_UUID_TYPE_16) {
- net_buf_simple_add_le16(ctxt->om,
- BLE_UUID16(svc->uuid)->value);
- }
-
- return 0;
-}
-
-static int access_chr(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
- const struct ble_gatt_chr_def *chr = arg;
-
- net_buf_simple_add_u8(ctxt->om, flags2perm(chr->flags, true));
- net_buf_simple_add_le16(ctxt->om, *chr->val_handle);
-
- if (chr->uuid->type == BLE_UUID_TYPE_16) {
- net_buf_simple_add_le16(ctxt->om,
- BLE_UUID16(chr->uuid)->value);
- } else {
- net_buf_simple_add_mem(ctxt->om,
- BLE_UUID128(chr->uuid)->value,
- 16);
- }
-
- return 0;
-}
-
-static int access_cccd(uint16_t conn_handle, uint16_t attr_handle,
- struct ble_gatt_access_ctxt *ctxt, void *arg)
-{
- return ble_gatts_clt_cfg_access(conn_handle, attr_handle,
- ctxt->op, 0, &ctxt->om, arg);
-}
-
-static int foreach_get_attr_val(u16_t handle,
- ble_gatt_access_fn access_cb,
- void *arg,
- struct ble_gatt_access_ctxt *ctxt,
- u16_t rx_handle)
-
-{
- struct gatt_get_attribute_value_rp *rp;
- uint16_t hdr_len;
- int rc;
-
- if (handle != rx_handle) {
- return 0;
- }
-
- rp = net_buf_simple_add(ctxt->om, sizeof(*rp));
- hdr_len = ctxt->om->om_len;
-
- rc = access_cb(1, handle, ctxt, arg);
-
- rp->att_response = (uint8_t) rc;
- rp->value_length = ctxt->om->om_len - hdr_len;
-
- return BLE_HS_EDONE;
-}
-
-static void get_attr_val_cb(const struct ble_gatt_svc_def *svc,
- uint16_t handle, uint16_t end_group_handle,
- void *arg)
-{
- struct get_attrs_foreach_data *foreach = arg;
- struct os_mbuf *buf = foreach->buf;
- struct ble_gatt_access_ctxt ctxt;
- const struct ble_gatt_svc_def **includes;
- const struct ble_gatt_chr_def *chr;
- const struct ble_gatt_dsc_def *dsc;
- int rc;
-
- SYS_LOG_DBG("");
-
- ctxt.om = buf;
-
- rc = foreach_get_attr_val(handle, access_svc, (void *) svc,
- &ctxt, foreach->start_handle);
- if (rc == BLE_HS_EDONE) {
- return;
- }
-
- handle += 1;
-
- if (svc->includes) {
- for (includes = &svc->includes[0];
- *includes != NULL; ++includes) {
- svc = *includes;
- foreach_get_attr_val(handle, access_incl_svc,
- (void *) svc, &ctxt,
- foreach->start_handle);
- handle += 1;
- }
- }
-
- for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
- rc = foreach_get_attr_val(handle, access_chr, (void *) chr,
- &ctxt, foreach->start_handle);
- if (rc == BLE_HS_EDONE) {
- return;
- }
-
- handle += 1;
-
- ctxt.op = BLE_GATT_ACCESS_OP_READ_CHR;
- ctxt.chr = chr;
-
- rc = foreach_get_attr_val(handle,
- chr->access_cb, chr->arg,
- &ctxt, foreach->start_handle);
- if (rc == BLE_HS_EDONE) {
- return;
- }
-
- handle += 1;
-
- if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
- (chr->flags & BLE_GATT_CHR_F_INDICATE)) {
- ctxt.op = BLE_GATT_ACCESS_OP_READ_CHR;
-
- rc = foreach_get_attr_val(handle,
- access_cccd, NULL,
- &ctxt, foreach->start_handle);
- if (rc == BLE_HS_EDONE) {
- return;
- }
-
- handle += 1;
- }
-
- for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
- ctxt.op = BLE_GATT_ACCESS_OP_READ_DSC;
- ctxt.dsc = dsc;
-
- rc = foreach_get_attr_val(handle,
- dsc->access_cb, dsc->arg,
- &ctxt, foreach->start_handle);
- if (rc == BLE_HS_EDONE) {
- return;
- }
-
- handle += 1;
- }
- }
-}
-
static void get_attr_val(u8_t *data, u16_t len)
{
const struct gatt_get_attribute_value_cmd *cmd = (void *) data;
+ struct gatt_get_attribute_value_rp *rp;
struct os_mbuf *buf = os_msys_get(0, 0);
- struct get_attrs_foreach_data foreach;
u16_t handle = sys_cpu_to_le16(cmd->handle);
+ uint8_t out_att_err;
+
+ SYS_LOG_DBG("");
- memset(&foreach, 0, sizeof(foreach));
net_buf_simple_init(buf, 0);
+ rp = net_buf_simple_add(buf, sizeof(*rp));
- foreach.buf = buf;
- foreach.start_handle = handle;
+ ble_att_svr_read_handle(BLE_HS_CONN_HANDLE_NONE,
+ handle, 0, buf,
+ &out_att_err);
- ble_gatts_lcl_svc_foreach(get_attr_val_cb, &foreach);
+ rp->att_response = out_att_err;
+ rp->value_length = os_mbuf_len(buf) - sizeof(*rp);
- if (buf->om_len) {
- tester_send(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE,
- CONTROLLER_INDEX, buf->om_data, buf->om_len);
- } else {
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
- }
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_GET_ATTRIBUTE_VALUE,
+ CONTROLLER_INDEX, buf);
os_mbuf_free_chain(buf);
}
[mynewt-nimble] 23/32: apps/bttester: Fix Connection Parameter
Update functionality
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit d13afd47cffb59a7843f364809f21891eec89857
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Mon Aug 26 16:54:32 2019 +0200
apps/bttester: Fix Connection Parameter Update functionality
1. Delete old implementations
2. Call GAP param update api from callout to workaround
an issue with PTS (GAP API waits for a response and PTS would not
send a response until we press OK on a window).
3. Keep sending Parameter update request after connection
is established to workaround a missing WID in L2CAP/LE/CPU/BV-01-C.
---
apps/bttester/src/gap.c | 116 +++++++++++++++++++-----------------------------
1 file changed, 46 insertions(+), 70 deletions(-)
diff --git a/apps/bttester/src/gap.c b/apps/bttester/src/gap.c
index a835ec8..169169e 100644
--- a/apps/bttester/src/gap.c
+++ b/apps/bttester/src/gap.c
@@ -52,6 +52,12 @@ static ble_addr_t peer_id_addr;
static ble_addr_t peer_ota_addr;
static bool encrypted = false;
+struct os_callout update_params_co;
+static struct gap_conn_param_update_cmd update_params;
+
+static void conn_param_update(struct os_event *ev);
+
+
static int gap_conn_find_by_addr(const ble_addr_t *dev_addr,
struct ble_gap_conn_desc *out_desc)
{
@@ -576,44 +582,6 @@ static void stop_discovery(const u8_t *data, u16_t len)
status);
}
-#if MYNEWT_VAL(BTTESTER_CONN_PARAM_UPDATE)
-static void conn_param_update_cb(uint16_t conn_handle, int status, void *arg)
-{
- console_printf("conn param update complete; conn_handle=%d status=%d\n",
- conn_handle, status);
-}
-
-static void conn_param_update_slave(u16_t conn_handle)
-{
- int rc;
- struct ble_l2cap_sig_update_params params;
-
- params.itvl_min = 0x0032;
- params.itvl_max = 0x0046;
- params.slave_latency = 0;
- params.timeout_multiplier = 0x07d0;
-
- rc = ble_l2cap_sig_update(conn_handle, ¶ms,
- conn_param_update_cb, NULL);
- assert(rc == 0);
-}
-
-static void conn_param_update_master(u16_t conn_handle)
-{
- int rc;
- struct ble_gap_upd_params params;
-
- params.itvl_min = 0x0032;
- params.itvl_max = 0x0046;
- params.latency = 0;
- params.supervision_timeout = 0x07d0;
- params.min_ce_len = 0;
- params.max_ce_len = 0;
-
- rc = ble_gap_update_params(conn_handle, ¶ms);
- assert(rc == 0);
-}
-#endif
/* Bluetooth Core Spec v5.1 | Section 10.7.1
* If a privacy-enabled Peripheral, that has a stored bond,
@@ -669,11 +637,14 @@ static void le_connected(u16_t conn_handle, int status)
ev.supervision_timeout = desc.supervision_timeout;
#if MYNEWT_VAL(BTTESTER_CONN_PARAM_UPDATE)
- if (desc.role == BLE_GAP_ROLE_MASTER) {
- conn_param_update_master(conn_handle);
- } else {
- conn_param_update_slave(conn_handle);
- }
+ memcpy(update_params.address, addr->val, sizeof(ev.address));
+ update_params.address_type = addr->type;
+ update_params.conn_itvl_min = desc.conn_itvl;
+ update_params.conn_itvl_max = desc.conn_itvl;
+ update_params.conn_latency = desc.conn_latency + 1;
+ update_params.supervision_timeout = desc.supervision_timeout;
+
+ conn_param_update(NULL);
#endif
tester_send(BTP_SERVICE_ID_GAP, GAP_EV_DEVICE_CONNECTED,
@@ -1310,15 +1281,8 @@ fail:
static void conn_param_update_cb(uint16_t conn_handle, int status, void *arg)
{
- u8_t btp_status;
-
console_printf("conn param update complete; conn_handle=%d status=%d\n",
conn_handle, status);
-
- btp_status = status ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS;
-
- tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONN_PARAM_UPDATE,
- CONTROLLER_INDEX, btp_status);
}
static int conn_param_update_slave(u16_t conn_handle,
@@ -1335,8 +1299,7 @@ static int conn_param_update_slave(u16_t conn_handle,
rc = ble_l2cap_sig_update(conn_handle, ¶ms,
conn_param_update_cb, NULL);
if (rc) {
- tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONN_PARAM_UPDATE,
- CONTROLLER_INDEX, BTP_STATUS_FAILED);
+ SYS_LOG_ERR("Failed to send update params: rc=%d", rc);
}
return 0;
@@ -1352,6 +1315,8 @@ static int conn_param_update_master(u16_t conn_handle,
params.itvl_max = cmd->conn_itvl_max;
params.latency = cmd->conn_latency;
params.supervision_timeout = cmd->supervision_timeout;
+ params.min_ce_len = 0;
+ params.max_ce_len = 0;
rc = ble_gap_update_params(conn_handle, ¶ms);
if (rc) {
SYS_LOG_ERR("Failed to send update params: rc=%d", rc);
@@ -1360,43 +1325,51 @@ static int conn_param_update_master(u16_t conn_handle,
return rc;
}
-static void conn_param_update(const u8_t *data, u16_t len)
+struct os_callout update_params_co;
+static struct gap_conn_param_update_cmd update_params;
+
+static void conn_param_update(struct os_event *ev)
{
- const struct gap_conn_param_update_cmd *cmd = (void *) data;
struct ble_gap_conn_desc desc;
- u8_t status = BTP_STATUS_SUCCESS;
int rc;
SYS_LOG_DBG("");
- rc = gap_conn_find_by_addr((ble_addr_t *)data, &desc);
+ rc = gap_conn_find_by_addr((ble_addr_t *)&update_params, &desc);
if (rc) {
- status = BTP_STATUS_FAILED;
goto rsp;
}
- if ((desc.conn_itvl >= cmd->conn_itvl_min) &&
- (desc.conn_itvl <= cmd->conn_itvl_max) &&
- (desc.conn_latency == cmd->conn_latency) &&
- (desc.supervision_timeout == cmd->supervision_timeout)) {
+ if ((desc.conn_itvl >= update_params.conn_itvl_min) &&
+ (desc.conn_itvl <= update_params.conn_itvl_max) &&
+ (desc.conn_latency == update_params.conn_latency) &&
+ (desc.supervision_timeout == update_params.supervision_timeout)) {
goto rsp;
}
if (desc.role == BLE_GAP_ROLE_MASTER) {
- rc = conn_param_update_master(desc.conn_handle, cmd);
+ rc = conn_param_update_master(desc.conn_handle, &update_params);
} else {
- rc = conn_param_update_slave(desc.conn_handle, cmd);
- if (!rc) {
- /* Response will be sent from callback */
- return;
- }
+ rc = conn_param_update_slave(desc.conn_handle, &update_params);
}
- status = rc ? BTP_STATUS_FAILED : BTP_STATUS_SUCCESS;
+ if (rc == 0) {
+ return;
+ }
rsp:
+ SYS_LOG_ERR("Conn param update fail; rc=%d", rc);
+}
+
+static void conn_param_update_async(const u8_t *data, u16_t len)
+{
+ const struct gap_conn_param_update_cmd *cmd = (void *) data;
+ update_params = *cmd;
+
+ os_callout_reset(&update_params_co, 0);
+
tester_rsp(BTP_SERVICE_ID_GAP, GAP_CONN_PARAM_UPDATE, CONTROLLER_INDEX,
- status);
+ BTP_STATUS_SUCCESS);
}
void tester_handle_gap(u8_t opcode, u8_t index, u8_t *data,
@@ -1473,7 +1446,7 @@ void tester_handle_gap(u8_t opcode, u8_t index, u8_t *data,
start_direct_adv(data, len);
return;
case GAP_CONN_PARAM_UPDATE:
- conn_param_update(data, len);
+ conn_param_update_async(data, len);
return;
default:
tester_rsp(BTP_SERVICE_ID_GAP, opcode, index,
@@ -1495,6 +1468,9 @@ static void tester_init_gap_cb(int err)
current_settings |= BIT(GAP_SETTINGS_BONDABLE);
current_settings |= BIT(GAP_SETTINGS_LE);
+ os_callout_init(&update_params_co, os_eventq_dflt_get(),
+ conn_param_update, NULL);
+
tester_rsp(BTP_SERVICE_ID_CORE, CORE_REGISTER_SERVICE, BTP_INDEX_NONE,
BTP_STATUS_SUCCESS);
}
[mynewt-nimble] 28/32: apps/bttester: Fix change_database
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 2344704bed5b969f67679a7ca9ed43d7c812f810
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Mon Aug 26 16:52:59 2019 +0200
apps/bttester: Fix change_database
This method is used to issue service change notification and
we don't need to actually change the database to end that.
---
apps/bttester/src/gatt.c | 10 ----------
1 file changed, 10 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index f295949..1741d3d 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1672,15 +1672,9 @@ free:
static void change_database(u8_t *data, u16_t len)
{
const struct gatt_change_database *cmd = (void *) data;
- int rc;
SYS_LOG_DBG("")
- rc = ble_gatts_svc_set_visibility(cmd->start_handle, cmd->visibility);
- if (rc) {
- goto fail;
- }
-
ble_gatts_show_local();
ble_svc_gatt_changed(cmd->start_handle, cmd->end_handle);
@@ -1689,10 +1683,6 @@ static void change_database(u8_t *data, u16_t len)
BTP_STATUS_SUCCESS);
return;
-
-fail:
- tester_rsp(BTP_SERVICE_ID_GATT, GATT_CHANGE_DATABASE, CONTROLLER_INDEX,
- BTP_STATUS_FAILED);
}
static void supported_commands(u8_t *data, u16_t len)
[mynewt-nimble] 08/32: apps/bttester: Improve add attributes and
set value
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 472485aa1c956e675e95430bd98af2e770d16f8b
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu Apr 25 14:13:44 2019 +0200
apps/bttester: Improve add attributes and set value
With this patch the add_service, etc. returns a attribute handle
in response, which can later be used to perform gatt reads/writes.
Additionally you can use these handles in set_value and
set_enc_key_size commands.
---
apps/bttester/src/gatt.c | 284 ++++++++++++++++++++++++++++++-----------------
1 file changed, 184 insertions(+), 100 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 1e53022..3a9b587 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -41,9 +41,6 @@
#define CONTROLLER_INDEX 0
#define MAX_BUFFER_SIZE 2048
-static const ble_uuid16_t BT_UUID_GATT_CEP = BLE_UUID16_INIT(0x2900);
-static const ble_uuid16_t BT_UUID_GATT_CCC = BLE_UUID16_INIT(0x2902);
-
static int gatt_chr_perm_map[] = {
BLE_GATT_CHR_F_READ,
BLE_GATT_CHR_F_WRITE,
@@ -150,15 +147,6 @@ static void gatt_buf_clear(void)
(void)memset(&gatt_buf, 0, sizeof(gatt_buf));
}
-struct gatt_value *find_gatt_value_by_id(u16_t id)
-{
- if (id < SERVER_MAX_VALUES) {
- return &gatt_values[id];
- }
-
- return NULL;
-}
-
static int gatt_svr_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt,
void *arg);
@@ -423,76 +411,113 @@ static void supported_commands(u8_t *data, u16_t len)
CONTROLLER_INDEX, (u8_t *) rp, sizeof(cmds));
}
-const struct ble_gatt_svc_def *find_svc(ble_uuid_any_t *uuid)
+enum attr_type {
+ BLE_GATT_ATTR_SVC = 0,
+ BLE_GATT_ATTR_CHR,
+ BLE_GATT_ATTR_DSC,
+};
+
+struct find_attr_data {
+ ble_uuid_any_t *uuid;
+ int attr_type;
+ void *ptr;
+ uint16_t handle;
+};
+
+static void find_attr_by_uuid_cb(const struct ble_gatt_svc_def *svc,
+ uint16_t handle, uint16_t end_group_handle,
+ void *arg)
{
- const struct ble_gatt_svc_def *svc;
+ struct find_attr_data *foreach = arg;
+ const struct ble_gatt_svc_def **includes;
+ const struct ble_gatt_chr_def *chr;
+ const struct ble_gatt_dsc_def *dsc;
- for (svc = gatt_svr_svcs; svc && svc->uuid; svc++) {
- if (ble_uuid_cmp(&uuid->u, svc->uuid) == 0) {
- return svc;
- }
+ SYS_LOG_DBG("");
+
+ if (foreach->attr_type == BLE_GATT_ATTR_SVC &&
+ ble_uuid_cmp(&foreach->uuid->u, svc->uuid) == 0) {
+ foreach->ptr = (void *) svc;
+ foreach->handle = handle;
+ return;
}
+ handle += 1;
- for (svc = gatt_svr_inc_svcs; svc && svc->uuid; svc++) {
- if (ble_uuid_cmp(&uuid->u, svc->uuid) == 0) {
- return svc;
+ if (svc->includes) {
+ for (includes = &svc->includes[0];
+ *includes != NULL; ++includes) {
+ handle += 1;
}
}
- return NULL;
-}
-
-const struct ble_gatt_chr_def *find_chr(ble_uuid_any_t *uuid)
-{
- const struct ble_gatt_svc_def *svc;
- const struct ble_gatt_chr_def *chr;
+ for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
+ if (foreach->attr_type == BLE_GATT_ATTR_CHR &&
+ ble_uuid_cmp(&foreach->uuid->u, chr->uuid) == 0) {
+ foreach->ptr = (void *) chr;
+ foreach->handle = handle;
+ return;
+ }
+ handle += 2;
- for (svc = gatt_svr_svcs; svc && svc->uuid; svc++) {
- for (chr = svc->characteristics; chr && chr->uuid; chr++) {
- if (ble_uuid_cmp(&uuid->u, chr->uuid) == 0) {
- return chr;
- }
+ if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
+ (chr->flags & BLE_GATT_CHR_F_INDICATE)) {
+ handle += 1;
}
- }
- for (svc = gatt_svr_inc_svcs; svc && svc->uuid; svc++) {
- for (chr = svc->characteristics; chr && chr->uuid; chr++) {
- if (ble_uuid_cmp(&uuid->u, chr->uuid) == 0) {
- return chr;
+ for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
+ if (foreach->attr_type == BLE_GATT_ATTR_DSC &&
+ ble_uuid_cmp(&foreach->uuid->u, dsc->uuid) == 0) {
+ foreach->ptr = (void *) dsc;
+ foreach->handle = handle;
+ return;
}
+ handle += 1;
}
}
-
- return NULL;
}
-const struct ble_gatt_dsc_def *find_dsc(ble_uuid_any_t *uuid)
+static void find_attr_by_handle_cb(const struct ble_gatt_svc_def *svc,
+ uint16_t handle, uint16_t end_group_handle,
+ void *arg)
{
- const struct ble_gatt_svc_def *svc;
+ struct find_attr_data *foreach = arg;
+ const struct ble_gatt_svc_def **includes;
const struct ble_gatt_chr_def *chr;
const struct ble_gatt_dsc_def *dsc;
- for (svc = gatt_svr_svcs; svc && svc->uuid; svc++) {
- for (chr = svc->characteristics; chr && chr->uuid; chr++) {
- for (dsc = chr->descriptors; dsc && dsc->uuid; dsc++) {
- if (ble_uuid_cmp(&uuid->u, dsc->uuid) == 0) {
- return dsc;
- }
- }
+ SYS_LOG_DBG("");
+
+ handle += 1;
+
+ if (svc->includes) {
+ for (includes = &svc->includes[0];
+ *includes != NULL; ++includes) {
+ handle += 1;
}
}
- for (svc = gatt_svr_inc_svcs; svc && svc->uuid; svc++) {
- for (chr = svc->characteristics; chr && chr->uuid; chr++) {
- for (dsc = chr->descriptors; dsc && dsc->uuid; dsc++) {
- if (ble_uuid_cmp(&uuid->u, dsc->uuid) == 0) {
- return dsc;
- }
+ for (chr = svc->characteristics; chr && chr->uuid; ++chr) {
+ if (handle == foreach->handle) {
+ foreach->attr_type = BLE_GATT_ATTR_CHR;
+ foreach->ptr = (void *) chr;
+ return;
+ }
+ handle += 2;
+
+ if ((chr->flags & BLE_GATT_CHR_F_NOTIFY) ||
+ (chr->flags & BLE_GATT_CHR_F_INDICATE)) {
+ handle += 1;
+ }
+
+ for (dsc = chr->descriptors; dsc && dsc->uuid; ++dsc) {
+ if (handle == foreach->handle) {
+ foreach->attr_type = BLE_GATT_ATTR_CHR;
+ foreach->ptr = (void *) dsc;
+ return;
}
+ handle += 1;
}
}
-
- return NULL;
}
static void add_service(u8_t *data, u16_t len)
@@ -500,12 +525,14 @@ static void add_service(u8_t *data, u16_t len)
const struct gatt_add_service_cmd *cmd = (void *) data;
struct gatt_add_service_rp rp;
const struct ble_gatt_svc_def *svc;
+ struct find_attr_data find_data;
ble_uuid_any_t uuid;
int type;
SYS_LOG_DBG("");
if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
+ SYS_LOG_ERR("Invalid service UUID");
goto fail;
}
@@ -521,19 +548,25 @@ static void add_service(u8_t *data, u16_t len)
goto fail;
}
- svc = find_svc(&uuid);
+ memset(&find_data, 0, sizeof(find_data));
+
+ find_data.uuid = &uuid;
+ find_data.attr_type = BLE_GATT_ATTR_SVC;
+
+ ble_gatts_lcl_svc_foreach(find_attr_by_uuid_cb, &find_data);
+
+ svc = find_data.ptr;
if (svc == NULL) {
- SYS_LOG_ERR("Invalid service UUID");
+ SYS_LOG_ERR("Could not find service");
goto fail;
}
if (type != svc->type) {
- SYS_LOG_ERR("Invalid service type");
+ SYS_LOG_ERR("Service type mismatch");
goto fail;
}
- /* TODO: set svc id */
- rp.svc_id = 0;
+ rp.svc_id = find_data.handle;
tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_SERVICE, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
@@ -666,6 +699,7 @@ static void add_characteristic(u8_t *data, u16_t len)
const struct gatt_add_characteristic_cmd *cmd = (void *) data;
struct gatt_add_characteristic_rp rp;
const struct ble_gatt_chr_def *chr;
+ struct find_attr_data find_data;
ble_uuid_any_t uuid;
uint16_t flags = 0;
int i;
@@ -673,11 +707,25 @@ static void add_characteristic(u8_t *data, u16_t len)
SYS_LOG_DBG("");
if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
+ SYS_LOG_ERR("Invalid characteristic UUID");
goto fail;
}
- /* characterisic must be added sequentially */
if (cmd->svc_id) {
+ SYS_LOG_ERR("Characteristic must be added sequentially");
+ goto fail;
+ }
+
+ memset(&find_data, 0, sizeof(find_data));
+
+ find_data.uuid = &uuid;
+ find_data.attr_type = BLE_GATT_ATTR_CHR;
+
+ ble_gatts_lcl_svc_foreach(find_attr_by_uuid_cb, &find_data);
+
+ chr = find_data.ptr;
+ if (chr == NULL) {
+ SYS_LOG_ERR("Could not find characteristic");
goto fail;
}
@@ -687,19 +735,12 @@ static void add_characteristic(u8_t *data, u16_t len)
}
}
- chr = find_chr(&uuid);
- if (chr == NULL) {
- SYS_LOG_ERR("Invalid characteristic UUID");
- goto fail;
- }
-
if ((chr->flags > 0) && ((flags & chr->flags) == 0)) {
SYS_LOG_ERR("Invalid flags");
goto fail;
}
- /* TODO: Set char id */
- rp.char_id = 0;
+ rp.char_id = find_data.handle;
tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_CHARACTERISTIC,
CONTROLLER_INDEX, (u8_t *) &rp, sizeof(rp));
@@ -715,6 +756,7 @@ static void add_descriptor(u8_t *data, u16_t len)
const struct gatt_add_descriptor_cmd *cmd = (void *) data;
struct gatt_add_descriptor_rp rp;
const struct ble_gatt_dsc_def *dsc;
+ struct find_attr_data find_data;
ble_uuid_any_t uuid;
uint16_t att_flags = 0;
int i;
@@ -722,40 +764,43 @@ static void add_descriptor(u8_t *data, u16_t len)
SYS_LOG_DBG("");
if (btp2bt_uuid(cmd->uuid, cmd->uuid_length, &uuid)) {
+ SYS_LOG_ERR("Invalid descriptor UUID");
goto fail;
}
- /* descriptor can be added only sequentially */
if (cmd->char_id) {
+ SYS_LOG_ERR("Descriptor must be added sequentially");
goto fail;
}
- att_flags = cmd->permissions;
+ memset(&find_data, 0, sizeof(find_data));
- if (!ble_uuid_cmp(&uuid.u, &BT_UUID_GATT_CEP.u)) {
- /* TODO: */
- } else if (!ble_uuid_cmp(&uuid.u, &BT_UUID_GATT_CCC.u)) {
- /* handled by host */
- } else {
- dsc = find_dsc(&uuid);
- if (dsc == NULL) {
- SYS_LOG_ERR("Invalid characteristic UUID");
- goto fail;
- }
+ find_data.uuid = &uuid;
+ find_data.attr_type = BLE_GATT_ATTR_DSC;
- for (i = 0; i < 8; ++i) {
- if (cmd->permissions & BIT(i)) {
- att_flags |= gatt_dsc_perm_map[i];
- }
- }
+ ble_gatts_lcl_svc_foreach(find_attr_by_uuid_cb, &find_data);
- if ((att_flags & dsc->att_flags) == 0) {
- SYS_LOG_ERR("Invalid flags");
- goto fail;
+ dsc = find_data.ptr;
+ if (dsc == NULL) {
+ SYS_LOG_ERR("Could not find descriptor");
+ goto fail;
+ }
+
+ att_flags = cmd->permissions;
+
+ for (i = 0; i < 8; ++i) {
+ if (cmd->permissions & BIT(i)) {
+ att_flags |= gatt_dsc_perm_map[i];
}
}
- rp.desc_id = 0;
+ if ((att_flags & dsc->att_flags) == 0) {
+ SYS_LOG_ERR("Invalid flags");
+ goto fail;
+ }
+
+ rp.desc_id = find_data.handle;
+
tester_send(BTP_SERVICE_ID_GATT, GATT_ADD_DESCRIPTOR, CONTROLLER_INDEX,
(u8_t *) &rp, sizeof(rp));
return;
@@ -782,14 +827,30 @@ static void set_value(u8_t *data, u16_t len)
{
const struct gatt_set_value_cmd *cmd = (void *) data;
const struct ble_gatt_chr_def *chr;
- struct gatt_value *gatt_value;
+ struct find_attr_data find_data;
+ struct gatt_value *gatt_value = NULL;
u16_t value_len;
const u8_t *value;
SYS_LOG_DBG("%d id", cmd->attr_id);
- gatt_value = find_gatt_value_by_id(
- sys_le16_to_cpu(cmd->attr_id));
+ memset(&find_data, 0, sizeof(find_data));
+
+ find_data.handle = sys_le16_to_cpu(cmd->attr_id);
+
+ ble_gatts_lcl_svc_foreach(find_attr_by_handle_cb, &find_data);
+
+ if (find_data.ptr == NULL) {
+ SYS_LOG_ERR("Could not find attribute");
+ goto fail;
+ }
+
+ if (find_data.attr_type == BLE_GATT_ATTR_CHR) {
+ gatt_value = ((struct ble_gatt_chr_def *)find_data.ptr)->arg;
+ } else if (find_data.attr_type == BLE_GATT_ATTR_DSC) {
+ gatt_value = ((struct ble_gatt_dsc_def *)find_data.ptr)->arg;
+ }
+
assert(gatt_value != NULL);
value_len = sys_le16_to_cpu(cmd->len);
@@ -810,6 +871,11 @@ static void set_value(u8_t *data, u16_t len)
tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_VALUE, CONTROLLER_INDEX,
BTP_STATUS_SUCCESS);
+ return;
+
+fail:
+ tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_VALUE,
+ CONTROLLER_INDEX, BTP_STATUS_FAILED);
}
static void start_server(u8_t *data, u16_t len)
@@ -832,16 +898,34 @@ static void start_server(u8_t *data, u16_t len)
static void set_enc_key_size(u8_t *data, u16_t len)
{
const struct gatt_set_enc_key_size_cmd *cmd = (void *) data;
- struct gatt_value *val;
- u8_t status = 0;
+ struct find_attr_data find_data;
+ struct gatt_value *val = NULL;
+ u8_t status = BTP_STATUS_SUCCESS;
/* Fail if requested key size is invalid */
if (cmd->key_size < 0x07 || cmd->key_size > 0x0f) {
status = BTP_STATUS_FAILED;
- goto fail;
+ goto done;
+ }
+
+ memset(&find_data, 0, sizeof(find_data));
+
+ find_data.handle = sys_le16_to_cpu(cmd->attr_id);
+
+ ble_gatts_lcl_svc_foreach(find_attr_by_handle_cb, &find_data);
+
+ if (find_data.ptr == NULL) {
+ SYS_LOG_ERR("Could not find attribute");
+ status = BTP_STATUS_FAILED;
+ goto done;
+ }
+
+ if (find_data.attr_type == BLE_GATT_ATTR_CHR) {
+ val = ((struct ble_gatt_chr_def *)find_data.ptr)->arg;
+ } else if (find_data.attr_type == BLE_GATT_ATTR_DSC) {
+ val = ((struct ble_gatt_dsc_def *)find_data.ptr)->arg;
}
- val = find_gatt_value_by_id(sys_le16_to_cpu(cmd->attr_id));
assert(val != NULL);
assert(val->ptr != NULL);
@@ -858,7 +942,7 @@ static void set_enc_key_size(u8_t *data, u16_t len)
break;
}
-fail:
+done:
tester_rsp(BTP_SERVICE_ID_GATT, GATT_SET_ENC_KEY_SIZE, CONTROLLER_INDEX,
status);
}
[mynewt-nimble] 29/32: apps/bttester: Add Attribute Value Changed
event
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit eacaa48177d9ba1ad84d9484c7d0452ef2f2e8a8
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu Aug 29 11:58:31 2019 +0200
apps/bttester: Add Attribute Value Changed event
---
apps/bttester/src/gatt.c | 47 ++++++++++++++++++++++++++++++++++++++---------
1 file changed, 38 insertions(+), 9 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 1741d3d..4b389c7 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -227,8 +227,27 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = {
},
};
+static void attr_value_changed_ev(u16_t handle, struct os_mbuf *data)
+{
+ struct gatt_attr_value_changed_ev *ev;
+ struct os_mbuf *buf = os_msys_get(0, 0);
+
+ SYS_LOG_DBG("");
+
+ net_buf_simple_init(buf, 0);
+ ev = net_buf_simple_add(buf, sizeof(*ev));
+
+ ev->handle = sys_cpu_to_le16(handle);
+ ev->data_length = sys_cpu_to_le16(os_mbuf_len(data));
+ os_mbuf_appendfrom(buf, data, 0, os_mbuf_len(data));
+
+ tester_send_buf(BTP_SERVICE_ID_GATT, GATT_EV_ATTR_VALUE_CHANGED,
+ CONTROLLER_INDEX, buf);
+}
+
static int
-gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
+gatt_svr_chr_write(uint16_t conn_handle, uint16_t attr_handle,
+ struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
void *dst, uint16_t *len)
{
uint16_t om_len;
@@ -244,6 +263,8 @@ gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len,
return BLE_ATT_ERR_UNLIKELY;
}
+ attr_value_changed_ev(attr_handle, om);
+
return 0;
}
@@ -273,7 +294,8 @@ gatt_svr_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_CHR_READ_WRITE:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_short_val,
&gatt_svr_pts_static_short_val, NULL);
return rc;
@@ -303,7 +325,8 @@ gatt_svr_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
case PTS_LONG_CHR_READ_WRITE:
case PTS_LONG_CHR_READ_WRITE_ALT:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_long_val,
&gatt_svr_pts_static_long_val, NULL);
return rc;
@@ -332,7 +355,8 @@ gatt_svr_read_write_auth_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_CHR_READ_WRITE_AUTHEN:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_val,
&gatt_svr_pts_static_val, NULL);
return rc;
@@ -365,7 +389,8 @@ gatt_svr_read_write_enc_test(uint16_t conn_handle, uint16_t attr_handle,
sizeof gatt_svr_pts_static_val);
return rc;
} else if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_val,
&gatt_svr_pts_static_val, NULL);
return rc;
@@ -390,7 +415,8 @@ gatt_svr_dsc_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_DSC_READ_WRITE:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_short_val,
&gatt_svr_pts_static_short_val, NULL);
return rc;
@@ -419,7 +445,8 @@ gatt_svr_dsc_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_LONG_DSC_READ_WRITE:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_long_val,
&gatt_svr_pts_static_long_val, NULL);
return rc;
@@ -472,7 +499,8 @@ gatt_svr_write_no_rsp_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_CHR_WRITE_NO_RSP:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_short_val,
&gatt_svr_pts_static_short_val, NULL);
return rc;
@@ -501,7 +529,8 @@ gatt_svr_rel_write_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_CHR_RELIABLE_WRITE:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
+ rc = gatt_svr_chr_write(conn_handle, attr_handle,
+ ctxt->om, 0,
sizeof gatt_svr_pts_static_val,
&gatt_svr_pts_static_val, NULL);
return rc;
[mynewt-nimble] 27/32: apps/bttester: Fix gatt svr access callbacks
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit fc6e29a2896191f8eccfa03d4be1d15c2af5fba1
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Fri Aug 23 15:46:19 2019 +0200
apps/bttester: Fix gatt svr access callbacks
---
apps/bttester/src/gatt.c | 114 ++++++++++++++++++-----------------------------
1 file changed, 43 insertions(+), 71 deletions(-)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index 22da3fe..f295949 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -271,17 +271,17 @@ gatt_svr_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
assert(uuid16 != 0);
switch (uuid16) {
- case PTS_CHR_READ_WRITE:
- if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
- sizeof gatt_svr_pts_static_short_val,
- &gatt_svr_pts_static_short_val, NULL);
- return rc;
- } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_short_val,
- sizeof gatt_svr_pts_static_short_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- }
+ case PTS_CHR_READ_WRITE:
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_short_val,
+ &gatt_svr_pts_static_short_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_short_val,
+ sizeof gatt_svr_pts_static_short_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
default:
assert(0);
return BLE_ATT_ERR_UNLIKELY;
@@ -301,27 +301,17 @@ gatt_svr_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_LONG_CHR_READ_WRITE:
- if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
- sizeof gatt_svr_pts_static_long_val,
- &gatt_svr_pts_static_long_val, NULL);
- return rc;
- } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
- sizeof gatt_svr_pts_static_long_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- }
case PTS_LONG_CHR_READ_WRITE_ALT:
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
rc = gatt_svr_chr_write(ctxt->om, 0,
sizeof gatt_svr_pts_static_long_val,
&gatt_svr_pts_static_long_val, NULL);
return rc;
- } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
- sizeof gatt_svr_pts_static_long_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- }
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
+ sizeof gatt_svr_pts_static_long_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
default:
assert(0);
return BLE_ATT_ERR_UNLIKELY;
@@ -341,25 +331,16 @@ gatt_svr_read_write_auth_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_CHR_READ_WRITE_AUTHEN:
- if (ctxt->op == BLE_GATT_CHR_F_WRITE_AUTHEN) {
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
rc = gatt_svr_chr_write(ctxt->om, 0,
sizeof gatt_svr_pts_static_val,
&gatt_svr_pts_static_val, NULL);
return rc;
- } else if (ctxt->op == BLE_GATT_CHR_F_READ_AUTHEN) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
- sizeof gatt_svr_pts_static_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- } else if (BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
- sizeof gatt_svr_pts_static_val,
- &gatt_svr_pts_static_val, NULL);
- return rc;
- } else if (BLE_GATT_ACCESS_OP_READ_CHR) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
- sizeof gatt_svr_pts_static_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- }
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
+ sizeof gatt_svr_pts_static_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
default:
assert(0);
return BLE_ATT_ERR_UNLIKELY;
@@ -383,21 +364,12 @@ gatt_svr_read_write_enc_test(uint16_t conn_handle, uint16_t attr_handle,
rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
sizeof gatt_svr_pts_static_val);
return rc;
- } else if (ctxt->op == BLE_GATT_CHR_F_READ_ENC) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_val,
- sizeof gatt_svr_pts_static_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- } else if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
- sizeof gatt_svr_pts_static_val,
- &gatt_svr_pts_static_val, NULL);
- return rc;
- } else if (ctxt->op == BLE_GATT_CHR_F_WRITE_ENC) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
- sizeof gatt_svr_pts_static_val,
- &gatt_svr_pts_static_val, NULL);
- return rc;
- }
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_val,
+ &gatt_svr_pts_static_val, NULL);
+ return rc;
+ }
default:
assert(0);
return BLE_ATT_ERR_UNLIKELY;
@@ -422,11 +394,11 @@ gatt_svr_dsc_read_write_test(uint16_t conn_handle, uint16_t attr_handle,
sizeof gatt_svr_pts_static_short_val,
&gatt_svr_pts_static_short_val, NULL);
return rc;
- } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_short_val,
- sizeof gatt_svr_pts_static_short_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- }
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_short_val,
+ sizeof gatt_svr_pts_static_short_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
default:
assert(0);
return BLE_ATT_ERR_UNLIKELY;
@@ -446,16 +418,16 @@ gatt_svr_dsc_read_write_long_test(uint16_t conn_handle, uint16_t attr_handle,
switch (uuid16) {
case PTS_LONG_DSC_READ_WRITE:
- if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
- rc = gatt_svr_chr_write(ctxt->om, 0,
- sizeof gatt_svr_pts_static_long_val,
- &gatt_svr_pts_static_long_val, NULL);
- return rc;
- } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
- rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
- sizeof gatt_svr_pts_static_long_val);
- return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
- }
+ if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_DSC) {
+ rc = gatt_svr_chr_write(ctxt->om, 0,
+ sizeof gatt_svr_pts_static_long_val,
+ &gatt_svr_pts_static_long_val, NULL);
+ return rc;
+ } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) {
+ rc = os_mbuf_append(ctxt->om, &gatt_svr_pts_static_long_val,
+ sizeof gatt_svr_pts_static_long_val);
+ return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+ }
default:
assert(0);
return BLE_ATT_ERR_UNLIKELY;
[mynewt-nimble] 21/32: apps/bttester: Fix get_attributes infinite
loop
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit e02b84115913f05835fe76d3c4cf11c71ad7b980
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Thu May 30 16:19:48 2019 +0200
apps/bttester: Fix get_attributes infinite loop
The entry variable was not updated in some cases.
---
apps/bttester/src/gatt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index a69fa57..2009459 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1994,6 +1994,8 @@ static void get_attrs(u8_t *data, u16_t len)
while (entry) {
if (entry->ha_handle_id < start_handle) {
+ entry = ble_att_svr_find_by_uuid(entry,
+ uuid_ptr, end_handle);
continue;
}
[mynewt-nimble] 32/32: apps/bttester: Fix mbuf handling in Mesh
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 7340e6cfbeb123292717ba1dbec53e3283c0b013
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Sep 4 10:27:52 2019 +0200
apps/bttester: Fix mbuf handling in Mesh
---
apps/bttester/src/mesh.c | 17 +++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)
diff --git a/apps/bttester/src/mesh.c b/apps/bttester/src/mesh.c
index 05c320d..6bac3cc 100644
--- a/apps/bttester/src/mesh.c
+++ b/apps/bttester/src/mesh.c
@@ -117,8 +117,8 @@ static void supported_commands(u8_t *data, u16_t len)
#endif /* CONFIG_BT_TESTING */
tester_set_bit(buf->om_data, MESH_PROXY_IDENTITY);
- tester_send(BTP_SERVICE_ID_MESH, MESH_READ_SUPPORTED_COMMANDS,
- CONTROLLER_INDEX, buf->om_data, buf->om_len);
+ tester_send_buf(BTP_SERVICE_ID_MESH, MESH_READ_SUPPORTED_COMMANDS,
+ CONTROLLER_INDEX, buf);
}
static struct bt_mesh_cfg_srv cfg_srv = {
@@ -350,9 +350,10 @@ static int output_string(const char *str)
net_buf_simple_add_mem(buf, str, ev->string_len);
- tester_send(BTP_SERVICE_ID_MESH, MESH_EV_OUT_STRING_ACTION,
- CONTROLLER_INDEX, buf->om_data, buf->om_len);
+ tester_send_buf(BTP_SERVICE_ID_MESH, MESH_EV_OUT_STRING_ACTION,
+ CONTROLLER_INDEX, buf);
+ os_mbuf_free_chain(buf);
return 0;
}
@@ -653,8 +654,8 @@ static void health_generate_faults(u8_t *data, u16_t len)
bt_mesh_fault_update(&elements[0]);
- tester_send(BTP_SERVICE_ID_MESH, MESH_HEALTH_GENERATE_FAULTS,
- CONTROLLER_INDEX, buf->om_data, buf->om_len);
+ tester_send_buf(BTP_SERVICE_ID_MESH, MESH_HEALTH_GENERATE_FAULTS,
+ CONTROLLER_INDEX, buf);
}
static void health_clear_faults(u8_t *data, u16_t len)
@@ -876,8 +877,8 @@ void net_recv_ev(u8_t ttl, u8_t ctl, u16_t src, u16_t dst, const void *payload,
ev->payload_len = payload_len;
net_buf_simple_add_mem(buf, payload, payload_len);
- tester_send(BTP_SERVICE_ID_MESH, MESH_EV_NET_RECV, CONTROLLER_INDEX,
- buf->om_data, buf->om_len);
+ tester_send_buf(BTP_SERVICE_ID_MESH, MESH_EV_NET_RECV, CONTROLLER_INDEX,
+ buf);
done:
os_mbuf_free_chain(buf);
}
[mynewt-nimble] 18/32: apps/bttester: Add missing return buf check
Posted by na...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
naraj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 951abc9c3501d803e4266e6e7ce898e53e3bbfef
Author: Michał Narajowski <mi...@codecoup.pl>
AuthorDate: Wed Jul 24 15:47:14 2019 +0200
apps/bttester: Add missing return buf check
---
apps/bttester/src/gatt.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/apps/bttester/src/gatt.c b/apps/bttester/src/gatt.c
index dba4442..a69fa57 100644
--- a/apps/bttester/src/gatt.c
+++ b/apps/bttester/src/gatt.c
@@ -1720,6 +1720,11 @@ static void write_long(u8_t *data, u16_t len)
om = ble_hs_mbuf_from_flat(cmd->data, sys_le16_to_cpu(cmd->data_length));
+ if (!om) {
+ SYS_LOG_ERR("Insufficient resources");
+ goto fail;
+ }
+
if (ble_gattc_write_long(conn.conn_handle, sys_le16_to_cpu(cmd->handle),
sys_le16_to_cpu(cmd->offset), om, write_rsp,
(void *) GATT_WRITE_LONG)) {