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
Revision 82:6c51cbe4bc12, committed 2014-12-12
- Comitter:
- rgrover1
- Date:
- Fri Dec 12 13:23:17 2014 +0000
- Parent:
- 81:8b98f9feba1e
- Child:
- 83:71302acf1804
- Commit message:
- Synchronized with git rev 9b331846
Author: Rohit Grover
add support for write authorization.
Changed in this revision
--- a/btle/custom/custom_helper.cpp Thu Dec 11 12:07:13 2014 +0000
+++ b/btle/custom/custom_helper.cpp Fri Dec 12 13:23:17 2014 +0000
@@ -189,6 +189,7 @@
uint8_t *p_data,
uint16_t min_length,
uint16_t max_length,
+ bool writeAuthorization,
ble_gatts_char_handles_t *p_char_handle)
{
/* Characteristic metadata */
@@ -212,7 +213,7 @@
(char_props.notify || char_props.indicate) ? &cccd_md : NULL;
/* Attribute declaration */
- ble_gatts_attr_md_t attr_md = {0};
+ ble_gatts_attr_md_t attr_md = {.wr_auth = writeAuthorization};
attr_md.vloc = BLE_GATTS_VLOC_STACK;
attr_md.vlen = (min_length == max_length) ? 0 : 1;
@@ -289,4 +290,4 @@
p_desc_handle));
return ERROR_NONE;
-}
+}
\ No newline at end of file
--- a/btle/custom/custom_helper.h Thu Dec 11 12:07:13 2014 +0000
+++ b/btle/custom/custom_helper.h Fri Dec 12 13:23:17 2014 +0000
@@ -36,6 +36,7 @@
uint8_t *p_data,
uint16_t min_length,
uint16_t max_length,
+ bool writeAuthorization,
ble_gatts_char_handles_t *p_char_handle);
error_t custom_add_in_descriptor(uint16_t char_handle,
@@ -49,4 +50,4 @@
}
#endif
-#endif // ifndef _CUSTOM_HELPER_H_
+#endif // ifndef _CUSTOM_HELPER_H_
\ No newline at end of file
--- 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;
