Patched version of nrf51822 FOTA compatible driver, with GPTIO disabled, as it clashed with the mbed definitions...

Fork of nRF51822 by Nordic Semiconductor

Revision:
82:6c51cbe4bc12
Parent:
78:9a5ba2c5d53c
Child:
83:71302acf1804
diff -r 8b98f9feba1e -r 6c51cbe4bc12 nRF51GattServer.cpp
--- a/nRF51GattServer.cpp	Thu Dec 11 12:07:13 2014 +0000
+++ b/nRF51GattServer.cpp	Fri Dec 12 13:23:17 2014 +0000
@@ -76,6 +76,7 @@
                                               p_char->getValueAttribute().getValuePtr(),
                                               p_char->getValueAttribute().getInitialLength(),
                                               p_char->getValueAttribute().getMaxLength(),
+                                              p_char->isWriteAuthorizationEnabled(),
                                               &nrfCharacteristicHandles[characteristicCount]),
                  BLE_ERROR_PARAM_OUT_OF_RANGE );
 
@@ -274,6 +275,14 @@
             sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0);
             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 */
+            }
+            eventType    = GattServerEvents::GATT_EVENT_WRITE_AUTHORIZATION_REQ;
+            handle_value = gattsEventP->params.authorize_request.request.write.handle;
+            break;
+
         default:
             return;
     }
@@ -293,6 +302,25 @@
                     handleDataWrittenEvent(&cbParams);
                     break;
                 }
+                case GattServerEvents::GATT_EVENT_WRITE_AUTHORIZATION_REQ: {
+                    GattCharacteristicWriteAuthCBParams cbParams = {
+                        .charHandle = i,
+                        .offset     = gattsEventP->params.authorize_request.request.write.offset,
+                        .len        = gattsEventP->params.authorize_request.request.write.len,
+                        .data       = gattsEventP->params.authorize_request.request.write.data,
+                    };
+                    ble_gatts_rw_authorize_reply_params_t reply = {
+                        .type = BLE_GATTS_AUTHORIZE_TYPE_WRITE,
+                        .params {
+                            .write = {
+                                .gatt_status = (p_characteristics[i]->authorizeWrite(&cbParams) ?
+                                                    BLE_GATT_STATUS_SUCCESS : BLE_GATT_STATUS_ATTERR_WRITE_NOT_PERMITTED)
+                            }
+                        }
+                    };
+                    sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
+                    break;
+                }
                 default:
                     handleEvent(eventType, i);
                     break;