From ef7e8958f78e83dc93fa170e983ecd19bb7ce3e2 Mon Sep 17 00:00:00 2001
From: schneider <schneider@blinkenlichts.net>
Date: Tue, 30 Jul 2019 13:30:54 +0200
Subject: [PATCH] fix(ble): Add some static checking of the attribute group
 sizes

---
 epicardium/ble/svc_core.c                            | 12 ++++++++++++
 epicardium/ble/svc_dis.c                             |  2 ++
 .../stack/ble-profiles/sources/services/svc_core.h   |  2 ++
 3 files changed, 16 insertions(+)

diff --git a/epicardium/ble/svc_core.c b/epicardium/ble/svc_core.c
index 6b960466..318af04d 100644
--- a/epicardium/ble/svc_core.c
+++ b/epicardium/ble/svc_core.c
@@ -27,6 +27,7 @@
 #include "svc_core.h"
 #include "svc_ch.h"
 #include "svc_cfg.h"
+#include "wsf_assert.h"
 
 /**************************************************************************************************
   Macros
@@ -79,6 +80,9 @@ static const uint16_t gapLenCarCh = sizeof(gapValCarCh);
 /* central address resolution */
 static uint8_t gapValCar[] = {FALSE};
 static const uint16_t gapLenCar = sizeof(gapValCar);
+#if 0
+/* TODO card10:
+ * Enable these if "privacy" is enabled. See svc_core.h lien 38 */
 
 /* resolvable private address only characteristic */
 static const uint8_t gapValRpaoCh[] = {ATT_PROP_READ, UINT16_TO_BYTES(GAP_RPAO_HDL), UINT16_TO_BYTES(ATT_UUID_RPAO)};
@@ -87,6 +91,7 @@ static const uint16_t gapLenRpaoCh = sizeof(gapValRpaoCh);
 /* resolvable private address only */
 static uint8_t gapValRpao[] = {0};
 static const uint16_t gapLenRpao = sizeof(gapValRpao);
+#endif
 
 /* Attribute list for GAP group */
 static const attsAttr_t gapList[] =
@@ -147,6 +152,9 @@ static const attsAttr_t gapList[] =
     0,
     ATTS_PERMIT_READ
   },
+#if 0
+/* TODO card10:
+ * Enable these if "privacy" is enabled. See svc_core.h lien 38 */
   {
     attChUuid,
     (uint8_t *) gapValRpaoCh,
@@ -163,6 +171,7 @@ static const attsAttr_t gapList[] =
     0,
     ATTS_PERMIT_READ
   }
+#endif
 };
 
 /* GAP group structure */
@@ -176,6 +185,7 @@ static attsGroup_t svcGapGroup =
   GAP_END_HDL
 };
 
+WSF_CT_ASSERT(((sizeof(gapList) / sizeof(gapList[0])) == GAP_END_HDL - GAP_START_HDL + 1));
 /**************************************************************************************************
  GATT group
 **************************************************************************************************/
@@ -244,6 +254,8 @@ static attsGroup_t svcGattGroup =
   GATT_END_HDL
 };
 
+WSF_CT_ASSERT(((sizeof(gattList) / sizeof(gattList[0])) == GATT_END_HDL - GATT_START_HDL + 1));
+
 /*************************************************************************************************/
 /*!
  *  \brief  Add the services to the attribute server.
diff --git a/epicardium/ble/svc_dis.c b/epicardium/ble/svc_dis.c
index e26463dc..6b35a241 100644
--- a/epicardium/ble/svc_dis.c
+++ b/epicardium/ble/svc_dis.c
@@ -24,6 +24,7 @@
  */
 #include "wsf_types.h"
 #include "att_api.h"
+#include "wsf_assert.h"
 #include "wsf_trace.h"
 #include "util/bstream.h"
 #include "svc_dis.h"
@@ -306,6 +307,7 @@ static attsGroup_t svcDisGroup =
   DIS_END_HDL
 };
 
+WSF_CT_ASSERT(((sizeof(disList) / sizeof(disList[0])) == DIS_END_HDL - DIS_START_HDL + 1));
 /*************************************************************************************************/
 /*!
  *  \brief  Add the services to the attribute server.
diff --git a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/services/svc_core.h b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/services/svc_core.h
index 7f246ad7..05dbe5e7 100644
--- a/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/services/svc_core.h
+++ b/lib/sdk/Libraries/BTLE/stack/ble-profiles/sources/services/svc_core.h
@@ -33,6 +33,8 @@ extern "C" {
  Handle Ranges
 **************************************************************************************************/
 /** \name GAP Service Handles
+ * TODO card10:
+ * WTF!
  * \note GAP -- RPAO characterstic added only when DM Privacy enabled
  */
 /**@{*/
-- 
GitLab