nimble: add offset option to write long in client With this patch it is possible to pass TC_GAW_CL_BI_09_C and TC_GAW_CL_BI_27_C.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/37fb8a69 Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/37fb8a69 Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/37fb8a69 Branch: refs/heads/develop Commit: 37fb8a6970d15e9d1f8ab1dc85c5520cf74052b8 Parents: c90a303 Author: MichaÅ Narajowski <[email protected]> Authored: Tue Dec 20 13:46:44 2016 +0100 Committer: MichaÅ Narajowski <[email protected]> Committed: Thu Dec 22 09:51:18 2016 +0100 ---------------------------------------------------------------------- apps/bletiny/src/bletiny.h | 2 +- apps/bletiny/src/cmd.c | 16 ++++++++++++++-- apps/bletiny/src/main.c | 6 +++--- net/nimble/host/include/host/ble_gatt.h | 2 +- net/nimble/host/src/ble_gattc.c | 5 +++-- net/nimble/host/test/src/ble_hs_test_util.c | 3 ++- 6 files changed, 24 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37fb8a69/apps/bletiny/src/bletiny.h ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/bletiny.h b/apps/bletiny/src/bletiny.h index f66ddfb..32f4ea3 100644 --- a/apps/bletiny/src/bletiny.h +++ b/apps/bletiny/src/bletiny.h @@ -150,7 +150,7 @@ int bletiny_write(uint16_t conn_handle, uint16_t attr_handle, int bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, struct os_mbuf *om); int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle, - struct os_mbuf *om); + uint16_t offset, struct os_mbuf *om); int bletiny_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs, int num_attrs); int bletiny_adv_start(uint8_t own_addr_type, uint8_t peer_addr_type, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37fb8a69/apps/bletiny/src/cmd.c ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/cmd.c b/apps/bletiny/src/cmd.c index 5a1ca1e..99c29b4 100644 --- a/apps/bletiny/src/cmd.c +++ b/apps/bletiny/src/cmd.c @@ -2684,6 +2684,7 @@ bletiny_write_help(void) console_printf("\tlist of:\n"); help_cmd_long("attr"); help_cmd_byte_stream("value"); + help_cmd_uint16("offset"); } static int @@ -2692,6 +2693,7 @@ cmd_write(int argc, char **argv) struct ble_gatt_attr attrs[MYNEWT_VAL(BLE_GATT_WRITE_MAX_ATTRS)] = { { 0 } }; uint16_t attr_handle; uint16_t conn_handle; + uint16_t offset; int total_attr_len; int num_attrs; int attr_len; @@ -2753,13 +2755,22 @@ cmd_write(int argc, char **argv) goto done; } + offset = parse_arg_uint16("offset", &rc); + if (rc == ENOENT) { + offset = 0; + } else if (rc != 0) { + console_printf("invalid 'offset' parameter\n"); + help_cmd_uint16("offset"); + return rc; + } + if (num_attrs >= sizeof attrs / sizeof attrs[0]) { rc = -EINVAL; goto done; } attrs[num_attrs].handle = attr_handle; - attrs[num_attrs].offset = 0; + attrs[num_attrs].offset = offset; attrs[num_attrs].om = ble_hs_mbuf_from_flat(cmd_buf + total_attr_len, attr_len); if (attrs[num_attrs].om == NULL) { @@ -2782,7 +2793,8 @@ cmd_write(int argc, char **argv) rc = -EINVAL; goto done; } - rc = bletiny_write_long(conn_handle, attrs[0].handle, attrs[0].om); + rc = bletiny_write_long(conn_handle, attrs[0].handle, + attrs[0].offset, attrs[0].om); attrs[0].om = NULL; } else if (num_attrs > 1) { rc = bletiny_write_reliable(conn_handle, attrs, num_attrs); http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37fb8a69/apps/bletiny/src/main.c ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/main.c b/apps/bletiny/src/main.c index 63019f6..1839778 100755 --- a/apps/bletiny/src/main.c +++ b/apps/bletiny/src/main.c @@ -1292,12 +1292,12 @@ bletiny_write_no_rsp(uint16_t conn_handle, uint16_t attr_handle, int bletiny_write_long(uint16_t conn_handle, uint16_t attr_handle, - struct os_mbuf *om) + uint16_t offset, struct os_mbuf *om) { int rc; - rc = ble_gattc_write_long(conn_handle, attr_handle, om, - bletiny_on_write, NULL); + rc = ble_gattc_write_long(conn_handle, attr_handle, offset, + om, bletiny_on_write, NULL); return rc; } http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37fb8a69/net/nimble/host/include/host/ble_gatt.h ---------------------------------------------------------------------- diff --git a/net/nimble/host/include/host/ble_gatt.h b/net/nimble/host/include/host/ble_gatt.h index d7bee3d..072c168 100644 --- a/net/nimble/host/include/host/ble_gatt.h +++ b/net/nimble/host/include/host/ble_gatt.h @@ -178,7 +178,7 @@ int ble_gattc_write_flat(uint16_t conn_handle, uint16_t attr_handle, const void *data, uint16_t data_len, ble_gatt_attr_fn *cb, void *cb_arg); int ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle, - struct os_mbuf *om, + uint16_t offset, struct os_mbuf *om, ble_gatt_attr_fn *cb, void *cb_arg); int ble_gattc_write_reliable(uint16_t conn_handle, struct ble_gatt_attr *attrs, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37fb8a69/net/nimble/host/src/ble_gattc.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/src/ble_gattc.c b/net/nimble/host/src/ble_gattc.c index 311c777..0fa43e1 100644 --- a/net/nimble/host/src/ble_gattc.c +++ b/net/nimble/host/src/ble_gattc.c @@ -4109,7 +4109,8 @@ ble_gattc_write_long_rx_exec(struct ble_gattc_proc *proc, int status) */ int ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle, - struct os_mbuf *txom, ble_gatt_attr_fn *cb, void *cb_arg) + uint16_t offset, struct os_mbuf *txom, + ble_gatt_attr_fn *cb, void *cb_arg) { #if !MYNEWT_VAL(BLE_GATT_WRITE_LONG) return BLE_HS_ENOTSUP; @@ -4129,7 +4130,7 @@ ble_gattc_write_long(uint16_t conn_handle, uint16_t attr_handle, proc->op = BLE_GATT_OP_WRITE_LONG; proc->conn_handle = conn_handle; proc->write_long.attr.handle = attr_handle; - proc->write_long.attr.offset = 0; + proc->write_long.attr.offset = offset; proc->write_long.attr.om = txom; proc->write_long.cb = cb; proc->write_long.cb_arg = cb_arg; http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/37fb8a69/net/nimble/host/test/src/ble_hs_test_util.c ---------------------------------------------------------------------- diff --git a/net/nimble/host/test/src/ble_hs_test_util.c b/net/nimble/host/test/src/ble_hs_test_util.c index ef4f9a1..070ff86 100644 --- a/net/nimble/host/test/src/ble_hs_test_util.c +++ b/net/nimble/host/test/src/ble_hs_test_util.c @@ -1902,10 +1902,11 @@ ble_hs_test_util_gatt_write_long_flat(uint16_t conn_handle, ble_gatt_attr_fn *cb, void *cb_arg) { struct os_mbuf *om; + uint16_t offset = 0; int rc; om = ble_hs_test_util_om_from_flat(data, data_len); - rc = ble_gattc_write_long(conn_handle, attr_handle, om, cb, cb_arg); + rc = ble_gattc_write_long(conn_handle, attr_handle, offset, om, cb, cb_arg); return rc; }
