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:55 UTC
[3/4] incubator-mynewt-larva git commit: Register characteristics
with proper ATT perms.
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;