|
25 | 25 | #include "wsf_types.h"
|
26 | 26 | #include "att_api.h"
|
27 | 27 |
|
| 28 | +/*! Maximum count of characteristics that can be stored for authorisation purposes */ |
| 29 | +#define MAX_CHARACTERISTIC_AUTHORIZATION_CNT 20 |
| 30 | + |
28 | 31 | /*! client characteristic configuration descriptors settings */
|
29 |
| -#define MAX_CCC_CNT 20 |
| 32 | +#define MAX_CCCD_CNT 20 |
30 | 33 |
|
31 | 34 | namespace ble {
|
32 | 35 | namespace vendor {
|
@@ -159,36 +162,74 @@ class GattServer : public ::GattServer,
|
159 | 162 | }
|
160 | 163 |
|
161 | 164 | 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); |
166 | 206 | void add_generic_access_service();
|
167 | 207 | void add_generic_attribute_service();
|
168 | 208 | 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); |
169 | 213 |
|
170 | 214 | struct alloc_block_t {
|
171 | 215 | alloc_block_t* next;
|
172 | 216 | uint8_t data[1];
|
173 | 217 | };
|
174 | 218 |
|
175 |
| - struct internal_char_t { |
176 |
| - uint16_t descLen; |
177 |
| - }; |
178 |
| - |
179 | 219 | struct internal_service_t {
|
180 |
| - uint16_t uuidLen; |
181 |
| - internal_char_t *chars; |
182 |
| - attsGroup_t *attGroup; |
| 220 | + attsGroup_t attGroup; |
183 | 221 | internal_service_t *next;
|
184 | 222 | };
|
185 | 223 |
|
186 | 224 | pal::SigningEventMonitor::EventHandler *_signing_event_handler;
|
187 | 225 |
|
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; |
192 | 233 |
|
193 | 234 | struct {
|
194 | 235 | attsGroup_t service;
|
|
0 commit comments