ble apps - use ANS package These two apps (bleprph and bletiny) used to reimplement the Alert Notification Service. Now they just depend on the ANS package.
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/b455cb0b Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/b455cb0b Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/b455cb0b Branch: refs/heads/develop Commit: b455cb0bf24d531bbc88ff047a0128e977dc52c9 Parents: d6d5639 Author: Christopher Collins <[email protected]> Authored: Thu Dec 29 17:21:43 2016 -0800 Committer: Christopher Collins <[email protected]> Committed: Thu Dec 29 17:21:43 2016 -0800 ---------------------------------------------------------------------- apps/bleprph/pkg.yml | 1 + apps/bleprph/src/gatt_svr.c | 106 --------------------------------------- apps/bletiny/pkg.yml | 4 +- apps/bletiny/src/gatt_svr.c | 106 --------------------------------------- 4 files changed, 2 insertions(+), 215 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b455cb0b/apps/bleprph/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/bleprph/pkg.yml b/apps/bleprph/pkg.yml index 7cbc6b7..2aa4245 100644 --- a/apps/bleprph/pkg.yml +++ b/apps/bleprph/pkg.yml @@ -29,6 +29,7 @@ pkg.deps: - mgmt/newtmgr/transport/ble - net/nimble/controller - net/nimble/host + - net/nimble/host/services/ans - net/nimble/host/services/gap - net/nimble/host/services/gatt - net/nimble/host/store/ram http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b455cb0b/apps/bleprph/src/gatt_svr.c ---------------------------------------------------------------------- diff --git a/apps/bleprph/src/gatt_svr.c b/apps/bleprph/src/gatt_svr.c index 3e3ef21..2a64547 100644 --- a/apps/bleprph/src/gatt_svr.c +++ b/apps/bleprph/src/gatt_svr.c @@ -54,46 +54,12 @@ const uint8_t gatt_svr_chr_sec_test_static_uuid[16] = { static uint8_t gatt_svr_sec_test_static_val; static int -gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, - struct ble_gatt_access_ctxt *ctxt, - void *arg); - -static int gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); static const struct ble_gatt_svc_def gatt_svr_svcs[] = { { - /*** Alert Notification Service. */ - .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid128 = BLE_UUID16(GATT_SVR_SVC_ALERT_UUID), - .characteristics = (struct ble_gatt_chr_def[]) { { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_READ, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_NEW_ALERT), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_NOTIFY, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_READ, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_UNR_ALERT_STAT_UUID), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_NOTIFY, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_ALERT_NOT_CTRL_PT), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_WRITE, - }, { - 0, /* No more characteristics in this service. */ - } }, - }, - - { /*** Service: Security test. */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid128 = gatt_svr_svc_sec_test_uuid, @@ -138,78 +104,6 @@ gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, return 0; } -#define GATT_SVR_NEW_ALERT_VAL_MAX_LEN 64 - -static const uint8_t gatt_svr_new_alert_cat = 0x01; /* Simple alert. */ -static uint8_t gatt_svr_new_alert_val[GATT_SVR_NEW_ALERT_VAL_MAX_LEN]; -static uint16_t gatt_svr_new_alert_val_len; -static const uint8_t gatt_svr_unr_alert_cat = 0x01; /* Simple alert. */ -static uint16_t gatt_svr_unr_alert_stat; -static uint16_t gatt_svr_alert_not_ctrl_pt; - -static int -gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, - struct ble_gatt_access_ctxt *ctxt, - void *arg) -{ - uint16_t uuid16; - int rc; - - uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128); - assert(uuid16 != 0); - - switch (uuid16) { - case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID: - assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR); - rc = os_mbuf_append(ctxt->om, &gatt_svr_new_alert_cat, - sizeof gatt_svr_new_alert_cat); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - - case GATT_SVR_CHR_NEW_ALERT: - if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - rc = gatt_svr_chr_write(ctxt->om, 0, - sizeof gatt_svr_new_alert_val, - gatt_svr_new_alert_val, - &gatt_svr_new_alert_val_len); - return rc; - } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) { - rc = os_mbuf_append(ctxt->om, &gatt_svr_new_alert_val, - sizeof gatt_svr_new_alert_val); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } - - case GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID: - assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR); - rc = os_mbuf_append(ctxt->om, &gatt_svr_unr_alert_cat, - sizeof gatt_svr_unr_alert_cat); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - - case GATT_SVR_CHR_UNR_ALERT_STAT_UUID: - if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - rc = gatt_svr_chr_write(ctxt->om, 2, 2, &gatt_svr_unr_alert_stat, - NULL); - return rc; - } else { - rc = os_mbuf_append(ctxt->om, &gatt_svr_unr_alert_stat, - sizeof gatt_svr_unr_alert_stat); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } - - case GATT_SVR_CHR_ALERT_NOT_CTRL_PT: - if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - rc = gatt_svr_chr_write(ctxt->om, 2, 2, - &gatt_svr_alert_not_ctrl_pt, NULL); - } else { - rc = BLE_ATT_ERR_UNLIKELY; - } - return rc; - - default: - assert(0); - return BLE_ATT_ERR_UNLIKELY; - } -} - static int gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b455cb0b/apps/bletiny/pkg.yml ---------------------------------------------------------------------- diff --git a/apps/bletiny/pkg.yml b/apps/bletiny/pkg.yml index b9a7465..703914d 100644 --- a/apps/bletiny/pkg.yml +++ b/apps/bletiny/pkg.yml @@ -27,12 +27,10 @@ pkg.deps: - sys/log - net/nimble/controller - net/nimble/host + - net/nimble/host/services/ans - net/nimble/host/services/gap - net/nimble/host/services/gatt - net/nimble/host/store/ram - net/nimble/transport/ram - sys/console/full - sys/shell - -### Disable some features to make bletiny small enough to fit on the nRF51. -### These features can be re-enabled in the target definition. http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/b455cb0b/apps/bletiny/src/gatt_svr.c ---------------------------------------------------------------------- diff --git a/apps/bletiny/src/gatt_svr.c b/apps/bletiny/src/gatt_svr.c index af7b00d..5c69d8b 100644 --- a/apps/bletiny/src/gatt_svr.c +++ b/apps/bletiny/src/gatt_svr.c @@ -96,11 +96,6 @@ static uint8_t gatt_svr_pts_static_val; static uint8_t gatt_svr_pts_static_long_val[30]; static int -gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, - struct ble_gatt_access_ctxt *ctxt, - void *arg); - -static int gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt, void *arg); @@ -235,35 +230,6 @@ static const struct ble_gatt_svc_def gatt_svr_svcs[] = { }, { - /*** Alert notification service. */ - .type = BLE_GATT_SVC_TYPE_PRIMARY, - .uuid128 = BLE_UUID16(GATT_SVR_SVC_ALERT_UUID), - .characteristics = (struct ble_gatt_chr_def[]) { { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_READ, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_NEW_ALERT), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_NOTIFY, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_READ, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_UNR_ALERT_STAT_UUID), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_NOTIFY, - }, { - .uuid128 = BLE_UUID16(GATT_SVR_CHR_ALERT_NOT_CTRL_PT), - .access_cb = gatt_svr_chr_access_alert, - .flags = BLE_GATT_CHR_F_WRITE, - }, { - 0, /* No more characteristics in this service. */ - } }, - }, - - { /*** Service: Security test. */ .type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid128 = gatt_svr_svc_sec_test_uuid, @@ -313,78 +279,6 @@ gatt_svr_chr_write(struct os_mbuf *om, uint16_t min_len, uint16_t max_len, return 0; } -#define GATT_SVR_NEW_ALERT_VAL_MAX_LEN 64 - -static const uint8_t gatt_svr_new_alert_cat = 0x01; /* Simple alert. */ -static uint8_t gatt_svr_new_alert_val[GATT_SVR_NEW_ALERT_VAL_MAX_LEN]; -static uint16_t gatt_svr_new_alert_val_len; -static const uint8_t gatt_svr_unr_alert_cat = 0x01; /* Simple alert. */ -static uint16_t gatt_svr_unr_alert_stat; -static uint16_t gatt_svr_alert_not_ctrl_pt; - -static int -gatt_svr_chr_access_alert(uint16_t conn_handle, uint16_t attr_handle, - struct ble_gatt_access_ctxt *ctxt, - void *arg) -{ - uint16_t uuid16; - int rc; - - uuid16 = ble_uuid_128_to_16(ctxt->chr->uuid128); - assert(uuid16 != 0); - - switch (uuid16) { - case GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID: - assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR); - rc = os_mbuf_append(ctxt->om, &gatt_svr_new_alert_cat, - sizeof gatt_svr_new_alert_cat); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - - case GATT_SVR_CHR_NEW_ALERT: - if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - rc = gatt_svr_chr_write(ctxt->om, 0, - sizeof gatt_svr_new_alert_val, - gatt_svr_new_alert_val, - &gatt_svr_new_alert_val_len); - return rc; - } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR) { - rc = os_mbuf_append(ctxt->om, &gatt_svr_new_alert_val, - sizeof gatt_svr_new_alert_val); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } - - case GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID: - assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR); - rc = os_mbuf_append(ctxt->om, &gatt_svr_unr_alert_cat, - sizeof gatt_svr_unr_alert_cat); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - - case GATT_SVR_CHR_UNR_ALERT_STAT_UUID: - if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - rc = gatt_svr_chr_write(ctxt->om, 2, 2, &gatt_svr_unr_alert_stat, - NULL); - return rc; - } else { - rc = os_mbuf_append(ctxt->om, &gatt_svr_unr_alert_stat, - sizeof gatt_svr_unr_alert_stat); - return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; - } - - case GATT_SVR_CHR_ALERT_NOT_CTRL_PT: - if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) { - rc = gatt_svr_chr_write(ctxt->om, 2, 2, - &gatt_svr_alert_not_ctrl_pt, NULL); - } else { - rc = BLE_ATT_ERR_UNLIKELY; - } - return rc; - - default: - assert(0); - return BLE_ATT_ERR_UNLIKELY; - } -} - static int gatt_svr_chr_access_sec_test(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt *ctxt,
