Commit graph

139 commits

Author SHA1 Message Date
Andres Amaya Garcia 0bcc2e96c9 Modify shutdown due to BLE API change
The module is updated to comply with the changes to BLE API regarding correct
shutdown functionality. The following changes are introduced to ble-nrf51822:

* Calls to the old static function shutdown in Gap, GattClient, GattServer and
SecurityManager are removed.
* The cleanup function in Gap, GattClient, GattServer and SecurityManager is
renamed to `reset()` and made public.
* The static references inside nRF5xGap, nRF5xGattClient, nRF5xGattServer and
nRF5xSecurityManager to objects of their own class are moved to nRF5xn.
* The static getInstance accessors in nRF5xGap, nRF5xGattClient,
nRF5xGattServer and nRF5xSecurityManager are removed and their functionality is
moved to the implemented virtual accessors in nRF5xn i.e. getGap(),
getGattClient, etc.
* A static function Instance is added to nRF5xn class to make the transport
object accessible across the module.
2015-12-14 15:15:35 +00:00
Vincent Coubard eb5ca3806d Add a function to change the lastHandle of a discovered characteristic 2015-12-14 15:04:56 +00:00
Vincent Coubard 7e784e0e0c Merge branch 'develop' of into characteristicDescriptorDiscovery 2015-12-14 11:57:57 +00:00
Andres Amaya Garcia 0429643609 Fix comment typo 2015-12-11 18:19:10 +00:00
Andres Amaya Garcia 7bf81e7edb Improve shutdown to clear BLE API and not just SD
Improve the shutdown functionality, such that a call to ble.shutdown() from
the user application clears the API and nRF5x state and NOT only the
SoftDevice. To achieve this the following changes are introduced:

* Add a protected member cleanup() to nRF5xGap, nRF5xGattClient,
nRF5xGattServer, nRF5xSecurityManager and nRF5xServiceDiscovery.
* Modify the shutdown() implementation in nRF5xn such that it also calls the
static member shutdown() exposed by the BLE API in Gap.h, SecurityManager.h,
GattClient.h and GattServer.h.
* Modify nRF5xGattClient, nRF5xGattServer and nRF5xSecurityManager
classes so that they dynamically create their respective objects only if
needed. Previously the GattClient, GattServer and SecurityManager objects were
declared as static, which means that they were always present even though they
were not always needed. This increases memory consumption unnecessarily.
Furthermore, pointers to the object instances are stored in static members of
the classes as specified by the BLE API base classes. This ensures that
calls to shutdown do not require calls to getInstance() functions that would
otherwise result in undesired memory allocations.
* nRF5xGap object is always needed, so this remains allocated statically. But
the reference in Gap is pointed to this object.

The shutdown procedure is as follows:

1. The user calls ble.shutdown() which executes the code in nRF5xn::shutdown()
1. The SoftDevice is shutdown
1. The static members of Gap.h, SecurityManager.h, GattClient.h and
GattServer.h are called to clean up their own state.

If at any point an error occur during the last step, BLE_ERROR_INVALID_STATE is
2015-12-11 17:56:57 +00:00
Marcus Chang b2cb566312 Added SecurityManager::setLinkSecurity call for elevating security settings on a particular connection. 2015-12-10 15:09:00 +00:00
Rohit Grover 6a0c605d44 Merge pull request pull/83 i.e. commit '6507b4a50ce849db7e5e541dfd03accfc38f1b6f' into develop 2015-12-08 13:58:32 +00:00
Rohit Grover dada1de8fc Merge pull request #82 from marcuschangarm/endian
WIP: UUID endian change
2015-12-08 11:18:44 +00:00
Marcus Chang 59fa852bea Added bit order parameter to UUID construction. 2015-12-07 13:35:45 +00:00
Andres Amaya Garcia 6507b4a50c Add -Wno-unused-function to supress-warnings.cmake 2015-12-02 16:13:18 +00:00
Marcus Chang e554200f5e Removed endian conversion in custom helper functions. 2015-12-02 15:39:06 +00:00
Rohit Grover 264a4ae4d7 Merge branch 'split_nordic_sdk' of into LiyouZhou-split_nordic_sdk 2015-12-02 15:21:35 +00:00
Rohit Grover d7834bc274 replace some loops with memcpy() 2015-12-02 13:09:33 +00:00
Rohit Grover 178931fee8 Merge branch 'uuid' of into marcuschangarm-uuid 2015-12-02 13:03:36 +00:00
Andres Amaya Garcia 4b3a1c85b5 Allow GattAttributes to have fixed length
Previously the concepts of initLength and lenth were clearly separated.
However, this was at the cost of registering all characteristics in the
SoftDevice as having variable length. Clearly, this is not the desired
behaviour. Therefore, an additional field '_hasVariableLen' is added to the
GattAttribute to address the problem. Also, the GattAttribute and
GattCharacteristic constructors have been modified to take a boolean that
sets '_hasVariableLen'.

**NOTE:** Changes to this module will cause projects to fail the build stage
if changes to the BLE_API are not published first.
2015-12-02 10:41:01 +00:00
Marcus Chang 2725247316 Fixed endianness bug in nRF5xServiceDiscovery::processDiscoverUUIDResponse to be consistent with BLE API. 2015-12-01 18:03:38 +00:00
Marcus Chang 314d3d449c Fixed bug in nRF5xGap.setAddress where random adresses where not set properly. 2015-12-01 14:10:20 +00:00
Liyou Zhou 52eabeaf95 Remove nordic sdk files from this module, they are now in
2015-12-01 11:42:23 +00:00
Andres Amaya Garcia 3fb32e167f Separate concept of minlen and len for BLE chars
In previous versions of BLE_API the GattCharacteristic initLen parameter is
named minLen as well. When the characteristic is committed to the SoftDevice
the value of initial length is also used as the minimum length of the
characteristic value. Furthermore, the test (max_length == min_length) is used
to determine whether the characteristic value has variable length. This is
slightly confusing and also causes problems if the user wishes to use a
characteristic with variable length but the initial lenght is equal to max

To solve this problem the characteristic is now always committed to the
SoftDevice as variable. Furthermore, the API only maintains the current lenght
and the max length i.e. the field initialLen in the GattAttribute is removed.
In nRF5xGattServer all calls to getInitialLength() are removed and replaced
with getLength().

* This change requires updates to ble.
* Ideally we would like the characteristics to be declared as 'variable' only
when necessary, but this requires changing the signature of the
GattCharacteristic and GattAttribute constructors. Therefore, it will be part
of a separate pull request.
2015-11-27 17:25:58 +00:00
Rohit Grover 27c5043fcc Merge pull request #77 from LiyouZhou/update-to-sdk-8.1
Update to sdk 8.1
2015-11-27 10:52:18 +00:00
Andres Amaya Garcia 167ddd63ab Execute radio notification in low priority context
The ble-nrf51822 implementation of the BLE API executes callbacks for radio
notification events at very high priority. This functionality is replaced by
executing the radio notification callback at a lower priority. When using
mbed OS the callback is posted through minar. In mbed classic the callback is
executed directly, but from a lower priority. Note that minar or callback
execution in mbed classic could not be posted/generated directly from the
radio notification handler because this causes race conditions that may lead
to a hard-fault. Alternatively, a Timeout was used to post the callback in
another context with lower priority.
2015-11-26 10:56:17 +00:00
Liyou Zhou 7d95b66f11 Rename due to importing mbed.h and requiring cpp libraries. 2015-11-24 18:41:19 +00:00
Liyou Zhou a583502f2b Update files to nrf51 sdk 8.1.0 2015-11-24 15:01:15 +00:00
Liyou Zhou af14327c85 Change folder structure to fit new sdk
Reverted some unnecessary changes.
2015-11-24 14:53:04 +00:00
Vincent Coubard b795c29150 Terminate pending discoveries when a connection end.
Add accessor for ServiceDiscovery and CharacteristicDescriptorDiscover in

Remove friend relationship with bleGattcEventHandler
2015-11-19 08:31:43 +00:00
Vincent Coubard c778aa8aa3 Rename characteristic descriptors discovery activity and termination function 2015-11-18 15:53:34 +00:00
Liyou Zhou dfb6ac292f Remove magic hash defines which are used in nrf51-sdk
nrf51-sdk files are modified to include these defines.
2015-11-18 14:25:10 +00:00
Liyou Zhou 348c323d27 Take modification out of the nordic sdk files
and put them into ARM written files.
2015-11-18 14:25:10 +00:00
Vincent Coubard cc0cf3dfa7 Merge remote-tracking branch 'origin/develop' into characteristicDescriptorDiscovery 2015-11-18 12:50:22 +00:00
Vincent Coubard 8bd7bdfa88 Add ARM header into source/nRF5xGattClient.h.
Use const references for passing characteristic discovery callbacks
Fix a bug in btle_discovery.cpp, the discovered descriptors were captured
by value instead of reference.
2015-11-18 12:45:43 +00:00
Vincent Coubard dc2dfb0a95 Add status parameter in terminateCharacteristicDiscovery function.
Fix terminate discovery (the replacement of the discovery was done after
the call to terminate).
When searching for a running discovery, dismiss results where the
characteristic is equal to the default characteristic value
Add Discovery::operator!=
Add support of DiscoveredCharacteristic last handle in the characteristic
discovery process
2015-11-17 14:20:17 +00:00
Vincent Coubard cdd5b92193 Relaunch discovery operation when gatt event status is
Report error in the Termination callback
2015-11-17 10:24:57 +00:00
Rohit Grover 7de2b7162f minor rewording of the comment introduced by the previous pull request 2015-11-16 09:41:27 +00:00
Vincent Coubard e15d59a758 Add Characteristic Descriptor Discovery implementation 2015-11-13 14:53:46 +00:00
Andres Amaya Garcia f8b3f1340f Post radio notification callback through minar
The ble-nrf51822 implementation of the BLE API generated callbacks for radio
notification events without using the minar scheduler and at very high
priority. This functionality is replaced by posting events through minar
when YOTTA_CFG_MBED_OS is defined. Note that minar could not be used directly
to post callbacks because radio notification events are handled at very high
priority, which caused a hard-fault when minar tries to enter a critical
section. Alternatively, a Timeout was used to post the callback in another
context with lower priority.
2015-11-13 14:51:36 +00:00
Andres Amaya Garcia c8cb3aeee3 Change assembly sequence to avoid changing APSR
Change assembly sequence that starts the Nordic bootloader to remove
MOV instruction before cheks of IPSR. The MOV might be translated into a ADDS
that could change the APSR and cause a wrong branch to be taken.
2015-11-13 10:36:02 +00:00
Andres Amaya Garcia 90f6c9714f Fix assembly sequence to start bootloader in GCC
The assemble sequence within an mbedOS application that starts the nordic
bootloader was being modified by the compiler. The result is that DFU enabled
applications could never start the bootloader correctly. This is because the
GCC compiler was translating a MOV instruction into a ADDS, which sets the
conditional flags in APSR before a conditional branch was executed. The result
of the incorrect branch caused the program to believe that it was in interrupt
mode when this was not the case.
2015-11-13 10:35:46 +00:00
Marcus Chang 55aef3bf24 Added watchdog header file from Nordic SDK 8.1 2015-11-07 12:27:34 +00:00
Rohit Grover 6b763c8709 bring in the latest changes for BLE::init() where we allow <object, member> tuples for init callback. 2015-11-03 12:41:08 +00:00
Vincent Coubard f0d521f04c Ensure that the initialization flags is set to false if the BLE stack is
shutdown properly.
2015-11-02 17:04:47 +00:00
Rohit Grover c5dc7e52a6 add init guards for some top level APIs 2015-10-30 10:27:18 +00:00
Rohit Grover 20b07e38bc update init() to match the chagnes around initializationCompleteCallback.
refer to and
2015-10-30 10:26:37 +00:00
Andres Amaya Garcia 97a65815ed Introduced changes for memory savings
Moved GattSecurityManager and GattClient to be allocated dynamically and
reduced the size of some arrays to increase memory savings.
2015-10-29 11:39:00 +00:00
Marcus Chang 6082c76ab5 When connecting, if no scanning parameters are passed, use values from Gap parent. 2015-10-16 11:44:03 +01:00
Rohit Grover 816f4559f1 white space diffs; convert tabs to spaces 2015-10-13 12:54:46 +01:00
Rohit Grover 031ae20002 Merge branch 'patch-1' of into Timmmm-patch-1 2015-10-13 12:51:08 +01:00
Jean-Philippe Brucker eab6631cb6 Update S110 detection macros again
The mbed SDK actually prefixes all labels from with "TARGET_".
Update our detection macros accordingly.
2015-10-05 18:05:55 +01:00
Tim 4af5d03cd5 Error check number of characteristics
Currently it just blindly writes beyond the end of the array, leading to impossible-to-find bugs.

It doesn't help that the limit on the number of characteristics doesn't seem to be documented anywhere.
2015-09-29 15:04:59 +01:00
Rohit Grover ee2b3dfe4a nRF5xGattServer::write()L remember to setup returnValue to BLE_STACK_BUSY in the case of an unforseen error. 2015-09-25 14:19:49 +01:00
Rohit Grover 167f304b68 minor cleanup to Fabien's pull request; remove the un-necessary gapConnectionHandle 2015-09-02 09:17:02 +01:00
Rohit Grover 887426ad0b minor white space diff 2015-08-28 14:01:52 +01:00
Rohit Grover b0bf2db253 Merge branch 'master' of into fabiencomte-master2 2015-08-28 13:51:10 +01:00
Fabien Comte 6cdb6f161f rgrover patch fixed 2015-08-28 14:44:34 +02:00
Rohit Grover 4fa43078db initialize all members of gattc_write_params_t in GattClient::write().
This avoids some compiler warnings about un-initialized members.
2015-08-25 10:34:01 +01:00
Rohit Grover 6a5d142f03 initialize the member authorizationReply when posting authorization callbacks to the application.
This is a nice-to-do.
2015-08-25 10:34:01 +01:00
Rohit Grover 94e699bbe8 supress warnings for unused paramters and missing initializers for the Nordic code. 2015-08-25 10:34:01 +01:00
Jean-Philippe Brucker dc1d7893c4 Update S110 detection macros
Those macros are defined by mbed SDK in They changed from
MCU_NORDIC_xxx_S110 to MCU_NRF51_xxx_S110. Update the #ifdefs accordingly.
2015-08-24 18:09:28 +01:00
Rohit Grover 74c707687b setup an event handler to post BLE events to Minar.
Stack and system events now get scheduled through minar.
2015-08-13 11:01:50 +01:00
Rohit Grover 6d1b1d94f6 white space diffs. 2015-08-12 10:55:44 +01:00
Rohit Grover 1da1aa8622 fix #39: have a single call to SOFTDEVICE_HANDLER_INIT() to remove duplication of BLE_EVT_BUFFER. 2015-08-11 14:42:53 +01:00
Rohit Grover c28d0eea88 fix #11. Remove include for missing header. 2015-08-11 14:35:20 +01:00
Rohit Grover 2c01109786 Merge pull request #38 from jpbrucker/s110_compat
Disable GattClient features when using S110 SoftDevice
2015-08-11 14:21:33 +01:00
Rohit Grover 2d149d36fb Merge branch 'GattCB_conn_handle' of into jpbrucker-GattCB_conn_handle 2015-08-11 14:08:07 +01:00
Jean-Philippe Brucker 3eabc779a0 Disable GattClient features when using S110 SoftDevice
S110 compatibility is already present, but this patch adds proper handling
of observer/central related features:
* Gap::startScan will return BLE_ERRROR_NOT_IMPLEMENTED (instead of
* nRF5xGattClient uses the default GattClient implementation when S110 is
  in use. All if its methods return NOT_IMPLEMENTED.

Example: for an application that acts as both a central and a peripheral,
using S110 will make the call return
BLE_ERROR_NOT_IMPLEMENTED, and advertisement features will continue
running normally.
In addition, with GCC, this patch will free 344 bytes of RAM and 2504
bytes of flash.
2015-08-11 13:02:34 +01:00
Jean-Philippe Brucker 73147b41c2 Fill connection handle in Gatt callbacks parameters 2015-08-11 11:31:20 +01:00
Rohit Grover e699db6a54 nRFGattClient: move the allocation of the singleton to within the getInstance() method.
This saves memory when getInstance() isn't used.
2015-08-11 10:32:33 +01:00
Joshua Slater 8830c07558 getAppearance now checks for correct success code from sd_ble_gap_appearance_get 2015-08-10 15:11:33 +01:00
Rohit Grover bf25a5a4c4 rename to getIntervalInADVUnits() 2015-08-10 15:11:18 +01:00
Joshua Slater 781dcbdcfd changed getInterval to getIntervalInAdvUnits to support changes in GapAdvertisingParams.h 2015-08-10 15:08:51 +01:00
Joshua Slater 110db4c514 Changed Gap:: to GapAdvertisingParams:: because of change in BLE 2015-08-06 10:50:53 +01:00
Rohit Grover 692d7e08e8 minor cosmetic change to the previous commit. 2015-08-05 12:47:41 +01:00
Rohit Grover 27cd45a37c Merge pull request #32 from jpbrucker/dynamic_clksrc
Select the clock source dynamically on SoftDevice initialisation
2015-08-05 12:35:28 +01:00
Jean-Philippe Brucker b22c2e826f Select the clock source dynamically on SoftDevice initialisation
Instead of relying on build macros to know which oscillator we're
supposedly using, check the value of LFCLKSRC register. This way, we can
trust mbed's init code to fallback on the internal clock if the user
specified a wrong target.
This change, along with the mbed patch that selects clock source
dynamically, will allow lots of application to still run and provide
FOTA, when the wrong Nordic platform is specified.

Signed-off-by: Jean-Philippe Brucker <>
2015-08-03 18:56:22 +01:00
Rohit Grover 71d6c4148f fix #29: add mention of version number to the version string. 2015-07-29 12:12:29 +01:00
Rohit Grover 6cdf4e12e0 fix #29: support getVersion for v8 of the softdevice. 2015-07-29 12:08:55 +01:00
Jean-Philippe Brucker 20f4417724 Add SoftDevice s110 compatibility
This patch adds the ability to use the API with the s110 SoftDevice.
Only a minor change is needed so far, to support the absence of roles in
2015-07-22 11:29:25 +01:00
Jean-Philippe Brucker 34977aea1c Add S110 compatibility in S130 headers 2015-07-22 11:29:25 +01:00
Rohit Grover 553132b406 add support to handle radio-notification event as a FuncionPointer so that we can have <object, member> pairs for callbacks. 2015-07-21 11:34:36 +01:00
Rohit Grover df2efa5adb white space diffs. 2015-07-13 07:51:07 +01:00
Rohit Grover c0a8c6b544 Merge branch 'master' of into afernandes 2015-07-13 07:49:07 +01:00
Andrew Fernandes 2e68655044 nRF51ServiceDiscovery should be able to match short AND long UUIDs. 2015-07-11 15:07:00 -04:00
Andrew Fernandes 4ec44d75e3 Change DiscoveredCharacteristic API to return long or short UUIDs. 2015-07-10 11:51:09 -04:00
Rohit Grover 9606130953 Merge branch 'master' of into adfernandes-master 2015-07-07 08:14:15 +01:00
Andrew Fernandes b743df2a51 Remove unnecessary 'compiler_abstraction.h' to get rid of duplicate '__ASM' warning. 2015-07-06 15:19:04 -04:00
Rohit Grover 0eb58d86f5 rename nRF51... to nRF5x...
This prepares us to support nRF52.
2015-07-06 14:18:01 +01:00
Rohit Grover 57c99a5ac3 fix #22: add GattClient API for handling HVX Events (notifications and indications). 2015-07-06 09:23:17 +01:00
Rohit Grover 5370a5097e relocating the tree under ble-nrf51822/btle 2015-07-02 13:32:19 +01:00
Rohit Grover 094e94b9f8 Merge branch 'master' of into autopulated-master 2015-07-02 12:56:29 +01:00
James Crosby 488e24620d restructure to yotta module, with a few tweaks to get things building 2015-06-23 18:15:41 +01:00