SG RFID nRF51822 fork

Fork of nRF51822 by Nordic Semiconductor

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Fri Dec 12 13:23:18 2014 +0000
Parent:
82:6c51cbe4bc12
Child:
84:658e5ec772a1
Commit message:
Synchronized with git rev f6b58a5a
Author: Rohit Grover
Release 0.2.5
=============

API enhancements to support read/write authorization for GATT accesses.

Enhancements
~~~~~~~~~~~~

* Add support for authorization, whereby the user application can receive a
callback to authorize a read or a write on a characteristic's value
attribute before GATT commits the transaction.

Bugfixes
~~~~~~~~

Compatibility
~~~~~~~~~~~~~

This release is backward compatible with 0.2.3.

Changed in this revision

btle/custom/custom_helper.cpp Show annotated file Show diff for this revision Revisions of this file
btle/custom/custom_helper.h Show annotated file Show diff for this revision Revisions of this file
nRF51GattServer.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/btle/custom/custom_helper.cpp	Fri Dec 12 13:23:17 2014 +0000
+++ b/btle/custom/custom_helper.cpp	Fri Dec 12 13:23:18 2014 +0000
@@ -189,6 +189,7 @@
                                      uint8_t    *p_data,
                                      uint16_t    min_length,
                                      uint16_t    max_length,
+                                     bool        readAuthorization,
                                      bool        writeAuthorization,
                                      ble_gatts_char_handles_t *p_char_handle)
 {
@@ -213,7 +214,10 @@
         (char_props.notify || char_props.indicate) ? &cccd_md : NULL;
 
     /* Attribute declaration */
-    ble_gatts_attr_md_t attr_md = {.wr_auth = writeAuthorization};
+    ble_gatts_attr_md_t attr_md = {
+        .rd_auth = readAuthorization,
+        .wr_auth = writeAuthorization,
+    };
 
     attr_md.vloc = BLE_GATTS_VLOC_STACK;
     attr_md.vlen = (min_length == max_length) ? 0 : 1;
--- a/btle/custom/custom_helper.h	Fri Dec 12 13:23:17 2014 +0000
+++ b/btle/custom/custom_helper.h	Fri Dec 12 13:23:18 2014 +0000
@@ -36,6 +36,7 @@
                                      uint8_t                  *p_data,
                                      uint16_t                  min_length,
                                      uint16_t                  max_length,
+                                     bool                      readAuthorization,
                                      bool                      writeAuthorization,
                                      ble_gatts_char_handles_t *p_char_handle);
 
--- a/nRF51GattServer.cpp	Fri Dec 12 13:23:17 2014 +0000
+++ b/nRF51GattServer.cpp	Fri Dec 12 13:23:18 2014 +0000
@@ -76,6 +76,7 @@
                                               p_char->getValueAttribute().getValuePtr(),
                                               p_char->getValueAttribute().getInitialLength(),
                                               p_char->getValueAttribute().getMaxLength(),
+                                              p_char->isReadAuthorizationEnabled(),
                                               p_char->isWriteAuthorizationEnabled(),
                                               &nrfCharacteristicHandles[characteristicCount]),
                  BLE_ERROR_PARAM_OUT_OF_RANGE );
@@ -276,11 +277,18 @@
             return;
 
         case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
-            if (gattsEventP->params.authorize_request.type != BLE_GATTS_AUTHORIZE_TYPE_WRITE) {
-                return; /* we don't handle anything other than write authorization at the moment */
+            switch (gattsEventP->params.authorize_request.type) {
+                case BLE_GATTS_AUTHORIZE_TYPE_READ:
+                    eventType    = GattServerEvents::GATT_EVENT_READ_AUTHORIZATION_REQ;
+                    handle_value = gattsEventP->params.authorize_request.request.read.handle;
+                    break;
+                case BLE_GATTS_AUTHORIZE_TYPE_WRITE:
+                    eventType    = GattServerEvents::GATT_EVENT_WRITE_AUTHORIZATION_REQ;
+                    handle_value = gattsEventP->params.authorize_request.request.write.handle;
+                    break;
+                default:
+                    return;
             }
-            eventType    = GattServerEvents::GATT_EVENT_WRITE_AUTHORIZATION_REQ;
-            handle_value = gattsEventP->params.authorize_request.request.write.handle;
             break;
 
         default:
@@ -321,6 +329,24 @@
                     sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
                     break;
                 }
+                case GattServerEvents::GATT_EVENT_READ_AUTHORIZATION_REQ: {
+                    GattCharacteristicReadAuthCBParams cbParams = {
+                        .charHandle = i,
+                        .offset     = gattsEventP->params.authorize_request.request.read.offset,
+                    };
+                    ble_gatts_rw_authorize_reply_params_t reply = {
+                        .type = BLE_GATTS_AUTHORIZE_TYPE_READ,
+                        .params {
+                            .read = {
+                                .gatt_status = (p_characteristics[i]->authorizeRead(&cbParams) ?
+                                                    BLE_GATT_STATUS_SUCCESS : BLE_GATT_STATUS_ATTERR_READ_NOT_PERMITTED)
+                            }
+                        }
+                    };
+                    sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
+                    break;
+                }
+
                 default:
                     handleEvent(eventType, i);
                     break;