No changes

Fork of nRF51822 by Nordic Semiconductor

Revision:
596:b66851544182
Parent:
581:1dd90ec7527b
Child:
598:814c1ce92947
--- a/source/nRF5xGap.h	Mon Jan 11 10:19:34 2016 +0000
+++ b/source/nRF5xGap.h	Mon Jan 11 10:19:34 2016 +0000
@@ -22,6 +22,12 @@
 #else
     #include "mbed.h"
 #endif
+#ifndef YOTTA_CFG_WHITELIST_MAX_SIZE
+    #define YOTTA_CFG_WHITELIST_MAX_SIZE BLE_GAP_WHITELIST_ADDR_MAX_COUNT
+#elif YOTTA_CFG_WHITELIST_MAX_SIZE > BLE_GAP_WHITELIST_ADDR_MAX_COUNT
+    #undef YOTTA_CFG_WHITELIST_MAX_SIZE
+    #define YOTTA_CFG_WHITELIST_MAX_SIZE BLE_GAP_WHITELIST_ADDR_MAX_COUNT
+#endif
 #include "ble/blecommon.h"
 #include "ble.h"
 #include "ble/GapAdvertisingParams.h"
@@ -37,6 +43,8 @@
 
 #include "btle_security.h"
 
+#include <set>
+
 void radioNotificationStaticCallback(bool param);
 
 /**************************************************************************/
@@ -80,6 +88,20 @@
 
     virtual ble_error_t reset(void);
 
+    /////////////////// WHITELISTING
+    virtual int8_t getMaxWhitelistSize(void) const;
+    virtual ble_error_t getWhitelist(std::set<BLEProtocol::Address_t> &whitelist) const;
+    virtual ble_error_t setWhitelist(std::set<BLEProtocol::Address_t> whitelist);
+
+    // Accessors
+    virtual void setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode);
+    virtual void setScanningPolicyMode(ScanningPolicyMode_t mode);
+    virtual void setInitiatorPolicyMode(InitiatorPolicyMode_t mode);
+    virtual Gap::AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const;
+    virtual Gap::ScanningPolicyMode_t getScanningPolicyMode(void) const;
+    virtual Gap::InitiatorPolicyMode_t getInitiatorPolicyMode(void) const;
+    ///////////////////
+
     virtual ble_error_t initRadioNotification(void) {
         if (ble_radio_notification_init(NRF_APP_PRIORITY_HIGH, NRF_RADIO_NOTIFICATION_DISTANCE_800US, radioNotificationStaticCallback) == NRF_SUCCESS) {
             return BLE_ERROR_NONE;
@@ -93,8 +115,8 @@
     virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams) {
         ble_gap_scan_params_t scanParams = {
             .active      = scanningParams.getActiveScanning(), /**< If 1, perform active scanning (scan requests). */
-            .selective   = 0,    /**< If 1, ignore unknown devices (non whitelisted). */
-            .p_whitelist = NULL, /**< Pointer to whitelist, NULL if none is given. */
+            .selective   = scanningPolicyMode,    /**< If 1, ignore unknown devices (non whitelisted). */
+            .p_whitelist = &whitelist, /**< Pointer to whitelist, NULL if none is given. */
             .interval    = scanningParams.getInterval(),  /**< Scan interval between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
             .window      = scanningParams.getWindow(),    /**< Scan window between 0x0004 and 0x4000 in 0.625ms units (2.5ms to 10.24s). */
             .timeout     = scanningParams.getTimeout(),   /**< Scan timeout between 0x0001 and 0xFFFF in seconds, 0x0000 disables timeout. */
@@ -117,6 +139,21 @@
 #endif
 
 private:
+    /////////////////WHITELISTING
+    Gap::AdvertisingPolicyMode_t advertisingPolicyMode;
+    Gap::ScanningPolicyMode_t    scanningPolicyMode;
+    Gap::InitiatorPolicyMode_t   initiatorPolicyMode; /* Unused */
+
+    ble_gap_addr_t whitelistAddrs[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    ble_gap_addr_t *whitelistAddresses[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    uint8_t        whitelistAddressesSize;
+    ble_gap_irk_t *whitelistIrks[YOTTA_CFG_WHITELIST_MAX_SIZE];
+    uint8_t        whitelistIrksSize;
+
+    ble_gap_whitelist_t whitelist;
+
+    /////////////////
+
     bool    radioNotificationCallbackParam; /* parameter to be passed into the Timeout-generated radio notification callback. */
     Timeout radioNotificationTimeout;
 
@@ -206,8 +243,19 @@
      */
     friend class nRF5xn;
 
-    nRF5xGap() {
+    nRF5xGap() :
+        advertisingPolicyMode(Gap::ADV_POLICY_IGNORE_WHITELIST),
+        scanningPolicyMode(Gap::SCAN_POLICY_IGNORE_WHITELIST),
+        initiatorPolicyMode(Gap::INIT_POLICY_IGNORE_WHITELIST),
+        whitelistAddressesSize(0),
+        whitelistIrksSize(0) {
         m_connectionHandle = BLE_CONN_HANDLE_INVALID;
+
+        whitelist.pp_addrs = whitelistAddresses;
+        for (int i = 0; i < YOTTA_CFG_WHITELIST_MAX_SIZE; i++) {
+            whitelistAddresses[i] = &(whitelistAddrs[i]);
+        }
+        whitelist.pp_irks  = whitelistIrks;
     }
 
     nRF5xGap(nRF5xGap const &);