Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
Diff: btle/custom/custom_helper.cpp
- Revision:
- 131:b21411170d00
- Parent:
- 126:e6114201f092
- Child:
- 146:ebe2aa09aa13
diff -r ec760bb91020 -r b21411170d00 btle/custom/custom_helper.cpp
--- a/btle/custom/custom_helper.cpp	Fri May 08 15:33:55 2015 +0100
+++ b/btle/custom/custom_helper.cpp	Fri May 08 15:33:55 2015 +0100
@@ -200,6 +200,7 @@
 error_t custom_add_in_characteristic(uint16_t    service_handle,
                                      ble_uuid_t *p_uuid,
                                      uint8_t     properties,
+                                     GattCharacteristic::ble_gatt_char_required_security_t requiredSecurity,
                                      uint8_t    *p_data,
                                      uint16_t    min_length,
                                      uint16_t    max_length,
@@ -244,11 +245,43 @@
     attr_md.vlen = (min_length == max_length) ? 0 : 1;
 
     if (char_props.read || char_props.notify || char_props.indicate) {
-        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
+        switch (requiredSecurity) {
+            case GattCharacteristic::SECURITY_MODE_ENCRYPTION_OPEN_LINK :
+                BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.read_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_ENCRYPTION_NO_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.read_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_ENCRYPTION_WITH_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&attr_md.read_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_SIGNED_NO_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(&attr_md.read_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_SIGNED_WITH_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(&attr_md.read_perm);
+                break;
+        };
     }
 
     if (char_props.write || char_props.write_wo_resp) {
-        BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
+        switch (requiredSecurity) {
+            case GattCharacteristic::SECURITY_MODE_ENCRYPTION_OPEN_LINK :
+                BLE_GAP_CONN_SEC_MODE_SET_OPEN(&attr_md.write_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_ENCRYPTION_NO_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_ENC_NO_MITM(&attr_md.write_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_ENCRYPTION_WITH_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_ENC_WITH_MITM(&attr_md.write_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_SIGNED_NO_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_SIGNED_NO_MITM(&attr_md.write_perm);
+                break;
+            case GattCharacteristic::SECURITY_MODE_SIGNED_WITH_MITM :
+                BLE_GAP_CONN_SEC_MODE_SET_SIGNED_WITH_MITM(&attr_md.write_perm);
+                break;
+        };
     }
 
     ble_gatts_attr_t attr_char_value = {0};
    