MYNEWT-349 BLE Host - API for gatt-service-changed

X-Original-Commit: 1e57852633bca23d2f5fedf62f1b36f635600332
This commit is contained in:
Christopher Collins
2016-12-09 13:24:27 -06:00
parent cba839a9e1
commit 09fe575855
2 changed files with 29 additions and 6 deletions
@@ -20,6 +20,8 @@
#ifndef H_BLE_SVC_GATT_
#define H_BLE_SVC_GATT_
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
@@ -28,6 +30,7 @@ struct ble_hs_cfg;
#define BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16 0x2a05
void ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle);
void ble_svc_gatt_init(void);
#ifdef __cplusplus
+26 -6
View File
@@ -23,6 +23,10 @@
#include "host/ble_hs.h"
#include "services/gatt/ble_svc_gatt.h"
static uint16_t ble_svc_gatt_changed_val_handle;
static uint16_t ble_svc_gatt_start_handle;
static uint16_t ble_svc_gatt_end_handle;
static int
ble_svc_gatt_access(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg);
@@ -35,6 +39,7 @@ static const struct ble_gatt_svc_def ble_svc_gatt_defs[] = {
.characteristics = (struct ble_gatt_chr_def[]) { {
.uuid128 = BLE_UUID16(BLE_SVC_GATT_CHR_SERVICE_CHANGED_UUID16),
.access_cb = ble_svc_gatt_access,
.val_handle = &ble_svc_gatt_changed_val_handle,
.flags = BLE_GATT_CHR_F_INDICATE,
}, {
0, /* No more characteristics in this service. */
@@ -50,7 +55,7 @@ static int
ble_svc_gatt_access(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
uint8_t *u8;
uint8_t *u8p;
/* The only operation allowed for this characteristic is indicate. This
* access callback gets called by the stack when it needs to read the
@@ -61,17 +66,32 @@ ble_svc_gatt_access(uint16_t conn_handle, uint16_t attr_handle,
assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
assert(ctxt->chr == &ble_svc_gatt_defs[0].characteristics[0]);
/* XXX: For now, always respond with 0 (unchanged). */
u8 = os_mbuf_extend(ctxt->om, 1);
if (u8 == NULL) {
return BLE_ATT_ERR_INSUFFICIENT_RES;
u8p = os_mbuf_extend(ctxt->om, 4);
if (u8p == NULL) {
return BLE_HS_ENOMEM;
}
*u8 = 0;
htole16(u8p + 0, ble_svc_gatt_start_handle);
htole16(u8p + 2, ble_svc_gatt_end_handle);
return 0;
}
/**
* Indicates a change in attribute assignment to all subscribed peers.
* Unconnected bonded peers receive an indication when they next connect.
*
* @param start_handle The start of the affected handle range.
* @param end_handle The end of the affected handle range.
*/
void
ble_svc_gatt_changed(uint16_t start_handle, uint16_t end_handle)
{
ble_svc_gatt_start_handle = start_handle;
ble_svc_gatt_end_handle = end_handle;
ble_gatts_chr_updated(ble_svc_gatt_changed_val_handle);
}
void
ble_svc_gatt_init(void)
{