@@ -31,6 +31,32 @@ typedef struct {
31
31
static unsigned uuidTableEntries = 0 ; /* current usage of the table */
32
32
converted_uuid_table_entry_t convertedUUIDTable[UUID_TABLE_MAX_ENTRIES];
33
33
34
+ namespace {
35
+
36
+ static void set_perm (ble_gap_conn_sec_mode_t & dest, GattAttribute::Security_t src) {
37
+ switch (src.value ()) {
38
+ case GattAttribute::Security_t::NONE:
39
+ BLE_GAP_CONN_SEC_MODE_SET_OPEN (&dest);
40
+ break ;
41
+
42
+ case GattAttribute::Security_t::UNAUTHENTICATED:
43
+ BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM (&dest);
44
+ break ;
45
+
46
+ case GattAttribute::Security_t::AUTHENTICATED:
47
+ BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM (&dest);
48
+ break ;
49
+
50
+ case GattAttribute::Security_t::SC_AUTHENTICATED:
51
+ BLE_GAP_CONN_SEC_MODE_SET_LESC_ENC_WITH_MITM (&dest);
52
+ break ;
53
+
54
+ default :
55
+ break ;
56
+ }
57
+ }
58
+
59
+ }
34
60
void custom_reset_128bits_uuid_table () {
35
61
uuidTableEntries = 0 ;
36
62
}
@@ -204,7 +230,9 @@ error_t custom_decode_uuid_base(uint8_t const *const p_uuid_base,
204
230
error_t custom_add_in_characteristic (uint16_t service_handle,
205
231
ble_uuid_t *p_uuid,
206
232
uint8_t properties,
207
- SecurityManager::SecurityMode_t requiredSecurity,
233
+ GattAttribute::Security_t read_security,
234
+ GattAttribute::Security_t write_security,
235
+ GattAttribute::Security_t update_security,
208
236
uint8_t *p_data,
209
237
uint16_t length,
210
238
uint16_t max_length,
@@ -227,8 +255,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
227
255
/* Notification requires cccd */
228
256
memclr_ ( &cccd_md, sizeof (ble_gatts_attr_md_t ));
229
257
cccd_md.vloc = BLE_GATTS_VLOC_STACK;
230
- BLE_GAP_CONN_SEC_MODE_SET_OPEN (& cccd_md.read_perm );
231
- BLE_GAP_CONN_SEC_MODE_SET_OPEN (& cccd_md.write_perm );
258
+ set_perm ( cccd_md.read_perm , GattAttribute::Security_t::NONE );
259
+ set_perm ( cccd_md.write_perm , update_security );
232
260
}
233
261
234
262
ble_gatts_char_md_t char_md = {0 };
@@ -257,49 +285,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
257
285
/* Always set variable size */
258
286
attr_md.vlen = has_variable_len;
259
287
260
- if (char_props.read || char_props.notify || char_props.indicate ) {
261
- switch (requiredSecurity) {
262
- case SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK :
263
- BLE_GAP_CONN_SEC_MODE_SET_OPEN (&attr_md.read_perm );
264
- break ;
265
- case SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM :
266
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM (&attr_md.read_perm );
267
- break ;
268
- case SecurityManager::SECURITY_MODE_ENCRYPTION_WITH_MITM :
269
- BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM (&attr_md.read_perm );
270
- break ;
271
- case SecurityManager::SECURITY_MODE_SIGNED_NO_MITM :
272
- BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM (&attr_md.read_perm );
273
- break ;
274
- case SecurityManager::SECURITY_MODE_SIGNED_WITH_MITM :
275
- BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM (&attr_md.read_perm );
276
- break ;
277
- default :
278
- break ;
279
- };
280
- }
281
-
282
- if (char_props.write || char_props.write_wo_resp ) {
283
- switch (requiredSecurity) {
284
- case SecurityManager::SECURITY_MODE_ENCRYPTION_OPEN_LINK :
285
- BLE_GAP_CONN_SEC_MODE_SET_OPEN (&attr_md.write_perm );
286
- break ;
287
- case SecurityManager::SECURITY_MODE_ENCRYPTION_NO_MITM :
288
- BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM (&attr_md.write_perm );
289
- break ;
290
- case SecurityManager::SECURITY_MODE_ENCRYPTION_WITH_MITM :
291
- BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM (&attr_md.write_perm );
292
- break ;
293
- case SecurityManager::SECURITY_MODE_SIGNED_NO_MITM :
294
- BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM (&attr_md.write_perm );
295
- break ;
296
- case SecurityManager::SECURITY_MODE_SIGNED_WITH_MITM :
297
- BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM (&attr_md.write_perm );
298
- break ;
299
- default :
300
- break ;
301
- };
302
- }
288
+ set_perm (attr_md.read_perm , read_security);
289
+ set_perm (attr_md.write_perm , write_security);
303
290
304
291
ble_gatts_attr_t attr_char_value = {0 };
305
292
@@ -343,7 +330,9 @@ error_t custom_add_in_descriptor(uint16_t char_handle,
343
330
uint16_t length,
344
331
uint16_t max_length,
345
332
bool has_variable_len,
346
- uint16_t *p_desc_handle)
333
+ uint16_t *p_desc_handle,
334
+ GattAttribute::Security_t read_security,
335
+ GattAttribute::Security_t write_security)
347
336
{
348
337
/* Descriptor metadata */
349
338
ble_gatts_attr_md_t desc_md = {0 };
@@ -353,8 +342,8 @@ error_t custom_add_in_descriptor(uint16_t char_handle,
353
342
desc_md.vlen = has_variable_len;
354
343
355
344
/* Make it readable and writable */
356
- BLE_GAP_CONN_SEC_MODE_SET_OPEN (& desc_md.read_perm );
357
- BLE_GAP_CONN_SEC_MODE_SET_OPEN (& desc_md.write_perm );
345
+ set_perm ( desc_md.read_perm , read_security );
346
+ set_perm ( desc_md.write_perm , write_security );
358
347
359
348
ble_gatts_attr_t attr_desc = {0 };
360
349
0 commit comments