Return-Path: X-Original-To: apmail-mynewt-commits-archive@minotaur.apache.org Delivered-To: apmail-mynewt-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 07C2D18CB6 for ; Mon, 28 Dec 2015 19:39:25 +0000 (UTC) Received: (qmail 88485 invoked by uid 500); 28 Dec 2015 19:39:24 -0000 Delivered-To: apmail-mynewt-commits-archive@mynewt.apache.org Received: (qmail 88457 invoked by uid 500); 28 Dec 2015 19:39:24 -0000 Mailing-List: contact commits-help@mynewt.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.incubator.apache.org Delivered-To: mailing list commits@mynewt.incubator.apache.org Received: (qmail 88448 invoked by uid 99); 28 Dec 2015 19:39:24 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Dec 2015 19:39:24 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id 63CC61A13B1 for ; Mon, 28 Dec 2015 19:39:24 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.226 X-Spam-Level: * X-Spam-Status: No, score=1.226 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.554] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id bacugnHqmfa7 for ; Mon, 28 Dec 2015 19:39:22 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id B686620F18 for ; Mon, 28 Dec 2015 19:39:22 +0000 (UTC) Received: (qmail 88386 invoked by uid 99); 28 Dec 2015 19:39:22 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Dec 2015 19:39:22 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 78A14DFBA7; Mon, 28 Dec 2015 19:39:22 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ccollins@apache.org To: commits@mynewt.incubator.apache.org Date: Mon, 28 Dec 2015 19:39:23 -0000 Message-Id: <25122737852b49be80532a7dab8722eb@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [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 Authored: Mon Dec 28 11:37:47 2015 -0800 Committer: Christopher Collins 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; }