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:
Mon Jan 11 10:19:38 2016 +0000
Parent:
603:b1616eaf8206
Child:
605:07229eef5014
Commit message:
Synchronized with git rev bdf392d4
Author: Andres Amaya Garcia
Remove redundant structures from nRF5xGap

Remove the following structures/arrays from the nRF5xGap class:

* ble_gap_whitelist_t whitelist
* ble_gap_addr_t *whitelistAddressePtrs[]
* ble_gap_irk_t *whitelistIrkPtrs[]

These are made redundant because the SoftDevice does not require the user to
keep a copy of the whitelist itself.

Changed in this revision

source/nRF5xGap.cpp Show annotated file Show diff for this revision Revisions of this file
source/nRF5xGap.h Show annotated file Show diff for this revision Revisions of this file
--- a/source/nRF5xGap.cpp	Mon Jan 11 10:19:37 2016 +0000
+++ b/source/nRF5xGap.cpp	Mon Jan 11 10:19:38 2016 +0000
@@ -168,16 +168,22 @@
         return BLE_ERROR_PARAM_OUT_OF_RANGE;
     }
 
+    /* Allocate the stack's whitelist statically */
+    ble_gap_whitelist_t  whitelist;
+    ble_gap_addr_t      *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    ble_gap_irk_t       *whitelistIrkPtrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+    /* Initialize the whitelist */
+    whitelist.pp_addrs   = whitelistAddressPtrs;
+    whitelist.pp_irks    = whitelistIrkPtrs;
+    whitelist.addr_count = 0;
+    whitelist.irk_count  = 0;
+
     /* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
     if (advertisingPolicyMode != Gap::ADV_POLICY_IGNORE_WHITELIST) {
-        ble_error_t error = generateStackWhitelist();
+        ble_error_t error = generateStackWhitelist(whitelist);
         if (error != BLE_ERROR_NONE) {
             return error;
         }
-    } else {
-        /* Reset the whitelist table to avoid any errors */
-        whitelist.addr_count = 0;
-        whitelist.irk_count  = 0;
     }
 
     /* Start Advertising */
@@ -199,18 +205,24 @@
 
 /* Observer role is not supported by S110, return BLE_ERROR_NOT_IMPLEMENTED */
 #if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
-ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams) {
+ble_error_t nRF5xGap::startRadioScan(const GapScanningParams &scanningParams)
+{
+    /* Allocate the stack's whitelist statically */
+    ble_gap_whitelist_t  whitelist;
+    ble_gap_addr_t      *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    ble_gap_irk_t       *whitelistIrkPtrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+    /* Initialize the whitelist */
+    whitelist.pp_addrs   = whitelistAddressPtrs;
+    whitelist.pp_irks    = whitelistIrkPtrs;
+    whitelist.addr_count = 0;
+    whitelist.irk_count  = 0;
 
     /* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
     if (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) {
-        ble_error_t error = generateStackWhitelist();
+        ble_error_t error = generateStackWhitelist(whitelist);
         if (error != BLE_ERROR_NONE) {
             return error;
         }
-    } else {
-        /* Reset the whitelist table to avoid any errors */
-        whitelist.addr_count = 0;
-        whitelist.irk_count  = 0;
     }
 
     ble_gap_scan_params_t scanParams = {
@@ -286,16 +298,22 @@
         connParams.conn_sup_timeout  = 600;
     }
 
+    /* Allocate the stack's whitelist statically */
+    ble_gap_whitelist_t  whitelist;
+    ble_gap_addr_t      *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    ble_gap_irk_t       *whitelistIrkPtrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
+    /* Initialize the whitelist */
+    whitelist.pp_addrs   = whitelistAddressPtrs;
+    whitelist.pp_irks    = whitelistIrkPtrs;
+    whitelist.addr_count = 0;
+    whitelist.irk_count  = 0;
+
     /* Add missing IRKs to whitelist from the bond table held by the SoftDevice */
     if (scanningPolicyMode != Gap::SCAN_POLICY_IGNORE_WHITELIST) {
-        ble_error_t error = generateStackWhitelist();
+        ble_error_t error = generateStackWhitelist(whitelist);
         if (error != BLE_ERROR_NONE) {
             return error;
         }
-    } else {
-        /* Reset the whitelist table to avoid any errors */
-        whitelist.addr_count = 0;
-        whitelist.irk_count  = 0;
     }
 
     ble_gap_scan_params_t scanParams;
@@ -839,7 +857,7 @@
     @endcode
 */
 /**************************************************************************/
-ble_error_t nRF5xGap::generateStackWhitelist(void)
+ble_error_t nRF5xGap::generateStackWhitelist(ble_gap_whitelist_t &whitelist)
 {
     ble_gap_whitelist_t  whitelistFromBondTable;
     ble_gap_addr_t      *addressPtr[1];
--- a/source/nRF5xGap.h	Mon Jan 11 10:19:37 2016 +0000
+++ b/source/nRF5xGap.h	Mon Jan 11 10:19:38 2016 +0000
@@ -133,11 +133,6 @@
     /* Internal representation of a whitelist */
     uint8_t         whitelistAddressesSize;
     ble_gap_addr_t  whitelistAddresses[YOTTA_CFG_WHITELIST_MAX_SIZE];
-    ble_gap_addr_t *whitelistAddressPtrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
-    ble_gap_irk_t  *whitelistIrkPtrs[YOTTA_CFG_IRK_TABLE_MAX_SIZE];
-
-    /* Structure used by the SoftDevice to represent a whitelist together with IRK table */
-    ble_gap_whitelist_t whitelist;
 
     /*
      * An internal function used to populate the ble_gap_whitelist_t that will be used by
@@ -145,7 +140,7 @@
      * API the whitelist is just a collection of keys, but for the stack it also includes
      * the IRK table.
      */
-    ble_error_t generateStackWhitelist(void);
+    ble_error_t generateStackWhitelist(ble_gap_whitelist_t &whitelist);
 
 private:
     bool    radioNotificationCallbackParam; /* parameter to be passed into the Timeout-generated radio notification callback. */
@@ -239,15 +234,9 @@
 
     nRF5xGap() :
         advertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST),
-        scanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST) {
+        scanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST),
+        whitelistAddressesSize(0) {
         m_connectionHandle = BLE_CONN_HANDLE_INVALID;
-
-        /* Reset the whitelist */
-        whitelist.addr_count   = 0;
-        whitelist.irk_count    = 0;
-        whitelist.pp_irks      = whitelistIrkPtrs;
-        whitelist.pp_addrs     = whitelistAddressPtrs;
-        whitelistAddressesSize = 0;
     }
 
     nRF5xGap(nRF5xGap const &);