You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/01/20 23:24:53 UTC
[1/4] incubator-mynewt-larva git commit: bleshell - Fill in some gaps.
Repository: incubator-mynewt-larva
Updated Branches:
refs/heads/master 0fa4e7fed -> 3ea740b2d
bleshell - Fill in some gaps.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/3ea740b2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/3ea740b2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/3ea740b2
Branch: refs/heads/master
Commit: 3ea740b2dcfd770a50aeb157586b4c7d31ad9cdf
Parents: 8e30133
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 20 14:24:08 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 20 14:24:44 2016 -0800
----------------------------------------------------------------------
project/bleshell/src/bleshell_priv.h | 1 +
project/bleshell/src/cmd.c | 24 ++++++++
project/bleshell/src/main.c | 89 ++++++++++++++++++----------
project/bleshell/src/parse.c | 11 ++--
project/bleshell/src/periph.c | 96 ++++++++++++++++++++++++++-----
5 files changed, 170 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3ea740b2/project/bleshell/src/bleshell_priv.h
----------------------------------------------------------------------
diff --git a/project/bleshell/src/bleshell_priv.h b/project/bleshell/src/bleshell_priv.h
index baeae4f..e8bdeea 100644
--- a/project/bleshell/src/bleshell_priv.h
+++ b/project/bleshell/src/bleshell_priv.h
@@ -94,5 +94,6 @@ int bleshell_write_long(uint16_t conn_handle, uint16_t attr_handle,
int bleshell_adv_start(int disc, int conn, uint8_t *peer_addr, int addr_type);
int bleshell_adv_stop(void);
int bleshell_conn_initiate(int addr_type, uint8_t *peer_addr);
+int bleshell_conn_cancel(void);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3ea740b2/project/bleshell/src/cmd.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/cmd.c b/project/bleshell/src/cmd.c
index e4853c0..47ec82c 100644
--- a/project/bleshell/src/cmd.c
+++ b/project/bleshell/src/cmd.c
@@ -40,14 +40,28 @@ cmd_exec(struct cmd_entry *cmds, int argc, char **argv)
}
static void
+cmd_print_dsc(struct bleshell_dsc *dsc)
+{
+ console_printf(" dsc_handle=%d uuid=", dsc->dsc.handle);
+ print_uuid(dsc->dsc.uuid128);
+ console_printf("\n");
+}
+
+static void
cmd_print_chr(struct bleshell_chr *chr)
{
+ struct bleshell_dsc *dsc;
+
console_printf(" def_handle=%d val_handle=%d properties=0x%02x "
"uuid=",
chr->chr.decl_handle, chr->chr.value_handle,
chr->chr.properties);
print_uuid(chr->chr.uuid128);
console_printf("\n");
+
+ SLIST_FOREACH(dsc, &chr->dscs, next) {
+ cmd_print_dsc(dsc);
+ }
}
static void
@@ -191,6 +205,16 @@ cmd_conn(int argc, char **argv)
int addr_type;
int rc;
+ if (argc > 1 && strcmp(argv[1], "cancel") == 0) {
+ rc = bleshell_conn_cancel();
+ if (rc != 0) {
+ console_printf("connection cancel fail: %d\n", rc);
+ return rc;
+ }
+
+ return 0;
+ }
+
addr_type = parse_arg_kv("addr_type", cmd_conn_addr_types);
if (addr_type == -1) {
return -1;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3ea740b2/project/bleshell/src/main.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/main.c b/project/bleshell/src/main.c
index 16157eb..da1a8d2 100755
--- a/project/bleshell/src/main.c
+++ b/project/bleshell/src/main.c
@@ -100,6 +100,16 @@ static struct os_mempool bleshell_chr_pool;
static void *bleshell_dsc_mem;
static struct os_mempool bleshell_dsc_pool;
+static void
+bleshell_print_bytes(uint8_t *bytes, int len)
+{
+ int i;
+
+ for (i = 0; i < len; i++) {
+ console_printf("%s0x%02x", i != 0 ? ":" : "", bytes[i]);
+ }
+}
+
static int
bleshell_conn_find_idx(uint16_t handle)
{
@@ -514,9 +524,6 @@ static int
bleshell_on_read(uint16_t conn_handle, struct ble_gatt_error *error,
struct ble_gatt_attr *attr, void *arg)
{
- uint8_t *u8p;
- int i;
-
if (error != NULL) {
console_printf("ERROR READING CHARACTERISTIC: conn_handle=%d "
"status=%d att_handle=%d\n",
@@ -525,10 +532,7 @@ bleshell_on_read(uint16_t conn_handle, struct ble_gatt_error *error,
console_printf("characteristic read complete; conn_handle=%d "
"attr_handle=%d len=%d value=", conn_handle,
attr->handle, attr->value_len);
- u8p = attr->value;
- for (i = 0; i < attr->value_len; i++) {
- console_printf("%s0x%02x", i != 0 ? ":" : "", u8p[i]);
- }
+ bleshell_print_bytes(attr->value, attr->value_len);
console_printf("\n");
}
@@ -540,7 +544,6 @@ bleshell_on_read_mult(uint16_t conn_handle, struct ble_gatt_error *error,
uint16_t *attr_handles, uint8_t num_attr_handles,
uint8_t *attr_data, uint16_t attr_data_len, void *arg)
{
- uint8_t *u8p;
int i;
if (error != NULL) {
@@ -555,10 +558,7 @@ bleshell_on_read_mult(uint16_t conn_handle, struct ble_gatt_error *error,
}
console_printf(" len=%d value=", attr_data_len);
- u8p = attr_data;
- for (i = 0; i < attr_data_len; i++) {
- console_printf("%s0x%02x", i != 0 ? ":" : "", u8p[i]);
- }
+ bleshell_print_bytes(attr_data, attr_data_len);
console_printf("\n");
}
@@ -570,9 +570,6 @@ static int
bleshell_on_write(uint16_t conn_handle, struct ble_gatt_error *error,
struct ble_gatt_attr *attr, void *arg)
{
- uint8_t *u8p;
- int i;
-
if (error != NULL) {
console_printf("ERROR WRITING CHARACTERISTIC: conn_handle=%d "
"status=%d att_handle=%d\n",
@@ -581,16 +578,26 @@ bleshell_on_write(uint16_t conn_handle, struct ble_gatt_error *error,
console_printf("characteristic write complete; conn_handle=%d "
"attr_handle=%d len=%d value=", conn_handle,
attr->handle, attr->value_len);
- u8p = attr->value;
- for (i = 0; i < attr->value_len; i++) {
- console_printf("%s0x%02x", i != 0 ? ":" : "", u8p[i]);
- }
+ bleshell_print_bytes(attr->value, attr->value_len);
console_printf("\n");
}
return 0;
}
+static int
+bleshell_on_notify(uint16_t conn_handle, uint16_t attr_handle,
+ uint8_t *attr_val, uint16_t attr_len, void *arg)
+{
+ console_printf("received notification from conn_handle=%d attr=%d "
+ "len=%d value=", conn_handle, attr_handle, attr_len);
+
+ bleshell_print_bytes(attr_val, attr_len);
+ console_printf("\n");
+
+ return 0;
+}
+
static void
bleshell_on_connect(int event, int status, struct ble_gap_conn_desc *desc,
void *arg)
@@ -609,11 +616,17 @@ bleshell_on_connect(int event, int status, struct ble_gap_conn_desc *desc,
if (status == 0) {
bleshell_conn_add(desc);
} else {
- conn_idx = bleshell_conn_find_idx(desc->conn_handle);
- if (conn_idx == -1) {
- console_printf("UNKNOWN CONNECTION\n");
+ if (desc->conn_handle == BLE_HS_CONN_HANDLE_NONE) {
+ if (status == BLE_HS_HCI_ERR(BLE_ERR_UNK_CONN_ID)) {
+ console_printf("connection procedure cancelled.\n");
+ }
} else {
- bleshell_conn_delete_idx(conn_idx);
+ conn_idx = bleshell_conn_find_idx(desc->conn_handle);
+ if (conn_idx == -1) {
+ console_printf("UNKNOWN CONNECTION\n");
+ } else {
+ bleshell_conn_delete_idx(conn_idx);
+ }
}
}
@@ -668,15 +681,15 @@ bleshell_disc_svc_by_uuid(uint16_t conn_handle, uint8_t *uuid128)
}
int
-bleshell_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
+bleshell_disc_all_dscs(uint16_t conn_handle, uint16_t chr_def_handle,
uint16_t chr_end_handle)
{
- intptr_t chr_def_handle;
+ intptr_t chr_def_handle_iptr;
int rc;
- chr_def_handle = chr_val_handle - 1;
- rc = ble_gattc_disc_all_dscs(conn_handle, chr_val_handle, chr_end_handle,
- bleshell_on_disc_d, &chr_def_handle);
+ chr_def_handle_iptr = chr_def_handle;
+ rc = ble_gattc_disc_all_dscs(conn_handle, chr_def_handle, chr_end_handle,
+ bleshell_on_disc_d, &chr_def_handle_iptr);
return rc;
}
@@ -737,8 +750,13 @@ bleshell_write(uint16_t conn_handle, uint16_t attr_handle, void *value,
{
int rc;
- rc = ble_gattc_write(conn_handle, attr_handle, value, value_len,
- bleshell_on_write, NULL);
+ if (conn_handle == BLE_HS_CONN_HANDLE_NONE) {
+ rc = ble_att_svr_write_local(attr_handle, value, value_len);
+ } else {
+ rc = ble_gattc_write(conn_handle, attr_handle, value, value_len,
+ bleshell_on_write, NULL);
+ }
+
return rc;
}
@@ -793,6 +811,15 @@ bleshell_conn_initiate(int addr_type, uint8_t *peer_addr)
return rc;
}
+int
+bleshell_conn_cancel(void)
+{
+ int rc;
+
+ rc = ble_gap_conn_cancel();
+ return rc;
+}
+
/**
* BLE test task
*
@@ -806,6 +833,8 @@ bleshell_task_handler(void *arg)
periph_init();
+ ble_att_set_notify_cb(bleshell_on_notify, NULL);
+
/* Initialize eventq */
os_eventq_init(&g_bleshell_evq);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3ea740b2/project/bleshell/src/parse.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/parse.c b/project/bleshell/src/parse.c
index 438bd74..354a3e1 100644
--- a/project/bleshell/src/parse.c
+++ b/project/bleshell/src/parse.c
@@ -7,10 +7,9 @@
#include "host/ble_uuid.h"
#include "bleshell_priv.h"
-#define CMD_MAX_ARG_LEN 32
#define CMD_MAX_ARGS 16
-static char cmd_args[CMD_MAX_ARGS][2][CMD_MAX_ARG_LEN];
+static char *cmd_args[CMD_MAX_ARGS][2];
static int cmd_num_args;
void
@@ -306,9 +305,7 @@ parse_arg_all(int argc, char **argv)
val = strtok(NULL, "=");
if (key != NULL && val != NULL) {
- if (strlen(key) == 0 || strlen(key) >= CMD_MAX_ARG_LEN ||
- strlen(val) >= CMD_MAX_ARG_LEN) {
-
+ if (strlen(key) == 0) {
console_printf("Error: invalid argument: %s\n", argv[i]);
return -1;
}
@@ -318,8 +315,8 @@ parse_arg_all(int argc, char **argv)
return -1;
}
- strcpy(cmd_args[cmd_num_args][0], key);
- strcpy(cmd_args[cmd_num_args][1], val);
+ cmd_args[cmd_num_args][0] = key;
+ cmd_args[cmd_num_args][1] = val;
cmd_num_args++;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/3ea740b2/project/bleshell/src/periph.c
----------------------------------------------------------------------
diff --git a/project/bleshell/src/periph.c b/project/bleshell/src/periph.c
index 5f4400f..ce814c1 100644
--- a/project/bleshell/src/periph.c
+++ b/project/bleshell/src/periph.c
@@ -15,6 +15,12 @@
BLE_GATT_CHR_F_NOTIFY | \
BLE_GATT_CHR_F_INDICATE)
+#define PERIPH_CHR_MAX_LEN 16
+
+
+static uint8_t periph_chr_data[3][PERIPH_CHR_MAX_LEN];
+static uint16_t periph_chr_lens[3];
+
static int
periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
union ble_gatt_access_ctxt *ctxt, void *arg);
@@ -63,32 +69,56 @@ static const struct ble_gatt_svc_def periph_svcs[] = {
};
static int
-periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
- union ble_gatt_access_ctxt *ctxt, void *arg)
+periph_gatt_read(uint16_t attr_handle, union ble_gatt_access_ctxt *ctxt,
+ void *arg)
{
- static uint8_t buf[128];
uint16_t uuid16;
+ int idx;
+
+ uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
+ switch (uuid16) {
+ case PERIPH_CHR1_UUID:
+ idx = 0;
+ break;
+
+ case PERIPH_CHR2_UUID:
+ idx = 1;
+ break;
+
+ case PERIPH_CHR3_UUID:
+ idx = 2;
+ break;
+
+ default:
+ assert(0);
+ break;
+ }
+
+ ctxt->chr_access.data = periph_chr_data[idx];
+ ctxt->chr_access.len = periph_chr_lens[idx];
+
+ return 0;
+}
- assert(op == BLE_GATT_ACCESS_OP_READ_CHR);
+static int
+periph_gatt_write(uint16_t attr_handle, union ble_gatt_access_ctxt *ctxt,
+ void *arg)
+{
+ uint16_t uuid16;
+ int idx;
uuid16 = ble_uuid_128_to_16(ctxt->chr_access.chr->uuid128);
switch (uuid16) {
case PERIPH_CHR1_UUID:
- console_printf("reading characteristic1 value\n");
- memcpy(buf, "char1", 5);
- ctxt->chr_access.len = 5;
+ idx = 0;
break;
case PERIPH_CHR2_UUID:
- console_printf("reading characteristic2 value\n");
- memcpy(buf, "char2", 5);
- ctxt->chr_access.len = 5;
+ idx = 1;
break;
case PERIPH_CHR3_UUID:
- console_printf("reading characteristic3 value\n");
- memcpy(buf, "char3", 5);
- ctxt->chr_access.len = 5;
+ idx = 2;
break;
default:
@@ -96,11 +126,33 @@ periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
break;
}
- ctxt->chr_access.data = buf;
+ if (ctxt->chr_access.len > sizeof periph_chr_data[idx]) {
+ return BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN;
+ }
+
+ memcpy(periph_chr_data[idx], ctxt->chr_access.data, ctxt->chr_access.len);
+ periph_chr_lens[idx] = ctxt->chr_access.len;
return 0;
}
+static int
+periph_gatt_cb(uint16_t conn_handle, uint16_t attr_handle, uint8_t op,
+ union ble_gatt_access_ctxt *ctxt, void *arg)
+{
+ switch (op) {
+ case BLE_GATT_ACCESS_OP_READ_CHR:
+ return periph_gatt_read(attr_handle, ctxt, arg);
+
+ case BLE_GATT_ACCESS_OP_WRITE_CHR:
+ return periph_gatt_write(attr_handle, ctxt, arg);
+
+ default:
+ assert(0);
+ return -1;
+ }
+}
+
static void
periph_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
{
@@ -123,6 +175,15 @@ periph_register_cb(uint8_t op, union ble_gatt_register_ctxt *ctxt, void *arg)
ctxt->chr_reg.val_handle);
break;
+ case BLE_GATT_REGISTER_OP_DSC:
+ uuid16 = ble_uuid_128_to_16(ctxt->dsc_reg.dsc->uuid128);
+ assert(uuid16 != 0);
+ console_printf("registering descriptor 0x%04x with handle=%d "
+ "chr_handle=%d\n",
+ uuid16, ctxt->dsc_reg.dsc_handle,
+ ctxt->dsc_reg.chr_def_handle);
+ break;
+
default:
assert(0);
break;
@@ -134,6 +195,13 @@ periph_init(void)
{
int rc;
+ strcpy((char *)periph_chr_data[0], "hello0");
+ periph_chr_lens[0] = strlen((char *)periph_chr_data[0]);
+ strcpy((char *)periph_chr_data[1], "hello1");
+ periph_chr_lens[1] = strlen((char *)periph_chr_data[1]);
+ strcpy((char *)periph_chr_data[2], "hello2");
+ periph_chr_lens[2] = strlen((char *)periph_chr_data[2]);
+
rc = ble_gatts_register_svcs(periph_svcs, periph_register_cb, NULL);
assert(rc == 0);
}
[4/4] incubator-mynewt-larva git commit: Add function for local
attribute write.
Posted by cc...@apache.org.
Add function for local attribute write.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/fe475640
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/fe475640
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/fe475640
Branch: refs/heads/master
Commit: fe4756407c986127debe96f691c573c49e1c8df8
Parents: 0fa4e7f
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 20 14:20:05 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 20 14:24:44 2016 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_att.h | 3 +++
net/nimble/host/src/ble_att_svr.c | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/fe475640/net/nimble/host/include/host/ble_att.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_att.h b/net/nimble/host/include/host/ble_att.h
index 949c963..6d7300c 100644
--- a/net/nimble/host/include/host/ble_att.h
+++ b/net/nimble/host/include/host/ble_att.h
@@ -112,6 +112,9 @@ typedef int ble_att_svr_notify_fn(uint16_t conn_handle, uint16_t attr_handle,
uint8_t *attr_val, uint16_t attr_len,
void *arg);
+int ble_att_svr_write_local(uint16_t attr_handle, void *data,
+ uint16_t data_len);
+
void ble_att_set_notify_cb(ble_att_svr_notify_fn *cb, void *cb_arg);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/fe475640/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index 236751a..e92f4b9 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -2072,6 +2072,28 @@ err:
return rc;
}
+int
+ble_att_svr_write_local(uint16_t attr_handle, void *data, uint16_t data_len)
+{
+ struct ble_att_svr_access_ctxt ctxt;
+ struct ble_att_svr_entry *entry;
+ int rc;
+
+ entry = NULL;
+ rc = ble_att_svr_find_by_handle(attr_handle, &entry);
+ if (rc != 0) {
+ return rc;
+ }
+
+ ctxt.attr_data = data;
+ ctxt.data_len = data_len;
+ ctxt.offset = 0;
+
+ rc = ble_att_svr_write(NULL, entry, &ctxt, NULL);
+
+ return rc;
+}
+
static void
ble_att_svr_prep_free(struct ble_att_prep_entry *entry)
{
[2/4] incubator-mynewt-larva git commit: Change GATT
discover-descriptors interface.
Posted by cc...@apache.org.
Change GATT discover-descriptors interface.
It used to expect the characgteristic value handle; not it takes the
characteristic definition handle.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/471a6c8b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/471a6c8b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/471a6c8b
Branch: refs/heads/master
Commit: 471a6c8b5b508f41e47503aa1dda142b94e80f65
Parents: fe47564
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 20 14:21:21 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 20 14:24:44 2016 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_gatt.h | 2 +-
net/nimble/host/src/ble_gattc.c | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/471a6c8b/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 57fc6ef..818273e 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -73,7 +73,7 @@ typedef int ble_gatt_chr_fn(uint16_t conn_handle, struct ble_gatt_error *error,
struct ble_gatt_chr *chr, void *arg);
typedef int ble_gatt_dsc_fn(uint16_t conn_handle, struct ble_gatt_error *error,
- uint16_t chr_val_handle, struct ble_gatt_dsc *dsc,
+ uint16_t chr_def_handle, struct ble_gatt_dsc *dsc,
void *arg);
int ble_gattc_exchange_mtu(uint16_t conn_handle,
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/471a6c8b/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 728545c..0311ec4 100644
--- a/net/nimble/host/src/ble_gattc.c
+++ b/net/nimble/host/src/ble_gattc.c
@@ -109,7 +109,7 @@ struct ble_gattc_proc {
} disc_chr_uuid;
struct {
- uint16_t chr_val_handle;
+ uint16_t chr_def_handle;
uint16_t prev_handle;
uint16_t end_handle;
ble_gatt_dsc_fn *cb;
@@ -1963,7 +1963,7 @@ ble_gattc_disc_all_dscs_cb(struct ble_gattc_proc *proc, int status,
} else {
rc = proc->disc_all_dscs.cb(proc->conn_handle,
ble_gattc_error(status, att_handle),
- proc->disc_all_dscs.chr_val_handle,
+ proc->disc_all_dscs.chr_def_handle,
dsc, proc->disc_all_dscs.cb_arg);
}
@@ -2080,7 +2080,7 @@ ble_gattc_disc_all_dscs_rx_complete(struct ble_gattc_proc *proc,
*
* @param conn_handle The connection over which to execute the
* procedure.
- * @param chr_val_handle The handle of the characteristic value
+ * @param chr_def_handle The handle of the characteristic definition
* attribute.
* @param chr_end_handle The last handle in the characteristic
* definition.
@@ -2089,7 +2089,7 @@ ble_gattc_disc_all_dscs_rx_complete(struct ble_gattc_proc *proc,
* @param cb_arg The argument to pass to the callback function.
*/
int
-ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
+ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_def_handle,
uint16_t chr_end_handle,
ble_gatt_dsc_fn *cb, void *cb_arg)
{
@@ -2100,8 +2100,8 @@ ble_gattc_disc_all_dscs(uint16_t conn_handle, uint16_t chr_val_handle,
if (rc != 0) {
return rc;
}
- proc->disc_all_dscs.chr_val_handle = chr_val_handle;
- proc->disc_all_dscs.prev_handle = chr_val_handle;
+ proc->disc_all_dscs.chr_def_handle = chr_def_handle;
+ proc->disc_all_dscs.prev_handle = chr_def_handle + 1;
proc->disc_all_dscs.end_handle = chr_end_handle;
proc->disc_all_dscs.cb = cb;
proc->disc_all_dscs.cb_arg = cb_arg;
[3/4] incubator-mynewt-larva git commit: Register characteristics
with proper ATT perms.
Posted by cc...@apache.org.
Register characteristics with proper ATT perms.
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/8e30133a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/8e30133a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/8e30133a
Branch: refs/heads/master
Commit: 8e30133a2943835f19656e605a179abde737bd07
Parents: 471a6c8
Author: Christopher Collins <cc...@gmail.com>
Authored: Wed Jan 20 14:22:55 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Wed Jan 20 14:24:44 2016 -0800
----------------------------------------------------------------------
net/nimble/host/src/ble_gatts.c | 68 ++++++++++++++++++++++++------------
1 file changed, 46 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/8e30133a/net/nimble/host/src/ble_gatts.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatts.c b/net/nimble/host/src/ble_gatts.c
index ce1a683..9bd4199 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -17,6 +17,7 @@
#include <stddef.h>
#include <assert.h>
#include <string.h>
+#include "console/console.h"
#include "nimble/ble.h"
#include "host/ble_uuid.h"
#include "ble_hs_priv.h"
@@ -27,8 +28,8 @@
#define BLE_GATTS_INCLUDE_SZ 6
#define BLE_GATTS_CHR_MAX_SZ 19
-#define BLE_GATTS_MAX_SERVICES 32 /* XXX: Make this configurable. */
-#define BLE_GATTS_MAX_CLT_CFGS 256 /* XXX: Make this configurable. */
+#define BLE_GATTS_MAX_SERVICES 16 /* XXX: Make this configurable. */
+#define BLE_GATTS_MAX_CLT_CFGS 32 /* XXX: Make this configurable. */
struct ble_gatts_svc_entry {
const struct ble_gatt_svc_def *svc;
@@ -100,6 +101,38 @@ ble_gatts_inc_access(uint16_t conn_handle, uint16_t attr_handle,
return 0;
}
+static uint16_t
+ble_gatts_chr_clt_cfg_allowed(const struct ble_gatt_chr_def *chr)
+{
+ uint16_t flags;
+
+ flags = 0;
+ if (chr->flags & BLE_GATT_CHR_F_NOTIFY) {
+ flags |= BLE_GATTS_CLT_CFG_F_NOTIFY;
+ }
+ if (chr->flags & BLE_GATT_CHR_F_INDICATE) {
+ flags |= BLE_GATTS_CLT_CFG_F_INDICATE;
+ }
+
+ return flags;
+}
+
+static uint8_t
+ble_gatts_att_flags_from_chr_flags(ble_gatt_chr_flags chr_flags)
+{
+ uint8_t att_flags;
+
+ att_flags = 0;
+ if (chr_flags & BLE_GATT_CHR_F_READ) {
+ att_flags |= HA_FLAG_PERM_READ;
+ }
+ if (chr_flags & (BLE_GATT_CHR_F_WRITE_NO_RSP | BLE_GATT_CHR_F_WRITE)) {
+ att_flags |= HA_FLAG_PERM_WRITE;
+ }
+
+ return att_flags;
+}
+
static uint8_t
ble_gatts_chr_properties(const struct ble_gatt_chr_def *chr)
{
@@ -224,6 +257,12 @@ ble_gatts_chr_val_access(uint16_t conn_handle, uint16_t attr_handle,
return rc;
}
+ if (att_op == BLE_ATT_ACCESS_OP_WRITE &&
+ ble_gatts_chr_clt_cfg_allowed(chr)) {
+
+ ble_gatts_chr_updated(attr_handle - 1);
+ }
+
att_ctxt->attr_data = gatt_ctxt.chr_access.data;
att_ctxt->data_len = gatt_ctxt.chr_access.len;
@@ -275,8 +314,8 @@ ble_gatts_register_inc(struct ble_gatts_svc_entry *entry)
assert(entry->handle != 0);
assert(entry->end_group_handle != 0xffff);
- rc = ble_att_svr_register(entry->svc->uuid128, HA_FLAG_PERM_READ,
- &handle, ble_gatts_inc_access, entry);
+ rc = ble_att_svr_register_uuid16(BLE_ATT_UUID_INCLUDE, HA_FLAG_PERM_READ,
+ &handle, ble_gatts_inc_access, entry);
if (rc != 0) {
return rc;
}
@@ -284,22 +323,6 @@ ble_gatts_register_inc(struct ble_gatts_svc_entry *entry)
return 0;
}
-static uint16_t
-ble_gatts_chr_clt_cfg_allowed(const struct ble_gatt_chr_def *chr)
-{
- uint16_t flags;
-
- flags = 0;
- if (chr->flags & BLE_GATT_CHR_F_NOTIFY) {
- flags |= BLE_GATTS_CLT_CFG_F_NOTIFY;
- }
- if (chr->flags & BLE_GATT_CHR_F_INDICATE) {
- flags |= BLE_GATTS_CLT_CFG_F_INDICATE;
- }
-
- return flags;
-}
-
static int
ble_gatts_clt_cfg_find_idx(struct ble_gatts_clt_cfg *cfgs,
uint16_t chr_def_handle)
@@ -515,6 +538,7 @@ ble_gatts_register_chr(const struct ble_gatt_chr_def *chr,
uint16_t def_handle;
uint16_t val_handle;
uint16_t dsc_handle;
+ uint8_t att_flags;
int rc;
if (!ble_gatts_chr_is_sane(chr)) {
@@ -534,8 +558,8 @@ ble_gatts_register_chr(const struct ble_gatt_chr_def *chr,
/* Register characteristic value attribute (cast away const on callback
* arg).
*/
- rc = ble_att_svr_register(chr->uuid128, HA_FLAG_PERM_READ /*XXX*/,
- &val_handle,
+ att_flags = ble_gatts_att_flags_from_chr_flags(chr->flags);
+ rc = ble_att_svr_register(chr->uuid128, att_flags, &val_handle,
ble_gatts_chr_val_access, (void *)chr);
if (rc != 0) {
return rc;