BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Revision:
252:69d049317cae
Parent:
249:5d9118449482
Child:
253:097be53aea02
--- a/public/GattCharacteristic.h	Fri Dec 12 13:32:24 2014 +0000
+++ b/public/GattCharacteristic.h	Fri Dec 12 13:32:24 2014 +0000
@@ -334,7 +334,7 @@
         _properties(props),
         _descriptors(descriptors),
         _descriptorCount(numDescriptors),
-        enableWriteAuthorization(false),
+        enabledWriteAuthorization(false),
         writeAuthorizationCallback() {
         /* empty */
     }
@@ -344,13 +344,13 @@
      * Setup write authorization.
      */
     void setWriteAuthorizationCallback(void (*callback)(GattCharacteristicWriteAuthCBParams *)) {
-        enableWriteAuthorization = true;
         writeAuthorizationCallback.attach(callback);
+        enabledWriteAuthorization = true;
     }
     template <typename T>
     void setWriteAuthorizationCallback(T *object, void (T::*member)(GattCharacteristicWriteAuthCBParams *)) {
-        enableWriteAuthorization = true;
         writeAuthorizationCallback.attach(object, member);
+        enabledWriteAuthorization = true;
     }
 
     /**
@@ -360,6 +360,10 @@
      * @return        true if the write is authorized to proceed.
      */
     bool authorizeWrite(GattCharacteristicWriteAuthCBParams *params) {
+        if (!isWriteAuthorizationEnabled()) {
+            return true;
+        }
+
         params->authorizationReply = true; /* initialized to true by default */
         writeAuthorizationCallback.call(params);
         return params->authorizationReply;
@@ -370,7 +374,7 @@
     GattAttribute::Handle_t getValueHandle(void)          const {return getValueAttribute().getHandle();}
     uint8_t                 getProperties(void)           const {return _properties;     }
     uint8_t                 getDescriptorCount(void)      const {return _descriptorCount;}
-    bool                    isWriteAuthorizationEnabled() const {return enableWriteAuthorization;}
+    bool                    isWriteAuthorizationEnabled() const {return enabledWriteAuthorization;      }
 
     GattAttribute *getDescriptor(uint8_t index) {
         if (index >= _descriptorCount) {
@@ -385,7 +389,7 @@
     uint8_t         _properties;
     GattAttribute **_descriptors;
     uint8_t         _descriptorCount;
-    bool            enableWriteAuthorization;
+    bool            enabledWriteAuthorization;
     FunctionPointerWithContext<GattCharacteristicWriteAuthCBParams *> writeAuthorizationCallback;
 
 private: