Nordic stack and drivers for the mbed BLE API

Dependents:   BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate writable_gatt ... more

Files at this revision

API Documentation at this revision

Comitter:
vcoubard
Date:
Fri Apr 08 11:05:55 2016 +0100
Parent:
620:98998cc3789b
Child:
622:5b9728d28fdc
Commit message:
Synchronized with git rev a18eb4a3
Author: Vincent Coubard
Fix incorrect handles of characteristics descriptors.

The variable descriptorCount is used as an index, and this index is used to set
the handle of the last registered descriptor.

Prior to this fix, descriptorCount was incremented before the handle the update
of the handle of a characteristics.

Short story, all characteristics descriptors handle were equaols to 0 instead
of the actual value.

Changed in this revision

CHANGELOG.md Show annotated file Show diff for this revision Revisions of this file
module.json Show annotated file Show diff for this revision Revisions of this file
source/btle/btle.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGattServer.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CHANGELOG.md	Fri Apr 08 11:05:55 2016 +0100
@@ -0,0 +1,329 @@
+# Change Log
+
+## [v2.5.1](https://github.com/ARMmbed/ble-nrf51822/tree/v2.5.1) (2016-01-27)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.5.0...v2.5.1)
+
+**Merged pull requests:**
+
+- Remove Gap::state updates from this module [\#108](https://github.com/ARMmbed/ble-nrf51822/pull/108) ([andresag01](https://github.com/andresag01))
+- merge version  [\#106](https://github.com/ARMmbed/ble-nrf51822/pull/106) ([pan-](https://github.com/pan-))
+
+## [v2.5.0](https://github.com/ARMmbed/ble-nrf51822/tree/v2.5.0) (2016-01-12)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.4.1...v2.5.0)
+
+**Merged pull requests:**
+
+- Fix access to enum member [\#105](https://github.com/ARMmbed/ble-nrf51822/pull/105) ([pan-](https://github.com/pan-))
+- Hotfix dependency [\#104](https://github.com/ARMmbed/ble-nrf51822/pull/104) ([pan-](https://github.com/pan-))
+- Finish implementation of getAddressesFromBondTable [\#103](https://github.com/ARMmbed/ble-nrf51822/pull/103) ([andresag01](https://github.com/andresag01))
+
+## [v2.4.1](https://github.com/ARMmbed/ble-nrf51822/tree/v2.4.1) (2016-01-11)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.4.0...v2.4.1)
+
+**Merged pull requests:**
+
+- merge branch develop \(v2.4.0\) [\#100](https://github.com/ARMmbed/ble-nrf51822/pull/100) ([pan-](https://github.com/pan-))
+
+## [v2.4.0](https://github.com/ARMmbed/ble-nrf51822/tree/v2.4.0) (2016-01-10)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.3.1...v2.4.0)
+
+**Merged pull requests:**
+
+- Add implementation of experimental whitelisting API [\#99](https://github.com/ARMmbed/ble-nrf51822/pull/99) ([andresag01](https://github.com/andresag01))
+
+## [v2.3.1](https://github.com/ARMmbed/ble-nrf51822/tree/v2.3.1) (2016-01-07)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.3.0...v2.3.1)
+
+**Merged pull requests:**
+
+- Update yotta module dependencies [\#98](https://github.com/ARMmbed/ble-nrf51822/pull/98) ([pan-](https://github.com/pan-))
+
+## [v2.3.0](https://github.com/ARMmbed/ble-nrf51822/tree/v2.3.0) (2015-12-23)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.10...v2.3.0)
+
+**Merged pull requests:**
+
+- Implementation of Characteristic descriptor discovery [\#74](https://github.com/ARMmbed/ble-nrf51822/pull/74) ([pan-](https://github.com/pan-))
+
+## [v2.2.10](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.10) (2015-12-23)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.9...v2.2.10)
+
+**Fixed bugs:**
+
+- nRF5xn::init don't verify if errors have occurred during btle\_init [\#59](https://github.com/ARMmbed/ble-nrf51822/issues/59)
+
+**Closed issues:**
+
+- A call to shutdown does not clear the state of some components of BLE API [\#85](https://github.com/ARMmbed/ble-nrf51822/issues/85)
+- Memory allocation issue on the NRF51DK board. [\#76](https://github.com/ARMmbed/ble-nrf51822/issues/76)
+- Terrible handling of initLen / minLen and variable length characteristics. [\#56](https://github.com/ARMmbed/ble-nrf51822/issues/56)
+
+**Merged pull requests:**
+
+- Fix shutdown of Gap instance to avoid NULL refs [\#96](https://github.com/ARMmbed/ble-nrf51822/pull/96) ([andresag01](https://github.com/andresag01))
+- Add check for return code of ble\_init [\#95](https://github.com/ARMmbed/ble-nrf51822/pull/95) ([andresag01](https://github.com/andresag01))
+
+## [v2.2.9](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.9) (2015-12-18)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.8...v2.2.9)
+
+**Closed issues:**
+
+- Cannot open source input file "system\_nrf51.h" [\#52](https://github.com/ARMmbed/ble-nrf51822/issues/52)
+
+**Merged pull requests:**
+
+- Remove occurrence of deprecated appearance enum [\#92](https://github.com/ARMmbed/ble-nrf51822/pull/92) ([andresag01](https://github.com/andresag01))
+
+## [v2.2.8](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.8) (2015-12-16)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.7...v2.2.8)
+
+## [v2.2.7](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.7) (2015-12-15)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.6...v2.2.7)
+
+**Merged pull requests:**
+
+- Replace deprecated inclusions of mbed.h [\#89](https://github.com/ARMmbed/ble-nrf51822/pull/89) ([andresag01](https://github.com/andresag01))
+- Improve shutdown to clear BLE API and not just SD [\#87](https://github.com/ARMmbed/ble-nrf51822/pull/87) ([andresag01](https://github.com/andresag01))
+
+## [v2.2.6](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.6) (2015-12-15)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.5...v2.2.6)
+
+**Merged pull requests:**
+
+- follow the extraction of address related types from Gap.h into BLEProtocol.h [\#88](https://github.com/ARMmbed/ble-nrf51822/pull/88) ([rgrover](https://github.com/rgrover))
+
+## [v2.2.5](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.5) (2015-12-11)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.3...v2.2.5)
+
+**Merged pull requests:**
+
+- Added SecurityManager::setLinkSecurity call for elevating security settings on a particular connection. [\#86](https://github.com/ARMmbed/ble-nrf51822/pull/86) ([marcuschangarm](https://github.com/marcuschangarm))
+
+## [v2.2.3](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.3) (2015-12-10)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.2...v2.2.3)
+
+## [v2.2.2](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.2) (2015-12-08)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.1...v2.2.2)
+
+**Merged pull requests:**
+
+- Add -Wno-unused-function to supress-warnings.cmake [\#83](https://github.com/ARMmbed/ble-nrf51822/pull/83) ([andresag01](https://github.com/andresag01))
+
+## [v2.2.1](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.1) (2015-12-08)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.2.0...v2.2.1)
+
+**Merged pull requests:**
+
+- WIP: UUID endian change [\#82](https://github.com/ARMmbed/ble-nrf51822/pull/82) ([marcuschangarm](https://github.com/marcuschangarm))
+
+## [v2.2.0](https://github.com/ARMmbed/ble-nrf51822/tree/v2.2.0) (2015-12-02)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.1.4...v2.2.0)
+
+## [v2.1.4](https://github.com/ARMmbed/ble-nrf51822/tree/v2.1.4) (2015-12-02)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.1.3...v2.1.4)
+
+## [v2.1.3](https://github.com/ARMmbed/ble-nrf51822/tree/v2.1.3) (2015-12-02)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.1.2...v2.1.3)
+
+## [v2.1.2](https://github.com/ARMmbed/ble-nrf51822/tree/v2.1.2) (2015-12-02)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.1.1...v2.1.2)
+
+**Merged pull requests:**
+
+- Allow GattAttributes to have variable length [\#81](https://github.com/ARMmbed/ble-nrf51822/pull/81) ([andresag01](https://github.com/andresag01))
+
+## [v2.1.1](https://github.com/ARMmbed/ble-nrf51822/tree/v2.1.1) (2015-12-02)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.1.0...v2.1.1)
+
+**Merged pull requests:**
+
+- Fixed endianness bug in nRF5xServiceDiscovery::processDiscoverUUIDResponse so it is consistent with BLE API. [\#80](https://github.com/ARMmbed/ble-nrf51822/pull/80) ([marcuschangarm](https://github.com/marcuschangarm))
+- Fixed bug in nRF5xGap.setAddress where random adresses where not set properly. [\#79](https://github.com/ARMmbed/ble-nrf51822/pull/79) ([marcuschangarm](https://github.com/marcuschangarm))
+- Separate concept of minlen and len for BLE chars [\#78](https://github.com/ARMmbed/ble-nrf51822/pull/78) ([andresag01](https://github.com/andresag01))
+- Split nordic sdk into its own module [\#75](https://github.com/ARMmbed/ble-nrf51822/pull/75) ([LiyouZhou](https://github.com/LiyouZhou))
+
+## [v2.1.0](https://github.com/ARMmbed/ble-nrf51822/tree/v2.1.0) (2015-11-27)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.8...v2.1.0)
+
+**Merged pull requests:**
+
+- Update to sdk 8.1 [\#77](https://github.com/ARMmbed/ble-nrf51822/pull/77) ([LiyouZhou](https://github.com/LiyouZhou))
+
+## [v2.0.8](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.8) (2015-11-26)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.7...v2.0.8)
+
+## [v2.0.7](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.7) (2015-11-26)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.6...v2.0.7)
+
+**Closed issues:**
+
+- test2000 [\#72](https://github.com/ARMmbed/ble-nrf51822/issues/72)
+- test1000000 [\#71](https://github.com/ARMmbed/ble-nrf51822/issues/71)
+- test4 [\#70](https://github.com/ARMmbed/ble-nrf51822/issues/70)
+- test3 [\#69](https://github.com/ARMmbed/ble-nrf51822/issues/69)
+- test2 [\#68](https://github.com/ARMmbed/ble-nrf51822/issues/68)
+
+**Merged pull requests:**
+
+- use Extern c around \#include to use nordic sdk headers implemented in C [\#73](https://github.com/ARMmbed/ble-nrf51822/pull/73) ([LiyouZhou](https://github.com/LiyouZhou))
+
+## [v2.0.6](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.6) (2015-11-17)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.5...v2.0.6)
+
+**Closed issues:**
+
+- test [\#66](https://github.com/ARMmbed/ble-nrf51822/issues/66)
+
+**Merged pull requests:**
+
+- add Nordic's license agreement. [\#67](https://github.com/ARMmbed/ble-nrf51822/pull/67) ([rgrover](https://github.com/rgrover))
+
+## [v2.0.5](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.5) (2015-11-16)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.4...v2.0.5)
+
+**Merged pull requests:**
+
+- Post radio notification callback through minar [\#65](https://github.com/ARMmbed/ble-nrf51822/pull/65) ([andresag01](https://github.com/andresag01))
+
+## [v2.0.4](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.4) (2015-11-13)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.3...v2.0.4)
+
+**Merged pull requests:**
+
+- Fix assembly sequence to start bootloader in GCC [\#64](https://github.com/ARMmbed/ble-nrf51822/pull/64) ([andresag01](https://github.com/andresag01))
+
+## [v2.0.3](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.3) (2015-11-09)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.2...v2.0.3)
+
+**Merged pull requests:**
+
+- Added watchdog header file from Nordic SDK 8.1 [\#62](https://github.com/ARMmbed/ble-nrf51822/pull/62) ([marcuschangarm](https://github.com/marcuschangarm))
+
+## [v2.0.2](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.2) (2015-11-03)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/mbedos-release-15-11...v2.0.2)
+
+## [mbedos-release-15-11](https://github.com/ARMmbed/ble-nrf51822/tree/mbedos-release-15-11) (2015-11-03)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.1...mbedos-release-15-11)
+
+## [v2.0.1](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.1) (2015-11-02)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v2.0.0...v2.0.1)
+
+**Merged pull requests:**
+
+- Ensure that the initialization flags is set to false if the BLE stack is shutdown properly. [\#58](https://github.com/ARMmbed/ble-nrf51822/pull/58) ([pan-](https://github.com/pan-))
+
+## [v2.0.0](https://github.com/ARMmbed/ble-nrf51822/tree/v2.0.0) (2015-11-02)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v1.1.0...v2.0.0)
+
+**Closed issues:**
+
+- Nordic SDK and SoftDevice [\#57](https://github.com/ARMmbed/ble-nrf51822/issues/57)
+- shouldn't eab6631cb be merged into master? [\#54](https://github.com/ARMmbed/ble-nrf51822/issues/54)
+
+**Merged pull requests:**
+
+- Introduced changes for memory savings [\#55](https://github.com/ARMmbed/ble-nrf51822/pull/55) ([andresag01](https://github.com/andresag01))
+
+## [v1.1.0](https://github.com/ARMmbed/ble-nrf51822/tree/v1.1.0) (2015-10-28)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/mbedos-techcon-oob2...v1.1.0)
+
+**Closed issues:**
+
+- target dependencies in module.json [\#50](https://github.com/ARMmbed/ble-nrf51822/issues/50)
+
+**Merged pull requests:**
+
+- When connecting, if no scanning parameters are passed, use values from Gap parent. [\#53](https://github.com/ARMmbed/ble-nrf51822/pull/53) ([marcuschangarm](https://github.com/marcuschangarm))
+
+## [mbedos-techcon-oob2](https://github.com/ARMmbed/ble-nrf51822/tree/mbedos-techcon-oob2) (2015-10-19)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v1.0.0...mbedos-techcon-oob2)
+
+## [v1.0.0](https://github.com/ARMmbed/ble-nrf51822/tree/v1.0.0) (2015-10-19)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v0.4.8...v1.0.0)
+
+**Closed issues:**
+
+- rename the bootloader files with \_fota in the name? [\#51](https://github.com/ARMmbed/ble-nrf51822/issues/51)
+
+**Merged pull requests:**
+
+- Update S110 detection macros, again [\#49](https://github.com/ARMmbed/ble-nrf51822/pull/49) ([jpbrucker](https://github.com/jpbrucker))
+- Error check number of characteristics [\#48](https://github.com/ARMmbed/ble-nrf51822/pull/48) ([Timmmm](https://github.com/Timmmm))
+
+## [v0.4.8](https://github.com/ARMmbed/ble-nrf51822/tree/v0.4.8) (2015-09-25)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v0.4.7...v0.4.8)
+
+**Closed issues:**
+
+- Error real cause loss in nRF5xGattServer.cpp [\#44](https://github.com/ARMmbed/ble-nrf51822/issues/44)
+
+**Merged pull requests:**
+
+- rgrover patch fixed [\#47](https://github.com/ARMmbed/ble-nrf51822/pull/47) ([fabiencomte](https://github.com/fabiencomte))
+- Update S110 detection macros [\#43](https://github.com/ARMmbed/ble-nrf51822/pull/43) ([jpbrucker](https://github.com/jpbrucker))
+- remove some unnecessary include paths [\#42](https://github.com/ARMmbed/ble-nrf51822/pull/42) ([autopulated](https://github.com/autopulated))
+- Add FOTA bootloader image [\#41](https://github.com/ARMmbed/ble-nrf51822/pull/41) ([jpbrucker](https://github.com/jpbrucker))
+
+## [v0.4.7](https://github.com/ARMmbed/ble-nrf51822/tree/v0.4.7) (2015-08-13)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v0.4.6...v0.4.7)
+
+## [v0.4.6](https://github.com/ARMmbed/ble-nrf51822/tree/v0.4.6) (2015-08-11)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v0.4.5...v0.4.6)
+
+**Closed issues:**
+
+- remove duplication of global static variable BLE\_EVT\_BUFFER [\#39](https://github.com/ARMmbed/ble-nrf51822/issues/39)
+- clearScanResponse\(\)  [\#30](https://github.com/ARMmbed/ble-nrf51822/issues/30)
+- Debug builds fail due to missing bsp.h [\#11](https://github.com/ARMmbed/ble-nrf51822/issues/11)
+
+**Merged pull requests:**
+
+- Disable GattClient features when using S110 SoftDevice [\#38](https://github.com/ARMmbed/ble-nrf51822/pull/38) ([jpbrucker](https://github.com/jpbrucker))
+
+## [v0.4.5](https://github.com/ARMmbed/ble-nrf51822/tree/v0.4.5) (2015-08-10)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v0.4.4...v0.4.5)
+
+## [v0.4.4](https://github.com/ARMmbed/ble-nrf51822/tree/v0.4.4) (2015-08-07)
+[Full Changelog](https://github.com/ARMmbed/ble-nrf51822/compare/v0.4.3...v0.4.4)
+
+**Closed issues:**
+
+- nrf51822 hangs after calling sd\_flash\_page\_erase\(\) [\#35](https://github.com/ARMmbed/ble-nrf51822/issues/35)
+- nRF5xn::getVersion return \(Unknown\) with version 8 soft device [\#29](https://github.com/ARMmbed/ble-nrf51822/issues/29)
+
+**Merged pull requests:**
+
+- Changed Gap:: to GapAdvertisingParams:: because of change in BLE [\#34](https://github.com/ARMmbed/ble-nrf51822/pull/34) ([jslater8](https://github.com/jslater8))
+- Select the clock source dynamically on SoftDevice initialisation [\#32](https://github.com/ARMmbed/ble-nrf51822/pull/32) ([jpbrucker](https://github.com/jpbrucker))
+- Add S110 SoftDevice compatibility [\#28](https://github.com/ARMmbed/ble-nrf51822/pull/28) ([jpbrucker](https://github.com/jpbrucker))
+
+## [v0.4.3](https://github.com/ARMmbed/ble-nrf51822/tree/v0.4.3) (2015-07-22)
+**Closed issues:**
+
+- Target polling failed [\#24](https://github.com/ARMmbed/ble-nrf51822/issues/24)
+- support  handling of HVX Events \(notifications and indications\). [\#22](https://github.com/ARMmbed/ble-nrf51822/issues/22)
+- provide an implementation for GattServer::areUpdatesEnabled\(\) [\#21](https://github.com/ARMmbed/ble-nrf51822/issues/21)
+- getValueHandle\(\) returns characteristicIndex instead of attribute-handle [\#20](https://github.com/ARMmbed/ble-nrf51822/issues/20)
+- Clash With Definition And Enum Naming [\#16](https://github.com/ARMmbed/ble-nrf51822/issues/16)
+- Errors in GCC build [\#14](https://github.com/ARMmbed/ble-nrf51822/issues/14)
+- bring s110 support back [\#10](https://github.com/ARMmbed/ble-nrf51822/issues/10)
+- Allow adding a User Description descriptor to a GattCharacteristic. [\#9](https://github.com/ARMmbed/ble-nrf51822/issues/9)
+- device\_manager\_peripheral.c includes app\_trace.h [\#7](https://github.com/ARMmbed/ble-nrf51822/issues/7)
+- linking esb\_gcc.a \(nrf51822 enhanced shock burst\) with mbed [\#5](https://github.com/ARMmbed/ble-nrf51822/issues/5)
+- The app\_timer usage may conflict [\#2](https://github.com/ARMmbed/ble-nrf51822/issues/2)
+- Nordic License [\#1](https://github.com/ARMmbed/ble-nrf51822/issues/1)
+
+**Merged pull requests:**
+
+- Develop [\#25](https://github.com/ARMmbed/ble-nrf51822/pull/25) ([zoujixing](https://github.com/zoujixing))
+- Remove unnecessary 'compiler\_abstraction.h' to get rid of duplicate '… [\#23](https://github.com/ARMmbed/ble-nrf51822/pull/23) ([adfernandes](https://github.com/adfernandes))
+- restructure for minimal yotta compatibility [\#15](https://github.com/ARMmbed/ble-nrf51822/pull/15) ([autopulated](https://github.com/autopulated))
+- Fix various GCC compilation issues. [\#12](https://github.com/ARMmbed/ble-nrf51822/pull/12) ([adfernandes](https://github.com/adfernandes))
+- Fix for GCC lost in SDK v8.0 update [\#8](https://github.com/ARMmbed/ble-nrf51822/pull/8) ([rosterloh](https://github.com/rosterloh))
+- new target DELTA\_DFCM\_NNN40 with nrf51822 chip, config internal RC crystal. [\#6](https://github.com/ARMmbed/ble-nrf51822/pull/6) ([Marcomissyou](https://github.com/Marcomissyou))
+- Updated return value for nRF51GattServer::updateValue. Will now report w... [\#4](https://github.com/ARMmbed/ble-nrf51822/pull/4) ([marcuschangarm](https://github.com/marcuschangarm))
+- Added optional data and length fields to the return struct for authorize... [\#3](https://github.com/ARMmbed/ble-nrf51822/pull/3) ([marcuschangarm](https://github.com/marcuschangarm))
+
+
+
+\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\ No newline at end of file
--- a/module.json	Fri Apr 08 11:05:53 2016 +0100
+++ b/module.json	Fri Apr 08 11:05:55 2016 +0100
@@ -1,6 +1,6 @@
 {
   "name": "ble-nrf51822",
-  "version": "2.5.0",
+  "version": "2.5.1",
   "description": "Nordic stack and drivers for the mbed BLE API.",
   "keywords": [
     "Bluetooth",
--- a/source/btle/btle.cpp	Fri Apr 08 11:05:53 2016 +0100
+++ b/source/btle/btle.cpp	Fri Apr 08 11:05:55 2016 +0100
@@ -189,12 +189,10 @@
                     break;
             }
 
-#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
             // Close all pending discoveries for this connection
             nRF5xGattClient& gattClient = ble.getGattClient();
             gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
             gattClient.discovery().terminate(handle);
-#endif
 
             gap.processDisconnectionEvent(handle, reason);
             break;
--- a/source/nRF5xGattServer.cpp	Fri Apr 08 11:05:53 2016 +0100
+++ b/source/nRF5xGattServer.cpp	Fri Apr 08 11:05:55 2016 +0100
@@ -1,513 +1,514 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "nRF5xGattServer.h"
-#ifdef YOTTA_CFG_MBED_OS
-    #include "mbed-drivers/mbed.h"
-#else
-    #include "mbed.h"
-#endif
-
-#include "common/common.h"
-#include "btle/custom/custom_helper.h"
-
-#include "nRF5xn.h"
-
-/**************************************************************************/
-/*!
-    @brief  Adds a new service to the GATT table on the peripheral
-
-    @returns    ble_error_t
-
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF5xGattServer::addService(GattService &service)
-{
-    /* ToDo: Make sure this service UUID doesn't already exist (?) */
-    /* ToDo: Basic validation */
-
-    /* Add the service to the nRF51 */
-    ble_uuid_t nordicUUID;
-    nordicUUID = custom_convert_to_nordic_uuid(service.getUUID());
-
-    uint16_t serviceHandle;
-    ASSERT( ERROR_NONE ==
-            sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
-                                     &nordicUUID,
-                                     &serviceHandle),
-            BLE_ERROR_PARAM_OUT_OF_RANGE );
-    service.setHandle(serviceHandle);
-
-    /* Add characteristics to the service */
-    for (uint8_t i = 0; i < service.getCharacteristicCount(); i++) {
-        if (characteristicCount >= BLE_TOTAL_CHARACTERISTICS) {
-            return BLE_ERROR_NO_MEM;
-        }
-        GattCharacteristic *p_char = service.getCharacteristic(i);
-
-        /* Skip any incompletely defined, read-only characteristics. */
-        if ((p_char->getValueAttribute().getValuePtr() == NULL) &&
-            (p_char->getValueAttribute().getLength() == 0) &&
-            (p_char->getProperties() == GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)) {
-            continue;
-        }
-
-        nordicUUID = custom_convert_to_nordic_uuid(p_char->getValueAttribute().getUUID());
-
-        /* The user-description descriptor is a special case which needs to be
-         * handled at the time of adding the characteristic. The following block
-         * is meant to discover its presence. */
-        const uint8_t *userDescriptionDescriptorValuePtr = NULL;
-        uint16_t userDescriptionDescriptorValueLen = 0;
-        for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
-            GattAttribute *p_desc = p_char->getDescriptor(j);
-            if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
-                userDescriptionDescriptorValuePtr = p_desc->getValuePtr();
-                userDescriptionDescriptorValueLen = p_desc->getLength();
-            }
-        }
-
-        ASSERT ( ERROR_NONE ==
-                 custom_add_in_characteristic(BLE_GATT_HANDLE_INVALID,
-                                              &nordicUUID,
-                                              p_char->getProperties(),
-                                              p_char->getRequiredSecurity(),
-                                              p_char->getValueAttribute().getValuePtr(),
-                                              p_char->getValueAttribute().getLength(),
-                                              p_char->getValueAttribute().getMaxLength(),
-                                              p_char->getValueAttribute().hasVariableLength(),
-                                              userDescriptionDescriptorValuePtr,
-                                              userDescriptionDescriptorValueLen,
-                                              p_char->isReadAuthorizationEnabled(),
-                                              p_char->isWriteAuthorizationEnabled(),
-                                              &nrfCharacteristicHandles[characteristicCount]),
-                 BLE_ERROR_PARAM_OUT_OF_RANGE );
-
-        /* Update the characteristic handle */
-        p_characteristics[characteristicCount] = p_char;
-        p_char->getValueAttribute().setHandle(nrfCharacteristicHandles[characteristicCount].value_handle);
-        characteristicCount++;
-
-        /* Add optional descriptors if any */
-        for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
-            if (descriptorCount >= BLE_TOTAL_DESCRIPTORS) {
-                return BLE_ERROR_NO_MEM;
-            }
-
-            GattAttribute *p_desc = p_char->getDescriptor(j);
-            /* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */
-            if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
-                continue;
-            }
-
-            nordicUUID = custom_convert_to_nordic_uuid(p_desc->getUUID());
-
-            ASSERT(ERROR_NONE ==
-                   custom_add_in_descriptor(BLE_GATT_HANDLE_INVALID,
-                                            &nordicUUID,
-                                            p_desc->getValuePtr(),
-                                            p_desc->getLength(),
-                                            p_desc->getMaxLength(),
-                                            p_desc->hasVariableLength(),
-                                            &nrfDescriptorHandles[descriptorCount]),
-                BLE_ERROR_PARAM_OUT_OF_RANGE);
-
-            p_descriptors[descriptorCount++] = p_desc;
-            p_desc->setHandle(nrfDescriptorHandles[descriptorCount]);
-        }
-    }
-
-    serviceCount++;
-
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Reads the value of a characteristic, based on the service
-            and characteristic index fields
-
-    @param[in]  attributeHandle
-                The handle of the GattCharacteristic to read from
-    @param[in]  buffer
-                Buffer to hold the the characteristic's value
-                (raw byte array in LSB format)
-    @param[in/out] len
-                input:  Length in bytes to be read.
-                output: Total length of attribute value upon successful return.
-
-    @returns    ble_error_t
-
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-*/
-/**************************************************************************/
-ble_error_t nRF5xGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
-{
-    return read(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, lengthP);
-}
-
-ble_error_t nRF5xGattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
-{
-    ble_gatts_value_t value = {
-        .len     = *lengthP,
-        .offset  = 0,
-        .p_value = buffer,
-    };
-
-    ASSERT( ERROR_NONE ==
-            sd_ble_gatts_value_get(connectionHandle, attributeHandle, &value),
-            BLE_ERROR_PARAM_OUT_OF_RANGE);
-    *lengthP = value.len;
-
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Updates the value of a characteristic, based on the service
-            and characteristic index fields
-
-    @param[in]  charHandle
-                The handle of the GattCharacteristic to write to
-    @param[in]  buffer
-                Data to use when updating the characteristic's value
-                (raw byte array in LSB format)
-    @param[in]  len
-                The number of bytes in buffer
-
-    @returns    ble_error_t
-
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-*/
-/**************************************************************************/
-ble_error_t nRF5xGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
-{
-    return write(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, len, localOnly);
-}
-
-ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
-{
-    ble_error_t returnValue = BLE_ERROR_NONE;
-
-    ble_gatts_value_t value = {
-        .len     = len,
-        .offset  = 0,
-        .p_value = const_cast<uint8_t *>(buffer),
-    };
-
-    if (localOnly) {
-        /* Only update locally regardless of notify/indicate */
-        ASSERT_INT( ERROR_NONE,
-                    sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value),
-                    BLE_ERROR_PARAM_OUT_OF_RANGE );
-        return BLE_ERROR_NONE;
-    }
-
-    int characteristicIndex = resolveValueHandleToCharIndex(attributeHandle);
-    if ((characteristicIndex != -1) &&
-        (p_characteristics[characteristicIndex]->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY))) {
-        /* HVX update for the characteristic value */
-        ble_gatts_hvx_params_t hvx_params;
-
-        hvx_params.handle = attributeHandle;
-        hvx_params.type   =
-            (p_characteristics[characteristicIndex]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION;
-        hvx_params.offset = 0;
-        hvx_params.p_data = const_cast<uint8_t *>(buffer);
-        hvx_params.p_len  = &len;
-
-        if (connectionHandle == BLE_CONN_HANDLE_INVALID) { /* use the default connection handle if the caller hasn't specified a valid connectionHandle. */
-            nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
-            connectionHandle = gap.getConnectionHandle();
-        }
-        error_t error = (error_t) sd_ble_gatts_hvx(connectionHandle, &hvx_params);
-        if (error != ERROR_NONE) {
-            switch (error) {
-                case ERROR_BLE_NO_TX_BUFFERS: /*  Notifications consume application buffers. The return value can be used for resending notifications. */
-                case ERROR_BUSY:
-                    returnValue = BLE_STACK_BUSY;
-                    break;
-
-                case ERROR_INVALID_STATE:
-                case ERROR_BLEGATTS_SYS_ATTR_MISSING:
-                    returnValue = BLE_ERROR_INVALID_STATE;
-                    break;
-
-                default :
-                    ASSERT_INT( ERROR_NONE,
-                                sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value),
-                                BLE_ERROR_PARAM_OUT_OF_RANGE );
-
-                    /* Notifications consume application buffers. The return value can
-                     * be used for resending notifications. */
-                    returnValue = BLE_STACK_BUSY;
-                    break;
-            }
-        }
-    } else {
-        returnValue = BLE_ERROR_INVALID_STATE; // if assert is not used
-        ASSERT_INT( ERROR_NONE,
-                    sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value),
-                    BLE_ERROR_PARAM_OUT_OF_RANGE );
-    }
-
-    return returnValue;
-}
-
-ble_error_t nRF5xGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
-{
-    /* Forward the call with the default connection handle. */
-    nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
-    return areUpdatesEnabled(gap.getConnectionHandle(), characteristic, enabledP);
-}
-
-ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
-{
-    int characteristicIndex = resolveValueHandleToCharIndex(characteristic.getValueHandle());
-    if (characteristicIndex == -1) {
-        return BLE_ERROR_INVALID_PARAM;
-    }
-
-    /* Read the cccd value from the GATT server. */
-    GattAttribute::Handle_t cccdHandle = nrfCharacteristicHandles[characteristicIndex].cccd_handle;
-    uint16_t cccdValue;
-    uint16_t length = sizeof(cccdValue);
-    ble_error_t rc = read(connectionHandle, cccdHandle, reinterpret_cast<uint8_t *>(&cccdValue), &length);
-    if (rc != BLE_ERROR_NONE) {
-        return rc;
-    }
-    if (length != sizeof(cccdValue)) {
-        return BLE_ERROR_INVALID_STATE;
-    }
-
-    /* Check for NOTFICATION or INDICATION in CCCD. */
-    if ((cccdValue & BLE_GATT_HVX_NOTIFICATION) || (cccdValue & BLE_GATT_HVX_INDICATION)) {
-        *enabledP = true;
-    }
-
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Clear nRF5xGattServer's state.
-
-    @returns    ble_error_t
-
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-*/
-/**************************************************************************/
-ble_error_t nRF5xGattServer::reset(void)
-{
-    /* Clear all state that is from the parent, including private members */
-    if (GattServer::reset() != BLE_ERROR_NONE) {
-        return BLE_ERROR_INVALID_STATE;
-    }
-
-    /* Clear derived class members */
-    memset(p_characteristics,        0, sizeof(p_characteristics));
-    memset(p_descriptors,            0, sizeof(p_descriptors));
-    memset(nrfCharacteristicHandles, 0, sizeof(ble_gatts_char_handles_t));
-    memset(nrfDescriptorHandles,     0, sizeof(nrfDescriptorHandles));
-    descriptorCount = 0;
-
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Callback handler for events getting pushed up from the SD
-*/
-/**************************************************************************/
-void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
-{
-    GattAttribute::Handle_t        handle_value;
-    GattServerEvents::gattEvent_t  eventType;
-    const ble_gatts_evt_t         *gattsEventP = &p_ble_evt->evt.gatts_evt;
-
-    switch (p_ble_evt->header.evt_id) {
-        case BLE_GATTS_EVT_WRITE: {
-                /* There are 2 use case here: Values being updated & CCCD (indicate/notify) enabled */
-
-                /* 1.) Handle CCCD changes */
-                handle_value = gattsEventP->params.write.handle;
-                int characteristicIndex = resolveCCCDHandleToCharIndex(handle_value);
-                if ((characteristicIndex != -1) &&
-                    (p_characteristics[characteristicIndex]->getProperties() &
-                        (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY))) {
-
-                    uint16_t cccd_value = (gattsEventP->params.write.data[1] << 8) | gattsEventP->params.write.data[0]; /* Little Endian but M0 may be mis-aligned */
-
-                    if (((p_characteristics[characteristicIndex]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE) && (cccd_value & BLE_GATT_HVX_INDICATION)) ||
-                        ((p_characteristics[characteristicIndex]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) && (cccd_value & BLE_GATT_HVX_NOTIFICATION))) {
-                        eventType = GattServerEvents::GATT_EVENT_UPDATES_ENABLED;
-                    } else {
-                        eventType = GattServerEvents::GATT_EVENT_UPDATES_DISABLED;
-                    }
-
-                    handleEvent(eventType, p_characteristics[characteristicIndex]->getValueHandle());
-                    return;
-                }
-
-                /* 2.) Changes to the characteristic value will be handled with other events below */
-                eventType = GattServerEvents::GATT_EVENT_DATA_WRITTEN;
-            }
-            break;
-
-        case BLE_GATTS_EVT_HVC:
-            /* Indication confirmation received */
-            eventType    = GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED;
-            handle_value = gattsEventP->params.hvc.handle;
-            break;
-
-        case BLE_EVT_TX_COMPLETE: {
-            handleDataSentEvent(p_ble_evt->evt.common_evt.params.tx_complete.count);
-            return;
-        }
-
-        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
-            sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0, 0);
-            return;
-
-        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
-            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;
-            }
-            break;
-
-        default:
-            return;
-    }
-
-    int characteristicIndex = resolveValueHandleToCharIndex(handle_value);
-    if (characteristicIndex == -1) {
-        return;
-    }
-
-    /* Find index (charHandle) in the pool */
-    switch (eventType) {
-        case GattServerEvents::GATT_EVENT_DATA_WRITTEN: {
-            GattWriteCallbackParams cbParams = {
-                .connHandle = gattsEventP->conn_handle,
-                .handle     = handle_value,
-                .writeOp    = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
-                .offset     = gattsEventP->params.write.offset,
-                .len        = gattsEventP->params.write.len,
-                .data       = gattsEventP->params.write.data
-            };
-            handleDataWrittenEvent(&cbParams);
-            break;
-        }
-        case GattServerEvents::GATT_EVENT_WRITE_AUTHORIZATION_REQ: {
-            GattWriteAuthCallbackParams cbParams = {
-                .connHandle = gattsEventP->conn_handle,
-                .handle     = handle_value,
-                .offset     = gattsEventP->params.authorize_request.request.write.offset,
-                .len        = gattsEventP->params.authorize_request.request.write.len,
-                .data       = gattsEventP->params.authorize_request.request.write.data,
-                .authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS /* the callback handler must leave this member
-                                                                   * set to AUTH_CALLBACK_REPLY_SUCCESS if the client
-                                                                   * request is to proceed. */
-            };
-            ble_gatts_rw_authorize_reply_params_t reply = {
-                .type = BLE_GATTS_AUTHORIZE_TYPE_WRITE,
-                .params = {
-                    .write = {
-                        .gatt_status = p_characteristics[characteristicIndex]->authorizeWrite(&cbParams)
-                    }
-                }
-            };
-            sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
-
-            /*
-             * If write-authorization is enabled for a characteristic,
-             * AUTHORIZATION_REQ event (if replied with true) is *not*
-             * followed by another DATA_WRITTEN event; so we still need
-             * to invoke handleDataWritten(), much the same as we would
-             * have done if write-authorization had not been enabled.
-             */
-            if (reply.params.write.gatt_status == BLE_GATT_STATUS_SUCCESS) {
-                GattWriteCallbackParams cbParams = {
-                    .connHandle = gattsEventP->conn_handle,
-                    .handle     = handle_value,
-                    .writeOp    = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
-                    .offset     = gattsEventP->params.authorize_request.request.write.offset,
-                    .len        = gattsEventP->params.authorize_request.request.write.len,
-                    .data       = gattsEventP->params.authorize_request.request.write.data,
-                };
-                handleDataWrittenEvent(&cbParams);
-            }
-            break;
-        }
-        case GattServerEvents::GATT_EVENT_READ_AUTHORIZATION_REQ: {
-            GattReadAuthCallbackParams cbParams = {
-                .connHandle         = gattsEventP->conn_handle,
-                .handle             = handle_value,
-                .offset             = gattsEventP->params.authorize_request.request.read.offset,
-                .len                = 0,
-                .data               = NULL,
-                .authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS /* the callback handler must leave this member
-                                                                   * set to AUTH_CALLBACK_REPLY_SUCCESS if the client
-                                                                   * request is to proceed. */
-            };
-
-            ble_gatts_rw_authorize_reply_params_t reply = {
-                .type = BLE_GATTS_AUTHORIZE_TYPE_READ,
-                .params = {
-                    .read = {
-                        .gatt_status = p_characteristics[characteristicIndex]->authorizeRead(&cbParams)
-                    }
-                }
-            };
-
-            if (cbParams.authorizationReply == BLE_GATT_STATUS_SUCCESS) {
-                if (cbParams.data != NULL) {
-                    reply.params.read.update = 1;
-                    reply.params.read.offset = cbParams.offset;
-                    reply.params.read.len    = cbParams.len;
-                    reply.params.read.p_data = cbParams.data;
-                }
-            }
-
-            sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
-            break;
-        }
-
-        default:
-            handleEvent(eventType, handle_value);
-            break;
-    }
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "nRF5xGattServer.h"
+#ifdef YOTTA_CFG_MBED_OS
+    #include "mbed-drivers/mbed.h"
+#else
+    #include "mbed.h"
+#endif
+
+#include "common/common.h"
+#include "btle/custom/custom_helper.h"
+
+#include "nRF5xn.h"
+
+/**************************************************************************/
+/*!
+    @brief  Adds a new service to the GATT table on the peripheral
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF5xGattServer::addService(GattService &service)
+{
+    /* ToDo: Make sure this service UUID doesn't already exist (?) */
+    /* ToDo: Basic validation */
+
+    /* Add the service to the nRF51 */
+    ble_uuid_t nordicUUID;
+    nordicUUID = custom_convert_to_nordic_uuid(service.getUUID());
+
+    uint16_t serviceHandle;
+    ASSERT( ERROR_NONE ==
+            sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY,
+                                     &nordicUUID,
+                                     &serviceHandle),
+            BLE_ERROR_PARAM_OUT_OF_RANGE );
+    service.setHandle(serviceHandle);
+
+    /* Add characteristics to the service */
+    for (uint8_t i = 0; i < service.getCharacteristicCount(); i++) {
+        if (characteristicCount >= BLE_TOTAL_CHARACTERISTICS) {
+            return BLE_ERROR_NO_MEM;
+        }
+        GattCharacteristic *p_char = service.getCharacteristic(i);
+
+        /* Skip any incompletely defined, read-only characteristics. */
+        if ((p_char->getValueAttribute().getValuePtr() == NULL) &&
+            (p_char->getValueAttribute().getLength() == 0) &&
+            (p_char->getProperties() == GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)) {
+            continue;
+        }
+
+        nordicUUID = custom_convert_to_nordic_uuid(p_char->getValueAttribute().getUUID());
+
+        /* The user-description descriptor is a special case which needs to be
+         * handled at the time of adding the characteristic. The following block
+         * is meant to discover its presence. */
+        const uint8_t *userDescriptionDescriptorValuePtr = NULL;
+        uint16_t userDescriptionDescriptorValueLen = 0;
+        for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
+            GattAttribute *p_desc = p_char->getDescriptor(j);
+            if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
+                userDescriptionDescriptorValuePtr = p_desc->getValuePtr();
+                userDescriptionDescriptorValueLen = p_desc->getLength();
+            }
+        }
+
+        ASSERT ( ERROR_NONE ==
+                 custom_add_in_characteristic(BLE_GATT_HANDLE_INVALID,
+                                              &nordicUUID,
+                                              p_char->getProperties(),
+                                              p_char->getRequiredSecurity(),
+                                              p_char->getValueAttribute().getValuePtr(),
+                                              p_char->getValueAttribute().getLength(),
+                                              p_char->getValueAttribute().getMaxLength(),
+                                              p_char->getValueAttribute().hasVariableLength(),
+                                              userDescriptionDescriptorValuePtr,
+                                              userDescriptionDescriptorValueLen,
+                                              p_char->isReadAuthorizationEnabled(),
+                                              p_char->isWriteAuthorizationEnabled(),
+                                              &nrfCharacteristicHandles[characteristicCount]),
+                 BLE_ERROR_PARAM_OUT_OF_RANGE );
+
+        /* Update the characteristic handle */
+        p_characteristics[characteristicCount] = p_char;
+        p_char->getValueAttribute().setHandle(nrfCharacteristicHandles[characteristicCount].value_handle);
+        characteristicCount++;
+
+        /* Add optional descriptors if any */
+        for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
+            if (descriptorCount >= BLE_TOTAL_DESCRIPTORS) {
+                return BLE_ERROR_NO_MEM;
+            }
+
+            GattAttribute *p_desc = p_char->getDescriptor(j);
+            /* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */
+            if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
+                continue;
+            }
+
+            nordicUUID = custom_convert_to_nordic_uuid(p_desc->getUUID());
+
+            ASSERT(ERROR_NONE ==
+                   custom_add_in_descriptor(BLE_GATT_HANDLE_INVALID,
+                                            &nordicUUID,
+                                            p_desc->getValuePtr(),
+                                            p_desc->getLength(),
+                                            p_desc->getMaxLength(),
+                                            p_desc->hasVariableLength(),
+                                            &nrfDescriptorHandles[descriptorCount]),
+                BLE_ERROR_PARAM_OUT_OF_RANGE);
+
+            p_descriptors[descriptorCount] = p_desc;
+            p_desc->setHandle(nrfDescriptorHandles[descriptorCount]);
+            descriptorCount++;
+        }
+    }
+
+    serviceCount++;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Reads the value of a characteristic, based on the service
+            and characteristic index fields
+
+    @param[in]  attributeHandle
+                The handle of the GattCharacteristic to read from
+    @param[in]  buffer
+                Buffer to hold the the characteristic's value
+                (raw byte array in LSB format)
+    @param[in/out] len
+                input:  Length in bytes to be read.
+                output: Total length of attribute value upon successful return.
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+*/
+/**************************************************************************/
+ble_error_t nRF5xGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
+{
+    return read(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, lengthP);
+}
+
+ble_error_t nRF5xGattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP)
+{
+    ble_gatts_value_t value = {
+        .len     = *lengthP,
+        .offset  = 0,
+        .p_value = buffer,
+    };
+
+    ASSERT( ERROR_NONE ==
+            sd_ble_gatts_value_get(connectionHandle, attributeHandle, &value),
+            BLE_ERROR_PARAM_OUT_OF_RANGE);
+    *lengthP = value.len;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Updates the value of a characteristic, based on the service
+            and characteristic index fields
+
+    @param[in]  charHandle
+                The handle of the GattCharacteristic to write to
+    @param[in]  buffer
+                Data to use when updating the characteristic's value
+                (raw byte array in LSB format)
+    @param[in]  len
+                The number of bytes in buffer
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+*/
+/**************************************************************************/
+ble_error_t nRF5xGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
+{
+    return write(BLE_CONN_HANDLE_INVALID, attributeHandle, buffer, len, localOnly);
+}
+
+ble_error_t nRF5xGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly)
+{
+    ble_error_t returnValue = BLE_ERROR_NONE;
+
+    ble_gatts_value_t value = {
+        .len     = len,
+        .offset  = 0,
+        .p_value = const_cast<uint8_t *>(buffer),
+    };
+
+    if (localOnly) {
+        /* Only update locally regardless of notify/indicate */
+        ASSERT_INT( ERROR_NONE,
+                    sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value),
+                    BLE_ERROR_PARAM_OUT_OF_RANGE );
+        return BLE_ERROR_NONE;
+    }
+
+    int characteristicIndex = resolveValueHandleToCharIndex(attributeHandle);
+    if ((characteristicIndex != -1) &&
+        (p_characteristics[characteristicIndex]->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY))) {
+        /* HVX update for the characteristic value */
+        ble_gatts_hvx_params_t hvx_params;
+
+        hvx_params.handle = attributeHandle;
+        hvx_params.type   =
+            (p_characteristics[characteristicIndex]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) ? BLE_GATT_HVX_NOTIFICATION : BLE_GATT_HVX_INDICATION;
+        hvx_params.offset = 0;
+        hvx_params.p_data = const_cast<uint8_t *>(buffer);
+        hvx_params.p_len  = &len;
+
+        if (connectionHandle == BLE_CONN_HANDLE_INVALID) { /* use the default connection handle if the caller hasn't specified a valid connectionHandle. */
+            nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
+            connectionHandle = gap.getConnectionHandle();
+        }
+        error_t error = (error_t) sd_ble_gatts_hvx(connectionHandle, &hvx_params);
+        if (error != ERROR_NONE) {
+            switch (error) {
+                case ERROR_BLE_NO_TX_BUFFERS: /*  Notifications consume application buffers. The return value can be used for resending notifications. */
+                case ERROR_BUSY:
+                    returnValue = BLE_STACK_BUSY;
+                    break;
+
+                case ERROR_INVALID_STATE:
+                case ERROR_BLEGATTS_SYS_ATTR_MISSING:
+                    returnValue = BLE_ERROR_INVALID_STATE;
+                    break;
+
+                default :
+                    ASSERT_INT( ERROR_NONE,
+                                sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value),
+                                BLE_ERROR_PARAM_OUT_OF_RANGE );
+
+                    /* Notifications consume application buffers. The return value can
+                     * be used for resending notifications. */
+                    returnValue = BLE_STACK_BUSY;
+                    break;
+            }
+        }
+    } else {
+        returnValue = BLE_ERROR_INVALID_STATE; // if assert is not used
+        ASSERT_INT( ERROR_NONE,
+                    sd_ble_gatts_value_set(connectionHandle, attributeHandle, &value),
+                    BLE_ERROR_PARAM_OUT_OF_RANGE );
+    }
+
+    return returnValue;
+}
+
+ble_error_t nRF5xGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP)
+{
+    /* Forward the call with the default connection handle. */
+    nRF5xGap &gap = (nRF5xGap &) nRF5xn::Instance(BLE::DEFAULT_INSTANCE).getGap();
+    return areUpdatesEnabled(gap.getConnectionHandle(), characteristic, enabledP);
+}
+
+ble_error_t nRF5xGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP)
+{
+    int characteristicIndex = resolveValueHandleToCharIndex(characteristic.getValueHandle());
+    if (characteristicIndex == -1) {
+        return BLE_ERROR_INVALID_PARAM;
+    }
+
+    /* Read the cccd value from the GATT server. */
+    GattAttribute::Handle_t cccdHandle = nrfCharacteristicHandles[characteristicIndex].cccd_handle;
+    uint16_t cccdValue;
+    uint16_t length = sizeof(cccdValue);
+    ble_error_t rc = read(connectionHandle, cccdHandle, reinterpret_cast<uint8_t *>(&cccdValue), &length);
+    if (rc != BLE_ERROR_NONE) {
+        return rc;
+    }
+    if (length != sizeof(cccdValue)) {
+        return BLE_ERROR_INVALID_STATE;
+    }
+
+    /* Check for NOTFICATION or INDICATION in CCCD. */
+    if ((cccdValue & BLE_GATT_HVX_NOTIFICATION) || (cccdValue & BLE_GATT_HVX_INDICATION)) {
+        *enabledP = true;
+    }
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Clear nRF5xGattServer's state.
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+*/
+/**************************************************************************/
+ble_error_t nRF5xGattServer::reset(void)
+{
+    /* Clear all state that is from the parent, including private members */
+    if (GattServer::reset() != BLE_ERROR_NONE) {
+        return BLE_ERROR_INVALID_STATE;
+    }
+
+    /* Clear derived class members */
+    memset(p_characteristics,        0, sizeof(p_characteristics));
+    memset(p_descriptors,            0, sizeof(p_descriptors));
+    memset(nrfCharacteristicHandles, 0, sizeof(ble_gatts_char_handles_t));
+    memset(nrfDescriptorHandles,     0, sizeof(nrfDescriptorHandles));
+    descriptorCount = 0;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Callback handler for events getting pushed up from the SD
+*/
+/**************************************************************************/
+void nRF5xGattServer::hwCallback(ble_evt_t *p_ble_evt)
+{
+    GattAttribute::Handle_t        handle_value;
+    GattServerEvents::gattEvent_t  eventType;
+    const ble_gatts_evt_t         *gattsEventP = &p_ble_evt->evt.gatts_evt;
+
+    switch (p_ble_evt->header.evt_id) {
+        case BLE_GATTS_EVT_WRITE: {
+                /* There are 2 use case here: Values being updated & CCCD (indicate/notify) enabled */
+
+                /* 1.) Handle CCCD changes */
+                handle_value = gattsEventP->params.write.handle;
+                int characteristicIndex = resolveCCCDHandleToCharIndex(handle_value);
+                if ((characteristicIndex != -1) &&
+                    (p_characteristics[characteristicIndex]->getProperties() &
+                        (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY))) {
+
+                    uint16_t cccd_value = (gattsEventP->params.write.data[1] << 8) | gattsEventP->params.write.data[0]; /* Little Endian but M0 may be mis-aligned */
+
+                    if (((p_characteristics[characteristicIndex]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE) && (cccd_value & BLE_GATT_HVX_INDICATION)) ||
+                        ((p_characteristics[characteristicIndex]->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) && (cccd_value & BLE_GATT_HVX_NOTIFICATION))) {
+                        eventType = GattServerEvents::GATT_EVENT_UPDATES_ENABLED;
+                    } else {
+                        eventType = GattServerEvents::GATT_EVENT_UPDATES_DISABLED;
+                    }
+
+                    handleEvent(eventType, p_characteristics[characteristicIndex]->getValueHandle());
+                    return;
+                }
+
+                /* 2.) Changes to the characteristic value will be handled with other events below */
+                eventType = GattServerEvents::GATT_EVENT_DATA_WRITTEN;
+            }
+            break;
+
+        case BLE_GATTS_EVT_HVC:
+            /* Indication confirmation received */
+            eventType    = GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED;
+            handle_value = gattsEventP->params.hvc.handle;
+            break;
+
+        case BLE_EVT_TX_COMPLETE: {
+            handleDataSentEvent(p_ble_evt->evt.common_evt.params.tx_complete.count);
+            return;
+        }
+
+        case BLE_GATTS_EVT_SYS_ATTR_MISSING:
+            sd_ble_gatts_sys_attr_set(gattsEventP->conn_handle, NULL, 0, 0);
+            return;
+
+        case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
+            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;
+            }
+            break;
+
+        default:
+            return;
+    }
+
+    int characteristicIndex = resolveValueHandleToCharIndex(handle_value);
+    if (characteristicIndex == -1) {
+        return;
+    }
+
+    /* Find index (charHandle) in the pool */
+    switch (eventType) {
+        case GattServerEvents::GATT_EVENT_DATA_WRITTEN: {
+            GattWriteCallbackParams cbParams = {
+                .connHandle = gattsEventP->conn_handle,
+                .handle     = handle_value,
+                .writeOp    = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.write.op),
+                .offset     = gattsEventP->params.write.offset,
+                .len        = gattsEventP->params.write.len,
+                .data       = gattsEventP->params.write.data
+            };
+            handleDataWrittenEvent(&cbParams);
+            break;
+        }
+        case GattServerEvents::GATT_EVENT_WRITE_AUTHORIZATION_REQ: {
+            GattWriteAuthCallbackParams cbParams = {
+                .connHandle = gattsEventP->conn_handle,
+                .handle     = handle_value,
+                .offset     = gattsEventP->params.authorize_request.request.write.offset,
+                .len        = gattsEventP->params.authorize_request.request.write.len,
+                .data       = gattsEventP->params.authorize_request.request.write.data,
+                .authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS /* the callback handler must leave this member
+                                                                   * set to AUTH_CALLBACK_REPLY_SUCCESS if the client
+                                                                   * request is to proceed. */
+            };
+            ble_gatts_rw_authorize_reply_params_t reply = {
+                .type = BLE_GATTS_AUTHORIZE_TYPE_WRITE,
+                .params = {
+                    .write = {
+                        .gatt_status = p_characteristics[characteristicIndex]->authorizeWrite(&cbParams)
+                    }
+                }
+            };
+            sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
+
+            /*
+             * If write-authorization is enabled for a characteristic,
+             * AUTHORIZATION_REQ event (if replied with true) is *not*
+             * followed by another DATA_WRITTEN event; so we still need
+             * to invoke handleDataWritten(), much the same as we would
+             * have done if write-authorization had not been enabled.
+             */
+            if (reply.params.write.gatt_status == BLE_GATT_STATUS_SUCCESS) {
+                GattWriteCallbackParams cbParams = {
+                    .connHandle = gattsEventP->conn_handle,
+                    .handle     = handle_value,
+                    .writeOp    = static_cast<GattWriteCallbackParams::WriteOp_t>(gattsEventP->params.authorize_request.request.write.op),
+                    .offset     = gattsEventP->params.authorize_request.request.write.offset,
+                    .len        = gattsEventP->params.authorize_request.request.write.len,
+                    .data       = gattsEventP->params.authorize_request.request.write.data,
+                };
+                handleDataWrittenEvent(&cbParams);
+            }
+            break;
+        }
+        case GattServerEvents::GATT_EVENT_READ_AUTHORIZATION_REQ: {
+            GattReadAuthCallbackParams cbParams = {
+                .connHandle         = gattsEventP->conn_handle,
+                .handle             = handle_value,
+                .offset             = gattsEventP->params.authorize_request.request.read.offset,
+                .len                = 0,
+                .data               = NULL,
+                .authorizationReply = AUTH_CALLBACK_REPLY_SUCCESS /* the callback handler must leave this member
+                                                                   * set to AUTH_CALLBACK_REPLY_SUCCESS if the client
+                                                                   * request is to proceed. */
+            };
+
+            ble_gatts_rw_authorize_reply_params_t reply = {
+                .type = BLE_GATTS_AUTHORIZE_TYPE_READ,
+                .params = {
+                    .read = {
+                        .gatt_status = p_characteristics[characteristicIndex]->authorizeRead(&cbParams)
+                    }
+                }
+            };
+
+            if (cbParams.authorizationReply == BLE_GATT_STATUS_SUCCESS) {
+                if (cbParams.data != NULL) {
+                    reply.params.read.update = 1;
+                    reply.params.read.offset = cbParams.offset;
+                    reply.params.read.len    = cbParams.len;
+                    reply.params.read.p_data = cbParams.data;
+                }
+            }
+
+            sd_ble_gatts_rw_authorize_reply(gattsEventP->conn_handle, &reply);
+            break;
+        }
+
+        default:
+            handleEvent(eventType, handle_value);
+            break;
+    }
 }
\ No newline at end of file