High level Bluetooth Low Energy API and radio abstraction layer

Dependents:   BLE_ANCS_SDAPI BLE_temperature BLE_HeartRate BLE_ANCS_SDAPI_IRC ... more

Overview

The BLE_API is a high level abstraction for using Bluetooth Low Energy on multiple platforms. For details and examples using the BLE_API please see the BLE_API Summary Page. Or click on the API Documentation tab above.

Supported Services

Supported services can be found in the BLE_API/services folder.

Files at this revision

API Documentation at this revision

Comitter:
rgrover1
Date:
Thu Nov 26 12:52:07 2015 +0000
Parent:
939:a613e75c7b9e
Child:
941:3ee6a753313d
Commit message:
Synchronized with git rev a6ef0025

Changed in this revision

CONTRIBUTING.md Show annotated file Show diff for this revision Revisions of this file
README.md Show annotated file Show diff for this revision Revisions of this file
ble/GapAdvertisingData.h Show annotated file Show diff for this revision Revisions of this file
ble/services/DFUService.h Show annotated file Show diff for this revision Revisions of this file
--- a/CONTRIBUTING.md	Thu Nov 26 12:52:07 2015 +0000
+++ b/CONTRIBUTING.md	Thu Nov 26 12:52:07 2015 +0000
@@ -1,7 +1,7 @@
 # Hello!
-We are an open source project of [ARM mbed](www.mbed.com). Contributions via [pull request](https://github.com/armmbed/yotta/pulls), and [bug reports](https://github.com/armmbed/yotta/issues) are welcome!
+We are an open source project of [ARM mbed](https://www.mbed.com). Contributions via [pull request](https://github.com/ARMmbed/ble/pulls), and [bug reports](https://github.com/ARMmbed/ble/issues) are welcome!
 
 Please submit your pull request to the 'develop' branch of this module. Commits to develop will merge into master at the time of the next release.
 
 # Contributor agreement
-For your pull request to be accepted, we will need you to agree to our [contributor agreement](http://developer.mbed.org/contributor_agreement/) to give us the necessary rights to use and distribute your contributions. (To click through the agreement create an account on mbed.com and log in.)
\ No newline at end of file
+For your pull request to be accepted, we will need you to agree to our [contributor agreement](https://developer.mbed.org/contributor_agreement/) to give us the necessary rights to use and distribute your contributions. (To click through the agreement create an account on mbed.com and log in.)
\ No newline at end of file
--- a/README.md	Thu Nov 26 12:52:07 2015 +0000
+++ b/README.md	Thu Nov 26 12:52:07 2015 +0000
@@ -1,21 +1,25 @@
 # mbed Bluetooth Low Energy Stack
-This is the github repo for the BLE_API used by developer.mbed.org. Please see [mbed BLE Homepage](http://developer.mbed.org/teams/Bluetooth-Low-Energy/) for all documentation, code examples and general help.
+This is the Github repo for the `BLE_API` used by developer.mbed.org. Please see the [mbed BLE Homepage](https://developer.mbed.org/teams/Bluetooth-Low-Energy/) for all documentation, code examples and general help.
 
 # Supported Services
-Supported GATT services and constantly being added and can be found in the /services folder.
-Currently supported  services include:
-* Battery 
+Supported GATT services and constantly being added and can be found in the `ble/source/services/` folder.
+
+Currently supported services include:
+* Battery
 * Device Firmware Update (DFU)
-* Device Information 
+* Device Information
+* Eddystone Configuration Service
 * Health Thermometer
 * Heart Rate
+* Link Loss
 * UART
 * UriBeacon
 * iBeacon
 
-# Getting Started 
-The mbed BLE API is meant to be used in projects on developer.mbed.org. Please see examples and sample project files there. 
+# Getting Started
+The mbed BLE API is meant to be used in projects on developer.mbed.org. Please see examples and sample project files there.
 A good starting point are these pages:
-* [mbed BLE Homepage](http://developer.mbed.org/teams/Bluetooth-Low-Energy/) for all things BLE
-* [mbed BLE Getting Started Guide](http://developer.mbed.org/forum/team-63-Bluetooth-Low-Energy-community/topic/5262/) a wonderful primer on using BLE with mbed
-* [mbed BLE API page](http://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/docs/tip/) for the API in generated by doxygen
\ No newline at end of file
+* [mbed BLE Homepage](https://developer.mbed.org/teams/Bluetooth-Low-Energy/) for all things BLE
+* [mbed BLE Getting Started Guide](https://developer.mbed.org/forum/team-63-Bluetooth-Low-Energy-community/topic/5262/) a wonderful primer on using BLE with mbed
+* [mbed BLE doc](https://docs.mbed.com/docs/ble-intros/en/latest/) for an introduction to mbed BLE
+* [mbed BLE API page](https://developer.mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/docs/tip/) for the API in generated by doxygen
\ No newline at end of file
--- a/ble/GapAdvertisingData.h	Thu Nov 26 12:52:07 2015 +0000
+++ b/ble/GapAdvertisingData.h	Thu Nov 26 12:52:07 2015 +0000
@@ -89,23 +89,22 @@
     */
     /**********************************************************************/
     enum DataType_t {
-        FLAGS                              = 0x01, /**< \ref *Flags */
-        INCOMPLETE_LIST_16BIT_SERVICE_IDS  = 0x02, /**< Incomplete list of 16-bit Service IDs */
-        COMPLETE_LIST_16BIT_SERVICE_IDS    = 0x03, /**< Complete list of 16-bit Service IDs */
-        INCOMPLETE_LIST_32BIT_SERVICE_IDS  = 0x04, /**< Incomplete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
-        COMPLETE_LIST_32BIT_SERVICE_IDS    = 0x05, /**< Complete list of 32-bit Service IDs (not relevant for Bluetooth 4.0) */
-        INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**< Incomplete list of 128-bit Service IDs */
-        COMPLETE_LIST_128BIT_SERVICE_IDS   = 0x07, /**< Complete list of 128-bit Service IDs */
-        SHORTENED_LOCAL_NAME               = 0x08, /**< Shortened Local Name */
-        COMPLETE_LOCAL_NAME                = 0x09, /**< Complete Local Name */
-        TX_POWER_LEVEL                     = 0x0A, /**< TX Power Level (in dBm) */
-        DEVICE_ID                          = 0x10, /**< Device ID */
-        SLAVE_CONNECTION_INTERVAL_RANGE    = 0x12, /**< Slave Connection Interval Range */
-        LIST_128BIT_SOLICITATION_IDS       = 0x15, /**< List of 128 bit service UUIDs the device is looking for */
-        SERVICE_DATA                       = 0x16, /**< Service Data */
-        APPEARANCE                         = 0x19, /**< \ref Appearance */
-        ADVERTISING_INTERVAL               = 0x1A, /**< Advertising Interval */
-        MANUFACTURER_SPECIFIC_DATA         = 0xFF  /**< Manufacturer Specific Data */
+        FLAGS                              = 0x01, /**< \ref *Flags. */
+        INCOMPLETE_LIST_16BIT_SERVICE_IDS  = 0x02, /**< Incomplete list of 16-bit service IDs. */
+        COMPLETE_LIST_16BIT_SERVICE_IDS    = 0x03, /**< Complete list of 16-bit service IDs. */
+        INCOMPLETE_LIST_32BIT_SERVICE_IDS  = 0x04, /**< Incomplete list of 32-bit service IDs (not relevant for Bluetooth 4.0). */
+        COMPLETE_LIST_32BIT_SERVICE_IDS    = 0x05, /**< Complete list of 32-bit service IDs (not relevant for Bluetooth 4.0). */
+        INCOMPLETE_LIST_128BIT_SERVICE_IDS = 0x06, /**< Incomplete list of 128-bit service IDs. */
+        COMPLETE_LIST_128BIT_SERVICE_IDS   = 0x07, /**< Complete list of 128-bit service IDs. */
+        SHORTENED_LOCAL_NAME               = 0x08, /**< Shortened local name. */
+        COMPLETE_LOCAL_NAME                = 0x09, /**< Complete local name. */
+        TX_POWER_LEVEL                     = 0x0A, /**< TX power level (in dBm). */
+        DEVICE_ID                          = 0x10, /**< Device ID. */
+        SLAVE_CONNECTION_INTERVAL_RANGE    = 0x12, /**< Slave connection interval range. */
+        SERVICE_DATA                       = 0x16, /**< Service data. */
+        APPEARANCE                         = 0x19, /**< \ref Appearance. */
+        ADVERTISING_INTERVAL               = 0x1A, /**< Advertising interval. */
+        MANUFACTURER_SPECIFIC_DATA         = 0xFF  /**< Manufacturer specific data. */
     };
     typedef enum DataType_t DataType; /* Deprecated type alias. This may be dropped in a future release. */
 
@@ -211,98 +210,27 @@
      */
     ble_error_t addData(DataType advDataType, const uint8_t *payload, uint8_t len)
     {
-        ble_error_t result = BLE_ERROR_BUFFER_OVERFLOW;
-
-        // find field
-        uint8_t* field = findField(advDataType);
-
-        // Field type already exist, either add to field or replace
-        if (field) {
-            switch(advDataType) {
-                //  These fields will be overwritten with the new value
-                case FLAGS:
-                case SHORTENED_LOCAL_NAME:
-                case COMPLETE_LOCAL_NAME:
-                case TX_POWER_LEVEL:
-                case DEVICE_ID:
-                case SLAVE_CONNECTION_INTERVAL_RANGE:
-                case SERVICE_DATA:
-                case APPEARANCE:
-                case ADVERTISING_INTERVAL:
-                case MANUFACTURER_SPECIFIC_DATA: {
-                    // current field length, with the type subtracted
-                    uint8_t dataLength = field[0] - 1;
-
-                    // new data has same length, do in-order replacement
-                    if (len == dataLength) {
-                        for (uint8_t idx = 0; idx < dataLength; idx++) {
-                            field[2 + idx] = payload[idx];
-                        }
-                    } else {
-                        // check if data fits
-                        if ((_payloadLen - dataLength + len) <= GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
-
-                            // remove old field
-                            while ((field + dataLength + 2) < &_payload[_payloadLen]) {
-                                *field = field[dataLength + 2];
-                                field++;
-                            }
-
-                            // reduce length
-                            _payloadLen -= dataLength + 2;
-
-                            // add new field
-                            result = appendField(advDataType, payload, len);
-                        }
-                    }
+        /* To Do: Check if an AD type already exists and if the existing */
+        /*       value is exclusive or not (flags and so on). */
 
-                    break;
-                }
-                // These fields will have the new data appended if there is sufficient space
-                case INCOMPLETE_LIST_16BIT_SERVICE_IDS:
-                case COMPLETE_LIST_16BIT_SERVICE_IDS:
-                case INCOMPLETE_LIST_32BIT_SERVICE_IDS:
-                case COMPLETE_LIST_32BIT_SERVICE_IDS:
-                case INCOMPLETE_LIST_128BIT_SERVICE_IDS:
-                case COMPLETE_LIST_128BIT_SERVICE_IDS:
-                case LIST_128BIT_SOLICITATION_IDS: {
-                    // check if data fits
-                    if ((_payloadLen + len) <= GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
-                        // make room for new field by moving the remainder of the
-                        // advertisement payload "to the right" starting after the
-                        // TYPE field.
-                        uint8_t* end = &_payload[_payloadLen];
-
-                        while (&field[1] < end) {
-                            end[len] = *end;
-                            end--;
-                        }
-
-                        // insert new data
-                        for (uint8_t idx = 0; idx < len; idx++) {
-                            field[2 + idx] = payload[idx];
-                        }
-
-                        // increment lengths
-                        field[0] += len;
-                        _payloadLen += len;
-
-                        result = BLE_ERROR_NONE;
-                    }
-
-                    break;
-                }
-                // Field exists but updating it is not supported. Abort operation.
-                default:
-                    result = BLE_ERROR_NOT_IMPLEMENTED;
-                    break;
-            }
-        } else {
-            // field doesn't exists, insert new
-            result = appendField(advDataType, payload, len);
+        /* Make sure we don't exceed the 31 byte payload limit. */
+        if (_payloadLen + len + 2 > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
+            return BLE_ERROR_BUFFER_OVERFLOW;
         }
 
-        return result;
+        /* Field length. */
+        memset(&_payload[_payloadLen], len + 1, 1);
+        _payloadLen++;
+
+        /* Field ID. */
+        memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
+        _payloadLen++;
+
+        /* Payload. */
+        memcpy(&_payload[_payloadLen], payload, len);
+        _payloadLen += len;
+
+        return BLE_ERROR_NONE;
     }
 
     /**
@@ -417,63 +345,7 @@
         return (uint16_t)_appearance;
     }
 
-    /**
-     * Search advertisement data for field.
-     * Returns pointer to the first element in the field if found, NULL otherwise.
-     * Where the first element is the length of the field.
-     */
-    const uint8_t* findField(DataType_t type) const {
-        return findField(type);
-    }
-
 private:
-    /**
-     * Append advertising data based on the specified AD type (see DataType)
-     */
-    ble_error_t appendField(DataType advDataType, const uint8_t *payload, uint8_t len)
-    {
-        /* Make sure we don't exceed the 31 byte payload limit */
-        if (_payloadLen + len + 2 > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
-            return BLE_ERROR_BUFFER_OVERFLOW;
-        }
-
-        /* Field length. */
-        memset(&_payload[_payloadLen], len + 1, 1);
-        _payloadLen++;
-
-        /* Field ID. */
-        memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
-        _payloadLen++;
-
-        /* Payload. */
-        memcpy(&_payload[_payloadLen], payload, len);
-        _payloadLen += len;
-
-        return BLE_ERROR_NONE;
-    }
-
-    /**
-     * Search advertisement data for field.
-     * Returns pointer to the first element in the field if found, NULL otherwise.
-     * Where the first element is the length of the field.
-     */
-    uint8_t* findField(DataType_t type) {
-        // scan through advertisement data
-        for (uint8_t idx = 0; idx < _payloadLen; ) {
-            uint8_t fieldType = _payload[idx + 1];
-
-            if (fieldType == type) {
-                return &_payload[idx];
-            }
-
-            // advance to next field
-            idx += _payload[idx] + 1;
-        }
-
-        // field not found
-        return NULL;
-    }
-
     uint8_t  _payload[GAP_ADVERTISING_DATA_MAX_PAYLOAD];
     uint8_t  _payloadLen;
     uint16_t _appearance;
--- a/ble/services/DFUService.h	Thu Nov 26 12:52:07 2015 +0000
+++ b/ble/services/DFUService.h	Thu Nov 26 12:52:07 2015 +0000
@@ -20,9 +20,7 @@
 #include "ble/BLE.h"
 #include "ble/UUID.h"
 
-extern "C" {
-#include "dfu_app_handler.h"
-}
+extern "C" void bootloader_start(void);
 
 extern const uint8_t  DFUServiceBaseUUID[];
 extern const uint16_t DFUServiceShortUUID;
@@ -103,13 +101,7 @@
                 handoverCallback();
             }
 
-            // Call bootloader_start implicitly trough a event handler call
-            // it is a work around for bootloader_start not being public in sdk 8.1
-            ble_dfu_t *p_dfu;
-            p_dfu-> conn_handle = params->connHandle;
-            ble_dfu_evt_t *p_evt;
-            p_evt->ble_dfu_evt_type = BLE_DFU_START;
-            dfu_app_on_dfu_evt(p_dfu, p_evt);
+            bootloader_start();
         }
     }