Skip to content
Snippets Groups Projects
Commit d871d57b authored by schneider's avatar schneider
Browse files

change(ble): Update gatt api with service changed handling from upstream

parent e00d6ed9
No related branches found
No related tags found
1 merge request!446Initial MicroPython BLE support (GATTS)
...@@ -74,6 +74,31 @@ void GattDiscover(dmConnId_t connId, uint16_t *pHdlList); ...@@ -74,6 +74,31 @@ void GattDiscover(dmConnId_t connId, uint16_t *pHdlList);
/*************************************************************************************************/ /*************************************************************************************************/
uint8_t GattValueUpdate(uint16_t *pHdlList, attEvt_t *pMsg); 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 */ /*! \} */ /* GATT_PROFILE */
#ifdef __cplusplus #ifdef __cplusplus
......
...@@ -19,13 +19,30 @@ ...@@ -19,13 +19,30 @@
#include "wsf_types.h" #include "wsf_types.h"
#include "wsf_assert.h" #include "wsf_assert.h"
#include "util/bstream.h"
#include "app_api.h" #include "app_api.h"
#include "gatt/gatt_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 Local Variables
**************************************************************************************************/ **************************************************************************************************/
/* Control block. */
gattServCb_t gattServCb;
/*! GATT service characteristics for discovery */ /*! GATT service characteristics for discovery */
/*! Service changed */ /*! Service changed */
...@@ -46,7 +63,7 @@ static const attcDiscChar_t gattScCcc = ...@@ -46,7 +63,7 @@ static const attcDiscChar_t gattScCcc =
static const attcDiscChar_t *gattDiscCharList[] = static const attcDiscChar_t *gattDiscCharList[] =
{ {
&gattSc, /* Service changed */ &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 */ /* sanity check: make sure handle list length matches characteristic list length */
...@@ -101,3 +118,68 @@ uint8_t GattValueUpdate(uint16_t *pHdlList, attEvt_t *pMsg) ...@@ -101,3 +118,68 @@ uint8_t GattValueUpdate(uint16_t *pHdlList, attEvt_t *pMsg)
return status; 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);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment