Skip to content

Commit 0f64b1c

Browse files
committed
CordioGattServer: Global refactoring
The registration process has been breaked down into several functions that register the service attribute, characteristic declaration attributes, characteristic value attributes and characteristic descriptors. Service registration now consider all characteristics permissions: read, write and update. Permissions are also considered when updates needs to be propagated to peers. Handling of user authorization is also a change introduced by this refactoring.
1 parent 55eb703 commit 0f64b1c

File tree

2 files changed

+823
-330
lines changed

2 files changed

+823
-330
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@
2525
#include "wsf_types.h"
2626
#include "att_api.h"
2727

28+
/*! Maximum count of characteristics that can be stored for authorisation purposes */
29+
#define MAX_CHARACTERISTIC_AUTHORIZATION_CNT 20
30+
2831
/*! client characteristic configuration descriptors settings */
29-
#define MAX_CCC_CNT 20
32+
#define MAX_CCCD_CNT 20
3033

3134
namespace ble {
3235
namespace vendor {
@@ -159,36 +162,74 @@ class GattServer : public ::GattServer,
159162
}
160163

161164
private:
162-
static void cccCback(attsCccEvt_t *pEvt);
163-
static void attCback(attEvt_t *pEvt);
164-
static uint8_t attsReadCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, attsAttr_t *pAttr);
165-
static uint8_t attsWriteCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, uint16_t len, uint8_t *pValue, attsAttr_t *pAttr);
165+
static uint16_t compute_attributes_count(GattService& service);
166+
167+
void insert_service_attribute(
168+
GattService& service,
169+
attsAttr_t *&attribute_it
170+
);
171+
172+
ble_error_t insert_characteristic(
173+
GattCharacteristic *characteristic,
174+
attsAttr_t *&attribute_it
175+
);
176+
177+
bool is_characteristic_valid(GattCharacteristic *characteristic);
178+
179+
void insert_characteristic_declaration_attribute(
180+
GattCharacteristic *characteristic,
181+
attsAttr_t *&attribute_it
182+
);
183+
184+
ble_error_t insert_characteristic_value_attribute(
185+
GattCharacteristic *characteristic,
186+
attsAttr_t *&attribute_it
187+
);
188+
189+
ble_error_t insert_descriptor(
190+
GattCharacteristic *characteristic,
191+
GattAttribute* descriptor,
192+
attsAttr_t *&attribute_it,
193+
bool& cccd_created
194+
);
195+
196+
ble_error_t insert_cccd(
197+
GattCharacteristic *characteristic,
198+
attsAttr_t *&attribute_it
199+
);
200+
201+
static void cccd_cb(attsCccEvt_t *pEvt);
202+
static void att_cb(const attEvt_t *pEvt);
203+
static uint8_t atts_read_cb(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, attsAttr_t *pAttr);
204+
static uint8_t atts_write_cb(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, uint16_t len, uint8_t *pValue, attsAttr_t *pAttr);
205+
static uint8_t atts_auth_cb(dmConnId_t connId, uint8_t permit, uint16_t handle);
166206
void add_generic_access_service();
167207
void add_generic_attribute_service();
168208
void* alloc_block(size_t block_size);
209+
GattCharacteristic* get_auth_char(uint16_t value_handle);
210+
bool get_cccd_id(GattAttribute::Handle_t cccd_handle, uint8_t& idx) const;
211+
bool has_cccd(GattAttribute::Handle_t char_handle) const;
212+
bool is_update_authorized(Gap::Handle_t connection, GattAttribute::Handle_t value_handle);
169213

170214
struct alloc_block_t {
171215
alloc_block_t* next;
172216
uint8_t data[1];
173217
};
174218

175-
struct internal_char_t {
176-
uint16_t descLen;
177-
};
178-
179219
struct internal_service_t {
180-
uint16_t uuidLen;
181-
internal_char_t *chars;
182-
attsGroup_t *attGroup;
220+
attsGroup_t attGroup;
183221
internal_service_t *next;
184222
};
185223

186224
pal::SigningEventMonitor::EventHandler *_signing_event_handler;
187225

188-
attsCccSet_t cccSet[MAX_CCC_CNT];
189-
uint16_t cccValues[MAX_CCC_CNT];
190-
uint16_t cccHandles[MAX_CCC_CNT];
191-
uint8_t cccCnt;
226+
attsCccSet_t cccds[MAX_CCCD_CNT];
227+
uint16_t cccd_values[MAX_CCCD_CNT];
228+
uint16_t cccd_handles[MAX_CCCD_CNT];
229+
uint8_t cccd_cnt;
230+
231+
GattCharacteristic *_auth_char[MAX_CHARACTERISTIC_AUTHORIZATION_CNT];
232+
uint8_t _auth_char_count;
192233

193234
struct {
194235
attsGroup_t service;

0 commit comments

Comments
 (0)