Commit Graph

82 Commits (9218e647e0868ae68608aab18b53c6c417fe5240)

Author SHA1 Message Date
Joe Finney 5231b5f526 First cut at a build without a global MicroBit singleton 2016-03-10 12:02:13 +00:00
Joe Finney 2f4e542fee Merge branch 'radio-recv-bug-94' 2016-02-26 16:33:28 +00:00
Joe Finney caa4924336 microbit: Added validation case in MicroBitRadioDatagram::recv()
Introduced missed validation case in MicroBitRadioDatagram::recv().
Added PacketBuffer::EmptyPacket as a NULL reference.
2016-02-26 16:27:13 +00:00
James Devine e115e5af8d microbit-dal: BUGFIX maintain cccd state when service changed fails
Previously, we would rely on service changed to complete successfully
to signify a successful cccd state restore.

However, android doesn’t register for service_changed notifications,
and as a result sd_ble_gatts_service_changed always returns an error.

This meant that cccds would be erased when the complete flag was not
one, which would have been all the time.
2016-02-26 15:45:15 +00:00
James Devine 5505fc6687 microbit-dal: fixed android waiting after DFU mode initiated
This commit introduces a wait_ms before entering DFU mode to allow soft
device to communicate to an android handset that the current connection
should be terminated.
2016-02-26 15:24:35 +00:00
James Devine 3019e34dd9 microbit: BLE fixes
This commit addresses a number of outstanding issues:

* whitelisting behaviour, form the nrf51-sdk, where an address and an
irk were added to the whitelist

* bond management bugs, from the nrf51-sdk, where one device would
replace another.

closes #57, closes #56, closes #58, closes #59, closes #44, closes #60
2016-02-26 15:21:30 +00:00
Joe Finney 6900bd8415 microbit: BUGFIX supporting repairing of the same device #2829
Re-pairing the same BLE device under SoftDevice 8.0 Nordic SDK 10 appears to
add a second entry to the bonding table when private resolvable addresses are
used by the central device. This adversely affects whitelisting, as only the
first added matching entry will be succesfully added to the whitelist. i.e. A
central device will no longer be able to connect to a micro:bit after pairing
a second time as the older bond will take prescedence.

Althoguh reported to Nordic, a long term fix is not immediately forthcoming.
This patch applies a workaround, by simply reversing the order of the
whitelist before use. As the list is maintained in the order of insertion,
reversing the list guarantees that the entry added to the whitelist will be
the most recently bonded one for any given peer.
2016-02-12 18:54:19 +00:00
Joe Finney 30ec004dc7 WIP: Working IOS pairing with service changed notification
n.b. changes to microBitConfig may need reverting
2016-02-11 21:58:07 +00:00
Joe Finney 3b25fe81ac WIP: Updates to IOS support 2016-02-10 18:12:31 +00:00
Joe Finney a61113f950 Merge branch 'rssi' 2016-02-09 01:09:36 +00:00
Joe Finney 2f6d405e81 microbit: Introduced managed type for packet buffers.
Introduce PacketBuffer as a mutable reference counted type Radio operations
Updated send() and recv() to use PacketBuffer rather than ManagedString
2016-02-09 01:04:57 +00:00
Joe Finney dda8598513 microbit: Added support for configurable GATT table size
Updates to MicroBitConfig options and initialisaiton code of the BLE stack to
allow Soft Device's GATT table to be of a given size. If this size is smaller
then the default, the runtime will reclaim that that memory as heap storage.
2016-02-08 00:57:20 +00:00
Joe Finney 8e3e061bec microbit: BUGFIX Fixed incorrect bond table entry count
The nordic implementation of the mbed whitelist API introduces entries into
the table that are not bonds. This patch corrects an assumption in
microbit-dal that the number of entries in the bond table table corellates
with the number of bonds.
2016-02-07 19:59:56 +00:00
Joe Finney 2e6459404b microbit: Added configuration to enable/disable BLE security
The BLE security options mandated for child protection can be highly
detrimental to the development process for new BLE services. This patch
introduces a configuration option to disable BLE security for this purpose.
Default BLE security settings remain unchanged.
2016-02-06 23:34:10 +00:00
James Devine af13c940c1 microbit: add RSSI to MicroBitRadio
Added the ability to capture the RSSI value, and an accessor and
mutator for the last received RSSI value.
2016-02-04 03:45:57 +00:00
James Devine ffc217e7ac microbit: fixed formatting issues in MicroBitRadio
Removed trailing whitespace.
2016-02-04 03:44:25 +00:00
Joe Finney 9d039fd9be microbit: BUGFIX Corrected length calculation for validation case
Incorreclty calculated payload bug also addressed here.
2016-02-03 14:41:45 +00:00
Joe Finney 5cb265c158 microbit: BUGFIX: Length field of datagram receive now correct
Datagram receive code incorrectly calculated the payload length, resulting in
packets being delivered to applications that were two bytes shorter than they
should be.
2016-02-03 14:35:12 +00:00
Joe Finney 5e7334b0bf microbit: integrated persistent storage for CCCD data.
There is an issue (
whereby CCCD data is required to be persisted through device resets.

This commit integrates the new MicroBitStorage class, and persistently
stores this information in flash.

P.S. what a long night!
2016-02-02 21:24:40 +00:00
Joe Finney e983b80b0b Merge branch 'master' into ble-bondtablepurge 2016-02-01 22:50:05 +00:00
Joe Finney e7132b0d13 microbit: Change to BLE bonding table replacement policy
Previous revisions of microbit-dal would handle the case of a bonding request
when the bond table was full by attempting to purge the bonding table on
demand. This suffered two flaws:

 1) Nordic's device manager does not support the purging of the bonding table
while a connection is active (including a pairing request).

 2) Some devices (e.g. Android 4.4.2 take two entries in the bonding table
when paired), thus making predictions of how 'full' the table is challenging.

This patch employs a simpler replacement policy. The maximum size of the bond
table has been increased to 6 (from 4). However, if the bond table contains 4
or more entries when entering pairing mode it will be purged in advance of any
pairing requetss being initiated.
2016-02-01 22:30:03 +00:00
James Devine 97c49d3279 Merge pull request #87 from lancaster-university/broadcast-radio
Adding Multicast peer-to-peer radio support MicroBitRadio!
2016-02-01 21:50:54 +00:00
Joe Finney 9026ca6e98 microbit: Optimisation of BLE mutex.
The BLE stack locks out the CPU for long periods of time when necessary. This
can be alleviated by eans of a flag that release the CPU between radio events.

This can cause issues from applications with tighter timing requirements.
This patch only enables this MUTEX when a BLE connection is active, rather
than automatically at startup. Therefore, application that do not actively use
BLE will not suffer this penalty.
2016-02-01 19:25:07 +00:00
Joe Finney 6838b38fc1 microbit: Remove redundant characteristics in BLE DeviceInformationService
The MANUFACTURER and HARDWARE_REVISION fields from this standard service have
been removed, as they carried no useful information.
2016-02-01 18:59:48 +00:00
Joe Finney 8bec31fe76 microbit: Additional validation on MicroBitRadio methods
MicroBitRadio methods that touch internal RADIO registers now ensure that
the BLE stack is not running before changing such registers.
2016-02-01 18:19:02 +00:00
Joe Finney d7aa95e867 microbit: minor updates to consistently use the MICROBIT_RADIO_HEADER_SIZE constant 2016-02-01 18:05:02 +00:00
Joe Finney 12c9ed246a microbit: Whitespace fixes 2016-02-01 17:54:33 +00:00
Joe Finney 420a73673d microbit: rename of MicroBitRadioEvent methods to align with MessageBus naming conventions. 2016-02-01 17:43:17 +00:00
Joe Finney d9d2343ab6 microbit: Add Multicast peer-to-peer radio capability
Integration of new radio mode that permits simple local area multicast communication
directly between micro:bits using the device's on board radio hardware.

It should be noted that this implementation build directly on the nrf51822
hardware. It is not a BLE protocol, and must (currently) be operated with BLE

A standard on the wire configuration is defined, to promote future
interoperability between projects and languages. A lightweight
packet format is also defined and adhered to, so as to promote future
extensibility without sacrificing compatibility. The notion of groups is also
introduced, that enable multiple groups of children to work in the same area
without compromising each other's projects.

In adition to a low level packet radio driver, two higher level protocols are
defined that allow simple user datagram communication between micro:bits and
an EventBus protocol that allows the micro:bit's MessageBus to be extended to
other micro:bits.
2016-02-01 04:29:27 +00:00
Joe Finney e3a23988f6 microbit: Promote constants in MicroBitBLEManager to .h file
Moved configuration constants from .cpp to .h file, so that they can be reused
more easily from other code, such as the broadcast radio code.
2016-02-01 04:25:51 +00:00
Joe Finney e3fdc5a290 microbit: Support for bonding only available in pairing mode
Update to BLE initialisation code. Ability to initiate pairing is now
restricted to pairing mode.
2016-01-25 21:05:15 +00:00
Joe Finney 99d7231945 microbit: Persistance of BLE Service Chnaged metadata
BLE maintains metadata on its characterisitics, some of which record whether
or not a central device (phone/tablet) wishes to receive notifications when a
given BLE characteristic changes value. One such characterisitic is used as
part of a core BLE service to indicate of the BLE profile of a device has

IOS is heavily reliant on this feature, and expects the state of this metadata
to be persistent across device reboots. This patch ensures that this metadata
is always set to allow Service Changed indications to be propagated to central
2016-01-25 21:05:13 +00:00
Joe Finney 6a7436e5c7 Merge pull request #48 from remay/quiet-gcc-build
Tidy up gcc -Wall fixes

Thanks @remay!
2016-01-25 20:55:37 +00:00
Joe Finney a4c0915fff microbit: BUGFIX Prevent BLE Magnetometer service from initiating compass

MicroBitCompass initiates a calibration procedure on demand if a heading is
requested from an uncalibrated device. The BLE MagnetometerService also
attempts to retrieve a heading periodically, but it is not good behaviour to
initiate calibration as a response to this.

This patch introduces a check such that the BLE MagnetometerService will only
attempt to read heading data from a previously calibrated compass.
2016-01-19 00:32:02 +00:00
Joe Finney 13eb3c07e7 microbit: Add explicit service changed notification
BLE central devices (such as mobile phones/tablets) are permitted to cache the
list of services and characteristics provided by a BLE peripheral such as the
micro:bit. This was causing compatibility problems with IOS during FOTA
flashing, as the the list of BLE services may change after flashing.
2016-01-17 00:23:00 +00:00
Joe Finney 1c9ae30d1c microbit: Added basic bond table management
The Nordic BLE stack contains a fixed size bond table - a list of devices that
have paired with our device (in the case the micro:bit). The default mbed
wrapper around the nordic stack does not account for the case where the bond
table is full.

This patch implements basic bounds checking within the MicroBitBLEManager so
that this table cannot overrun. If a new device attempts to pair when the bond
table is full, the table is emptied prior to completing bonding.
2016-01-16 21:05:46 +00:00
Joe Finney e754ecf3aa microbit: Setting of default BLE transmission power level
Added configuration option in MicroBitConfig to allow the default power level
to be defined. Based on experiments undertaken by the BBC and subsequent policies defined by
the BBC's child protection panel, to is set by default it's lowest level (0),
in order to protect children's privacy.

It should be noted that this is 30dB below the device's default setting, so will
inevitably leave the device more susceptible to interference, and therefore
significantly reduce the reliability of the device. This will likely present
itself through increased packet loss, reduced thorughout, lost data and
connection drop outs. The normal BLE power level on commercial devices
translates to  power level of 6.

The author has witnessed an inability to connect to a micro:bit from a
distance of 40cm under domestic conditions using a Samsung S5 mini
running Android 4.4.2.
2016-01-16 17:29:46 +00:00
Joe Finney 07852b0cd6 microbit: Added support for BLE transmission power control
Added new method to MicroBitBLEManager to allow the radio transmission power
to be controlled. Provides a linear power level scale in the range 0..7.
2016-01-16 17:07:20 +00:00
Joe Finney f17151a0bf microbit: Added optional support for whitelisting and limited advertising
Added MicroBitConfig.h option to enable/disable whitelisting
Added MicroBitConfig.h option to enable/disable limited period advertising
Added support for limited period advertising
Minor code cleanups
2016-01-16 16:54:58 +00:00
Robert May 098a2378e3 Merge lancaster-university/master and silence warnings. 2016-01-13 20:51:49 +01:00
Joe Finney 90cf35a38a WIP: compiling but untested first cut at whitelisting code 2016-01-13 00:20:37 +00:00
James Devine 6b1e020392 microbit: formatting corrections
There was some incorrect tabulation in a few lines of this file, this has now been corrected.
2016-01-12 20:50:42 +00:00
Joe Finney 55601f3e0e Merge branch 'master' into secure-ble 2016-01-05 01:25:52 +00:00
Joe Finney e1f75b2c4c microbit: Added read capability to MicroBitDFUService::ControlPoint characteristic
Whilst Android devices permit explicit initiation of the BLE pairing process,
IOS based devices are only  capable of implicit initiation of pairing based
on accessing a protected characteristic. Adding read capability to the
ControlPoint characteristic provides a safe and convenient way for IOS devices
to initiate pairing.
2016-01-04 23:41:22 +00:00
Joe Finney 7a71b58bd4 microbit: Revert explicit use of public addresses in pairing mode 2016-01-04 23:06:48 +00:00
Joe Finney 203246b975 WIP: Revert to public addresses pending further debug 2015-12-18 12:27:08 +00:00
Joe Finney c7ea0af6fe WIP: Analysing correct use of private resolvable addresses 2015-12-17 14:27:57 +00:00
Joe Finney 14831ac9b9 Updates to BLE 2.1.11 / ble-nrf51822 2.2.3
Minor amends:
  - bleDisconnectionCallback signature change
  - bleSetAdvertisingInterval now takes milliseconds as a parameter
  - event based invocation of DFU bootloader
2015-12-11 04:57:06 +00:00
Joe Finney 6d610f049a microbit: Updates to Pairing Mode to improve the user experience
More specifically:

- BLUEZONE mode renamed to PairingMode (by popular request).
- Added timeout of 90 seconds before automatic device reboot.
- Move from a scroll to a print based algorithm to improve the amount of time key is displayed fully.
- Added compulsory 'click to bond' button press.
- Improved response time of tick/cross being displayed.
2015-12-11 03:43:18 +00:00
Joe Finney 5a9f5d42bd microbit: Updates to enable anonymous advertising during normal operation
Changes to default BLE name. During normal operation, all micro:bits now have the same name: BBC micro:bit
When pairing mode (AKA BLUEZONE) is entered, device name details re appended as before, to give BBC micro:bit [<name>]

This is to provide a degree of anonymity to users, to make tracking of kids more difficult.
2015-12-11 02:09:31 +00:00