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 2015/12/28 20:39:23 UTC
[2/3] incubator-mynewt-larva git commit: Fix some GATT server crashes.
Fix some GATT server crashes.
(complete lack of testing for last week's commit!)
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/38d7d737
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/38d7d737
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/38d7d737
Branch: refs/heads/master
Commit: 38d7d7371b0fefaeb1d43151300ba73ec95afbf0
Parents: 23c28c0
Author: Christopher Collins <cc...@gmail.com>
Authored: Mon Dec 28 11:37:47 2015 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Mon Dec 28 11:39:06 2015 -0800
----------------------------------------------------------------------
net/nimble/host/include/host/ble_att.h | 3 +++
net/nimble/host/include/host/ble_gatt.h | 5 ++--
net/nimble/host/src/ble_att_svr.c | 21 ++++++++++++++++
net/nimble/host/src/ble_gatt.c | 6 +++++
net/nimble/host/src/ble_gatts.c | 37 +++++++++++++++++++++++-----
5 files changed, 64 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/38d7d737/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 52046c5..7705f39 100644
--- a/net/nimble/host/include/host/ble_att.h
+++ b/net/nimble/host/include/host/ble_att.h
@@ -99,5 +99,8 @@ typedef int ble_att_svr_access_fn(uint16_t handle_id, uint8_t *uuid128,
int ble_att_svr_register(uint8_t *uuid, uint8_t flags, uint16_t *handle_id,
ble_att_svr_access_fn *cb, void *cb_arg);
+int ble_att_svr_register_uuid16(uint16_t uuid16, uint8_t flags,
+ uint16_t *handle_id, ble_att_svr_access_fn *cb,
+ void *cb_arg);
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/38d7d737/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 fbba391..6706613 100644
--- a/net/nimble/host/include/host/ble_gatt.h
+++ b/net/nimble/host/include/host/ble_gatt.h
@@ -80,15 +80,16 @@ struct ble_gatt_dsc_def {
};
struct ble_gatt_chr_def {
- uint8_t *uuid128;
+ uint8_t *uuid128; /* NULL if no more characteristics. */
ble_att_svr_access_fn *access_cb;
+ void *arg;
struct ble_gatt_dsc_def *descriptors;
uint8_t properties;
};
#define BLE_GATT_SVC_TYPE_END 0
#define BLE_GATT_SVC_TYPE_PRIMARY 1
-#define BLE_GATT_SVC_TYPE_SECONDAY 2
+#define BLE_GATT_SVC_TYPE_SECONDARY 2
struct ble_gatt_svc_def {
uint8_t type;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/38d7d737/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 4975d65..40f99dd 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -157,6 +157,27 @@ ble_att_svr_register(uint8_t *uuid, uint8_t flags, uint16_t *handle_id,
return 0;
}
+int
+ble_att_svr_register_uuid16(uint16_t uuid16, uint8_t flags,
+ uint16_t *handle_id, ble_att_svr_access_fn *cb,
+ void *cb_arg)
+{
+ uint8_t uuid128[16];
+ int rc;
+
+ rc = ble_hs_uuid_from_16bit(uuid16, uuid128);
+ if (rc != 0) {
+ return rc;
+ }
+
+ rc = ble_att_svr_register(uuid128, flags, handle_id, cb, cb_arg);
+ if (rc != 0) {
+ return rc;
+ }
+
+ return 0;
+}
+
/**
* Walk the host attribute list, calling walk_func on each entry with argument.
* If walk_func wants to stop iteration, it returns 1. To continue iteration
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/38d7d737/net/nimble/host/src/ble_gatt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_gatt.c b/net/nimble/host/src/ble_gatt.c
index de2766a..920e4e2 100644
--- a/net/nimble/host/src/ble_gatt.c
+++ b/net/nimble/host/src/ble_gatt.c
@@ -62,6 +62,12 @@ ble_gatt_connection_broken(uint16_t conn_handle)
}
int
+ble_gatt_register_services(const struct ble_gatt_svc_def *svcs)
+{
+ return ble_gatts_register_services(svcs);
+}
+
+int
ble_gatt_init(void)
{
int rc;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/38d7d737/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 b5de5b0..d5010c8 100644
--- a/net/nimble/host/src/ble_gatts.c
+++ b/net/nimble/host/src/ble_gatts.c
@@ -106,6 +106,7 @@ ble_gatts_chr_access(uint16_t handle_id, uint8_t *uuid128, uint8_t op,
memcpy(buf + 3, chr->uuid128, 16);
ctxt->ahc_read.attr_len = 19;
}
+ ctxt->ahc_read.attr_data = buf;
return 0;
}
@@ -180,7 +181,7 @@ ble_gatts_register_dsc(const struct ble_gatt_dsc_def *dsc)
}
static int
-ble_gatts_register_characteristic(const struct ble_gatt_chr_def *chr)
+ble_gatts_register_chr(const struct ble_gatt_chr_def *chr)
{
struct ble_gatt_dsc_def *dsc;
uint16_t handle;
@@ -189,8 +190,18 @@ ble_gatts_register_characteristic(const struct ble_gatt_chr_def *chr)
/* Register characteristic declaration attribute (cast away const on
* callback arg).
*/
- rc = ble_att_svr_register(chr->uuid128, HA_FLAG_PERM_READ, &handle,
- ble_gatts_chr_access, (void *)chr);
+ rc = ble_att_svr_register_uuid16(BLE_ATT_UUID_CHARACTERISTIC,
+ HA_FLAG_PERM_READ, &handle,
+ ble_gatts_chr_access, (void *)chr);
+ if (rc != 0) {
+ return rc;
+ }
+
+ /* Register characteristic value attribute (cast away const on callback
+ * arg).
+ */
+ rc = ble_att_svr_register(chr->uuid128, HA_FLAG_PERM_READ /*XXX*/, &handle,
+ chr->access_cb, (void *)chr->arg);
if (rc != 0) {
return rc;
}
@@ -214,6 +225,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
{
const struct ble_gatt_svc_def *incl;
const struct ble_gatt_chr_def *chr;
+ uint16_t uuid16;
int idx;
int rc;
@@ -224,8 +236,21 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
/* Register service definition attribute (cast away const on callback
* arg).
*/
- rc = ble_att_svr_register(svc->uuid128, HA_FLAG_PERM_READ, out_handle,
- ble_gatts_svc_access, (void *)svc);
+ switch (svc->type) {
+ case BLE_GATT_SVC_TYPE_PRIMARY:
+ uuid16 = BLE_ATT_UUID_PRIMARY_SERVICE;
+ break;
+
+ case BLE_GATT_SVC_TYPE_SECONDARY:
+ uuid16 = BLE_ATT_UUID_SECONDARY_SERVICE;
+ break;
+
+ default:
+ return BLE_HS_EINVAL;
+ }
+
+ rc = ble_att_svr_register_uuid16(uuid16, HA_FLAG_PERM_READ, out_handle,
+ ble_gatts_svc_access, (void *)svc);
if (rc != 0) {
return rc;
}
@@ -246,7 +271,7 @@ ble_gatts_register_svc(const struct ble_gatt_svc_def *svc,
/* Register each characteristic. */
if (svc->characteristics != NULL) {
for (chr = svc->characteristics; chr->uuid128 != NULL; chr++) {
- rc = ble_gatts_register_characteristic(chr);
+ rc = ble_gatts_register_chr(chr);
if (rc != 0) {
return rc;
}