diff --git a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_api.h b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_api.h index 028016242eea1d038513f5ca619edb6f61401635..8dd5fcb013715abb9e2a6061349f157b28a150fd 100644 --- a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_api.h +++ b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_api.h @@ -74,6 +74,31 @@ void GattDiscover(dmConnId_t connId, uint16_t *pHdlList); /*************************************************************************************************/ uint8_t GattValueUpdate(uint16_t *pHdlList, attEvt_t *pMsg); +/*************************************************************************************************/ +/*! + * \brief Set Index of the Service Changed CCCD in the ATT Server. + * + * \param idx Index of the Service Changed CCCD in the ATT Server. + * + * \return None. + */ +/*************************************************************************************************/ +void GattSetSvcChangedIdx(uint8_t idx); + +/*************************************************************************************************/ +/*! + * \brief Send Service Change Indications to the specified connections if they are configured to + * do so. + * + * \param connId DM Connection identifier or \ref DM_CONN_ID_NONE to send to all connections. + * \param start start handle for service changed value. + * \param end end handle for service changed value. + * + * \return None. + */ +/*************************************************************************************************/ +void GattSendServiceChangedInd(dmConnId_t connId, uint16_t start, uint16_t end); + /*! \} */ /* GATT_PROFILE */ #ifdef __cplusplus diff --git a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_main.c b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_main.c index d7aeb9af7b81add8fa9f09aebd5afbf1e0330915..ad52cc678af7d1119f246b8e43a05dbef892cb2e 100644 --- a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_main.c +++ b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/profiles/gatt/gatt_main.c @@ -19,13 +19,30 @@ #include "wsf_types.h" #include "wsf_assert.h" +#include "util/bstream.h" #include "app_api.h" #include "gatt/gatt_api.h" +#include "svc_core.h" +#include "att_api.h" + +/************************************************************************************************** +Data Types +**************************************************************************************************/ + +/* Control block. */ +typedef struct +{ + bool_t svcChangedCccdIdxSet; /* Check if Service Changed CCCD index has been initialized. */ + uint8_t svcChangedCccdIdx; /* Stored index of Service Changed CCCD. */ +} gattServCb_t; /************************************************************************************************** Local Variables **************************************************************************************************/ +/* Control block. */ +gattServCb_t gattServCb; + /*! GATT service characteristics for discovery */ /*! Service changed */ @@ -46,7 +63,7 @@ static const attcDiscChar_t gattScCcc = static const attcDiscChar_t *gattDiscCharList[] = { &gattSc, /* Service changed */ - &gattScCcc /* Service changed client characteristic configuration descriptor */ + &gattScCcc, /* Service changed client characteristic configuration descriptor */ }; /* sanity check: make sure handle list length matches characteristic list length */ @@ -101,3 +118,68 @@ uint8_t GattValueUpdate(uint16_t *pHdlList, attEvt_t *pMsg) return status; } + +/*************************************************************************************************/ +/*! + * \brief Set Index of the Service Changed CCCD in the ATT Server. + * + * \param idx Index of the Service Changed CCCD in the ATT Server. + * + * \return None. + */ +/*************************************************************************************************/ +void GattSetSvcChangedIdx(uint8_t idx) +{ + gattServCb.svcChangedCccdIdxSet = TRUE; + gattServCb.svcChangedCccdIdx = idx; +} + +/*************************************************************************************************/ +/*! + * \brief Send Service Change Indications to the specified connections if they are configured to + * do so. + * + * \param connId DM Connection identifier or \ref DM_CONN_ID_NONE to send to all connections. + * \param start start handle for service changed value. + * \param end end handle for service changed value. + * + * \return None. + */ +/*************************************************************************************************/ +void GattSendServiceChangedInd(dmConnId_t connId, uint16_t start, uint16_t end) +{ + uint8_t svcChangedValues[4]; + uint8_t *p; + + if (!gattServCb.svcChangedCccdIdxSet) + { + return; + } + + p = svcChangedValues; + UINT16_TO_BSTREAM(p, start); + UINT16_TO_BSTREAM(p, end); + + /* If connection is not specified */ + if (connId == DM_CONN_ID_NONE) + { + /* Send to all. */ + for (connId = 1; connId <= DM_CONN_MAX; connId++) + { + if (AttsCccEnabled(connId, gattServCb.svcChangedCccdIdx)) + { + AttsHandleValueInd(connId, GATT_SC_HDL, sizeof(svcChangedValues), svcChangedValues); + } + } + } + else + { + /* Send to only this one. */ + if (AttsCccEnabled(connId, gattServCb.svcChangedCccdIdx)) + { + AttsHandleValueInd(connId, GATT_SC_HDL, sizeof(svcChangedValues), svcChangedValues); + } + } +} + +