mirror of https://github.com/ARMmbed/mbed-os.git
Cordio: Use GenericGap instead of CordioGap.
parent
e9170e6507
commit
c8747aad0f
|
@ -22,12 +22,15 @@
|
||||||
#include "ble/BLEInstanceBase.h"
|
#include "ble/BLEInstanceBase.h"
|
||||||
|
|
||||||
#include "CordioHCIDriver.h"
|
#include "CordioHCIDriver.h"
|
||||||
#include "CordioGap.h"
|
|
||||||
#include "CordioGattServer.h"
|
#include "CordioGattServer.h"
|
||||||
#include "CordioSecurityManager.h"
|
#include "CordioSecurityManager.h"
|
||||||
#include "CordioPalAttClient.h"
|
#include "CordioPalAttClient.h"
|
||||||
#include "ble/pal/AttClientToGattClientAdapter.h"
|
#include "ble/pal/AttClientToGattClientAdapter.h"
|
||||||
#include "ble/generic/GenericGattClient.h"
|
#include "ble/generic/GenericGattClient.h"
|
||||||
|
#include "CordioPalGap.h"
|
||||||
|
#include "CordioPalGenericAccessService.h"
|
||||||
|
#include "ble/generic/GenericGap.h"
|
||||||
|
#include "ble/pal/SimpleEventQueue.h"
|
||||||
|
|
||||||
namespace ble {
|
namespace ble {
|
||||||
namespace vendor {
|
namespace vendor {
|
||||||
|
@ -81,12 +84,12 @@ public:
|
||||||
/**
|
/**
|
||||||
* @see BLEInstanceBase::getGap
|
* @see BLEInstanceBase::getGap
|
||||||
*/
|
*/
|
||||||
virtual Gap& getGap();
|
virtual ::Gap& getGap();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BLEInstanceBase::getGap
|
* @see BLEInstanceBase::getGap
|
||||||
*/
|
*/
|
||||||
virtual const Gap& getGap() const;
|
virtual const ::Gap& getGap() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see BLEInstanceBase::getGattServer
|
* @see BLEInstanceBase::getGattServer
|
||||||
|
@ -143,6 +146,7 @@ private:
|
||||||
} initialization_status;
|
} initialization_status;
|
||||||
|
|
||||||
::BLE::InstanceID_t instanceID;
|
::BLE::InstanceID_t instanceID;
|
||||||
|
mutable pal::SimpleEventQueue _event_queue;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cordio
|
} // namespace cordio
|
||||||
|
|
|
@ -1,262 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
* Copyright (c) 2017-2017 ARM Limited
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef CORDIO_GAP_H_
|
|
||||||
#define CORDIO_GAP_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "ble/blecommon.h"
|
|
||||||
#include "ble/GapAdvertisingParams.h"
|
|
||||||
#include "ble/GapAdvertisingData.h"
|
|
||||||
#include "ble/Gap.h"
|
|
||||||
#include "ble/GapScanningParams.h"
|
|
||||||
#include "dm_api.h"
|
|
||||||
#include "att_api.h"
|
|
||||||
|
|
||||||
namespace ble {
|
|
||||||
namespace vendor {
|
|
||||||
namespace cordio {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap
|
|
||||||
*/
|
|
||||||
class Gap : public ::Gap
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* Return the Gap singleton implementing ::Gap for the Cordio stac.
|
|
||||||
*/
|
|
||||||
static Gap &getInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This function shall be called once the stack has been initialized
|
|
||||||
*/
|
|
||||||
void initialize();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setAddress
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setAddress(AddressType_t type, const Address_t address);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getAddress
|
|
||||||
*/
|
|
||||||
virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setAdvertisingData
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setAdvertisingData(
|
|
||||||
const GapAdvertisingData&, const GapAdvertisingData&
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::connect
|
|
||||||
*/
|
|
||||||
virtual ble_error_t connect(
|
|
||||||
const BLEProtocol::AddressBytes_t peerAddr,
|
|
||||||
BLEProtocol::AddressType_t peerAddrType,
|
|
||||||
const ConnectionParams_t* connectionParams,
|
|
||||||
const GapScanningParams* scanParams
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getMinAdvertisingInterval
|
|
||||||
*/
|
|
||||||
virtual uint16_t getMinAdvertisingInterval() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getMinNonConnectableAdvertisingInterval
|
|
||||||
*/
|
|
||||||
virtual uint16_t getMinNonConnectableAdvertisingInterval() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getMaxAdvertisingInterval
|
|
||||||
*/
|
|
||||||
virtual uint16_t getMaxAdvertisingInterval() const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::startAdvertising
|
|
||||||
*/
|
|
||||||
virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::stopAdvertising
|
|
||||||
*/
|
|
||||||
virtual ble_error_t stopAdvertising();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::disconnect
|
|
||||||
*/
|
|
||||||
virtual ble_error_t disconnect(
|
|
||||||
Handle_t connectionHandle,
|
|
||||||
DisconnectionReason_t reason
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::disconnect
|
|
||||||
*/
|
|
||||||
virtual ble_error_t disconnect(DisconnectionReason_t reason);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setDeviceName
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getDeviceName
|
|
||||||
*/
|
|
||||||
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setAppearance
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getAppearance
|
|
||||||
*/
|
|
||||||
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setTxPower
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setTxPower(int8_t txPower);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getPermittedTxPowerValues
|
|
||||||
*/
|
|
||||||
virtual void getPermittedTxPowerValues(
|
|
||||||
const int8_t **valueArrayPP, size_t *countP
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the internal connection handle
|
|
||||||
*/
|
|
||||||
void setConnectionHandle(uint16_t m_connectionHandle);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current connection handle
|
|
||||||
*/
|
|
||||||
uint16_t getConnectionHandle();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getPreferredConnectionParams
|
|
||||||
*/
|
|
||||||
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setPreferredConnectionParams
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setPreferredConnectionParams(
|
|
||||||
const ConnectionParams_t *params
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::updateConnectionParams
|
|
||||||
*/
|
|
||||||
virtual ble_error_t updateConnectionParams(
|
|
||||||
Handle_t handle, const ConnectionParams_t *params
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::startRadioScan
|
|
||||||
*/
|
|
||||||
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::stopScan
|
|
||||||
*/
|
|
||||||
virtual ble_error_t stopScan();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when advertising is stopped.
|
|
||||||
*/
|
|
||||||
void advertisingStopped();
|
|
||||||
|
|
||||||
// Whitelist management
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getMaxWhitelistSize
|
|
||||||
*/
|
|
||||||
virtual uint8_t getMaxWhitelistSize(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getWhitelist
|
|
||||||
*/
|
|
||||||
virtual ble_error_t getWhitelist(Whitelist_t &whitelist) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setWhitelist
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setWhitelist(const Whitelist_t &whitelist);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setAdvertisingPolicyMode
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getAdvertisingPolicyMode
|
|
||||||
*/
|
|
||||||
virtual AdvertisingPolicyMode_t getAdvertisingPolicyMode(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setScanningPolicyMode
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setScanningPolicyMode(ScanningPolicyMode_t mode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getScanningPolicyMode
|
|
||||||
*/
|
|
||||||
virtual ScanningPolicyMode_t getScanningPolicyMode(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::setInitiatorPolicyMode
|
|
||||||
*/
|
|
||||||
virtual ble_error_t setInitiatorPolicyMode(InitiatorPolicyMode_t mode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::getInitiatorPolicyMode
|
|
||||||
*/
|
|
||||||
virtual InitiatorPolicyMode_t getInitiatorPolicyMode(void) const;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see ::Gap::reset
|
|
||||||
*/
|
|
||||||
virtual ble_error_t reset(void);
|
|
||||||
|
|
||||||
private:
|
|
||||||
Gap();
|
|
||||||
|
|
||||||
Gap(Gap const &);
|
|
||||||
void operator=(Gap const &);
|
|
||||||
|
|
||||||
uint16_t m_connectionHandle;
|
|
||||||
addr_type_t m_type;
|
|
||||||
Address_t m_addr;
|
|
||||||
|
|
||||||
AdvertisingPolicyMode_t advertising_policy_mode;
|
|
||||||
ScanningPolicyMode_t scanning_policy_mode;
|
|
||||||
InitiatorPolicyMode_t initiator_policy_mode;
|
|
||||||
Whitelist_t whitelist;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace cordio
|
|
||||||
} // namespace vendor
|
|
||||||
} // namespace ble
|
|
||||||
|
|
||||||
#endif /* CORDIO_GAP_H_ */
|
|
|
@ -39,9 +39,6 @@
|
||||||
/*! WSF handler ID */
|
/*! WSF handler ID */
|
||||||
wsfHandlerId_t stack_handler_id;
|
wsfHandlerId_t stack_handler_id;
|
||||||
|
|
||||||
/* Store the Event signaling state */
|
|
||||||
bool isEventsSignaled = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Weak definition of ble_cordio_get_hci_driver.
|
* Weak definition of ble_cordio_get_hci_driver.
|
||||||
* A runtime error is generated if the user does not define any
|
* A runtime error is generated if the user does not define any
|
||||||
|
@ -78,10 +75,7 @@ extern "C" void hci_mbed_os_handle_reset_sequence(uint8_t* msg)
|
||||||
*/
|
*/
|
||||||
extern "C" void wsf_mbed_ble_signal_event(void)
|
extern "C" void wsf_mbed_ble_signal_event(void)
|
||||||
{
|
{
|
||||||
if(isEventsSignaled == false) {
|
ble::vendor::cordio::BLE::deviceInstance().signalEventsToProcess(::BLE::DEFAULT_INSTANCE);
|
||||||
isEventsSignaled = true;
|
|
||||||
ble::vendor::cordio::BLE::deviceInstance().signalEventsToProcess(::BLE::DEFAULT_INSTANCE);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,7 +93,8 @@ namespace cordio {
|
||||||
|
|
||||||
BLE::BLE(CordioHCIDriver& hci_driver) :
|
BLE::BLE(CordioHCIDriver& hci_driver) :
|
||||||
initialization_status(NOT_INITIALIZED),
|
initialization_status(NOT_INITIALIZED),
|
||||||
instanceID(::BLE::DEFAULT_INSTANCE)
|
instanceID(::BLE::DEFAULT_INSTANCE),
|
||||||
|
_event_queue()
|
||||||
{
|
{
|
||||||
_hci_driver = &hci_driver;
|
_hci_driver = &hci_driver;
|
||||||
stack_setup();
|
stack_setup();
|
||||||
|
@ -122,9 +117,9 @@ ble_error_t BLE::init(
|
||||||
::BLE::InstanceID_t instanceID,
|
::BLE::InstanceID_t instanceID,
|
||||||
FunctionPointerWithContext< ::BLE::InitializationCompleteCallbackContext *> initCallback)
|
FunctionPointerWithContext< ::BLE::InitializationCompleteCallbackContext *> initCallback)
|
||||||
{
|
{
|
||||||
|
|
||||||
switch (initialization_status) {
|
switch (initialization_status) {
|
||||||
case NOT_INITIALIZED:
|
case NOT_INITIALIZED:
|
||||||
|
_event_queue.initialize(this, instanceID);
|
||||||
_init_callback = initCallback;
|
_init_callback = initCallback;
|
||||||
start_stack_reset();
|
start_stack_reset();
|
||||||
return BLE_ERROR_NONE;
|
return BLE_ERROR_NONE;
|
||||||
|
@ -157,6 +152,7 @@ ble_error_t BLE::shutdown()
|
||||||
getGattServer().reset();
|
getGattServer().reset();
|
||||||
getGattClient().reset();
|
getGattClient().reset();
|
||||||
getGap().reset();
|
getGap().reset();
|
||||||
|
_event_queue.clear();
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
return BLE_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
@ -167,15 +163,25 @@ const char* BLE::getVersion()
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gap& BLE::getGap()
|
::Gap& BLE::getGap()
|
||||||
{
|
{
|
||||||
return cordio::Gap::getInstance();
|
typedef ::Gap& return_type;
|
||||||
|
const BLE* self = this;
|
||||||
|
return const_cast<return_type>(self->getGap());
|
||||||
}
|
}
|
||||||
|
|
||||||
const Gap& BLE::getGap() const
|
const ::Gap& BLE::getGap() const
|
||||||
{
|
{
|
||||||
return cordio::Gap::getInstance();
|
static pal::vendor::cordio::Gap& cordio_pal_gap =
|
||||||
}
|
pal::vendor::cordio::Gap::get_gap();
|
||||||
|
static pal::vendor::cordio::GenericAccessService cordio_gap_service;
|
||||||
|
static ble::generic::GenericGap gap(
|
||||||
|
_event_queue,
|
||||||
|
cordio_pal_gap,
|
||||||
|
cordio_gap_service
|
||||||
|
);
|
||||||
|
return gap;
|
||||||
|
};
|
||||||
|
|
||||||
GattServer& BLE::getGattServer()
|
GattServer& BLE::getGattServer()
|
||||||
{
|
{
|
||||||
|
@ -226,11 +232,8 @@ void BLE::waitForEvent()
|
||||||
|
|
||||||
void BLE::processEvents()
|
void BLE::processEvents()
|
||||||
{
|
{
|
||||||
if (isEventsSignaled) {
|
callDispatcher();
|
||||||
isEventsSignaled = false;
|
}
|
||||||
callDispatcher();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void BLE::stack_handler(wsfEventMask_t event, wsfMsgHdr_t* msg)
|
void BLE::stack_handler(wsfEventMask_t event, wsfMsgHdr_t* msg)
|
||||||
{
|
{
|
||||||
|
@ -245,66 +248,12 @@ void BLE::processEvents()
|
||||||
BLE_ERROR_NONE
|
BLE_ERROR_NONE
|
||||||
};
|
};
|
||||||
deviceInstance().getGattServer().initialize();
|
deviceInstance().getGattServer().initialize();
|
||||||
deviceInstance().getGap().initialize();
|
|
||||||
deviceInstance().initialization_status = INITIALIZED;
|
deviceInstance().initialization_status = INITIALIZED;
|
||||||
_init_callback.call(&context);
|
_init_callback.call(&context);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case DM_ADV_START_IND:
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DM_ADV_STOP_IND:
|
|
||||||
Gap::getInstance().advertisingStopped();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case DM_SCAN_REPORT_IND: {
|
|
||||||
hciLeAdvReportEvt_t *scan_report = (hciLeAdvReportEvt_t*) msg;
|
|
||||||
Gap::getInstance().processAdvertisementReport(
|
|
||||||
scan_report->addr,
|
|
||||||
scan_report->rssi,
|
|
||||||
(scan_report->eventType == DM_RPT_SCAN_RESPONSE) ? true : false,
|
|
||||||
(GapAdvertisingParams::AdvertisingType_t) scan_report->eventType,
|
|
||||||
scan_report->len,
|
|
||||||
scan_report->pData
|
|
||||||
);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case DM_CONN_OPEN_IND: {
|
|
||||||
hciLeConnCmplEvt_t* conn_evt = (hciLeConnCmplEvt_t*) msg;
|
|
||||||
dmConnId_t connection_id = conn_evt->hdr.param;
|
|
||||||
Gap::getInstance().setConnectionHandle(connection_id);
|
|
||||||
Gap::AddressType_t own_addr_type;
|
|
||||||
Gap::Address_t own_addr;
|
|
||||||
Gap::getInstance().getAddress(&own_addr_type, own_addr);
|
|
||||||
|
|
||||||
Gap::ConnectionParams_t params = {
|
|
||||||
conn_evt->connInterval,
|
|
||||||
conn_evt->connInterval,
|
|
||||||
conn_evt->connLatency,
|
|
||||||
conn_evt->supTimeout
|
|
||||||
};
|
|
||||||
|
|
||||||
Gap::getInstance().processConnectionEvent(
|
|
||||||
connection_id,
|
|
||||||
(conn_evt->role == DM_ROLE_MASTER) ? Gap::CENTRAL : Gap::PERIPHERAL,
|
|
||||||
(Gap::AddressType_t) conn_evt->addrType,
|
|
||||||
conn_evt->peerAddr,
|
|
||||||
own_addr_type,
|
|
||||||
own_addr,
|
|
||||||
¶ms
|
|
||||||
);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case DM_CONN_CLOSE_IND: {
|
|
||||||
dmEvt_t *disconnect_evt = (dmEvt_t*) msg;
|
|
||||||
Gap::getInstance().setConnectionHandle(DM_CONN_ID_NONE);
|
|
||||||
Gap::getInstance().processDisconnectionEvent(
|
|
||||||
disconnect_evt->hdr.param,
|
|
||||||
(Gap::DisconnectionReason_t) disconnect_evt->connClose.reason
|
|
||||||
);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
ble::pal::vendor::cordio::Gap::gap_handler(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -419,6 +368,10 @@ void BLE::start_stack_reset()
|
||||||
|
|
||||||
void BLE::callDispatcher()
|
void BLE::callDispatcher()
|
||||||
{
|
{
|
||||||
|
// process the external event queue
|
||||||
|
_event_queue.process();
|
||||||
|
|
||||||
|
// follow by stack events
|
||||||
static uint32_t lastTimeUs = us_ticker_read();
|
static uint32_t lastTimeUs = us_ticker_read();
|
||||||
uint32_t currTimeUs, deltaTimeMs;
|
uint32_t currTimeUs, deltaTimeMs;
|
||||||
|
|
||||||
|
|
|
@ -1,543 +0,0 @@
|
||||||
/* mbed Microcontroller Library
|
|
||||||
* Copyright (c) 2017-2017 ARM Limited
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
#include "CordioGap.h"
|
|
||||||
#include "mbed.h"
|
|
||||||
#include "dm_api.h"
|
|
||||||
#include "CordioGattServer.h"
|
|
||||||
#include "hci_core.h"
|
|
||||||
|
|
||||||
/**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
|
|
||||||
#define BLE_GAP_ADV_INTERVAL_MIN 0x0020
|
|
||||||
|
|
||||||
/**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
|
|
||||||
#define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0
|
|
||||||
|
|
||||||
/**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */
|
|
||||||
#define BLE_GAP_ADV_INTERVAL_MAX 0x4000
|
|
||||||
|
|
||||||
namespace ble {
|
|
||||||
namespace vendor {
|
|
||||||
namespace cordio {
|
|
||||||
|
|
||||||
Gap &Gap::getInstance()
|
|
||||||
{
|
|
||||||
static Gap m_instance;
|
|
||||||
return m_instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gap::initialize()
|
|
||||||
{
|
|
||||||
uint8_t whitelist_size = HciGetWhiteListSize();
|
|
||||||
|
|
||||||
if (whitelist_size == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
whitelist.addresses = new(std::nothrow) BLEProtocol::Address_t[whitelist_size];
|
|
||||||
if (whitelist.addresses == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
whitelist.size = 0;
|
|
||||||
whitelist.capacity = hciCoreCb.whiteListSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setAddress(AddressType_t type, const Address_t address)
|
|
||||||
{
|
|
||||||
switch (type) {
|
|
||||||
case BLEProtocol::AddressType::PUBLIC:
|
|
||||||
// TODO: use vendor specific commands from the driver
|
|
||||||
return BLE_ERROR_OPERATION_NOT_PERMITTED;
|
|
||||||
|
|
||||||
// See bluetooth 5, Vol 6 part, part B, 1.3.2
|
|
||||||
case BLEProtocol::AddressType::RANDOM_STATIC:
|
|
||||||
if ((address[5] >> 6) != 3) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_type = type;
|
|
||||||
BdaCpy(m_addr, address);
|
|
||||||
DmDevSetRandAddr(m_addr);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// should not be here, generation is supposed to be handled by the controller.
|
|
||||||
case BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE:
|
|
||||||
case BLEProtocol::AddressType::RANDOM_PRIVATE_NON_RESOLVABLE:
|
|
||||||
m_type = type;
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
|
|
||||||
default:
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
DmAdvSetAddrType(m_type);
|
|
||||||
DmConnSetAddrType(m_type);
|
|
||||||
DmScanSetAddrType(m_type);
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::getAddress(AddressType_t *typeP, Address_t address)
|
|
||||||
{
|
|
||||||
*typeP = m_type;
|
|
||||||
|
|
||||||
if(m_type == BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE ||
|
|
||||||
m_type == BLEProtocol::AddressType::RANDOM_PRIVATE_RESOLVABLE) {
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
BdaCpy(address, m_addr);
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setAdvertisingData(const GapAdvertisingData &advData, const GapAdvertisingData &scanResponse)
|
|
||||||
{
|
|
||||||
/* Make sure we don't exceed the advertising payload length */
|
|
||||||
if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
|
|
||||||
return BLE_ERROR_BUFFER_OVERFLOW;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make sure we have a payload! */
|
|
||||||
if (advData.getPayloadLen() == 0) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set advertising and scan response data for discoverable mode */
|
|
||||||
DmAdvSetData(DM_ADV_HANDLE_DEFAULT, HCI_ADV_DATA_OP_COMP_FRAG, DM_DATA_LOC_ADV, advData.getPayloadLen(), (uint8_t*)advData.getPayload());
|
|
||||||
DmAdvSetData(DM_ADV_HANDLE_DEFAULT, HCI_ADV_DATA_OP_COMP_FRAG, DM_DATA_LOC_SCAN, scanResponse.getPayloadLen(), (uint8_t*)scanResponse.getPayload());
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::connect(
|
|
||||||
const BLEProtocol::AddressBytes_t peerAddr,
|
|
||||||
BLEProtocol::AddressType_t peerAddrType,
|
|
||||||
const ConnectionParams_t* connectionParams,
|
|
||||||
const GapScanningParams* scanParams
|
|
||||||
) {
|
|
||||||
// prepare the scan interval
|
|
||||||
if (scanParams != NULL) {
|
|
||||||
DmConnSetScanInterval(scanParams->getInterval(), scanParams->getWindow());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connectionParams != NULL) {
|
|
||||||
hciConnSpec_t conn_spec = {
|
|
||||||
/* connIntervalMin */ connectionParams->minConnectionInterval,
|
|
||||||
/* connIntervalMax */ connectionParams->maxConnectionInterval,
|
|
||||||
/* connLatency */ connectionParams->slaveLatency,
|
|
||||||
/* supTimeout */ connectionParams->connectionSupervisionTimeout,
|
|
||||||
/* minCeLen */ DM_GAP_CONN_EST_MIN_CE_LEN,
|
|
||||||
/* maxCeLen */ DM_GAP_CONN_EST_MAX_CE_LEN
|
|
||||||
};
|
|
||||||
DmConnSetConnSpec(&conn_spec);
|
|
||||||
}
|
|
||||||
|
|
||||||
DmScanStop();
|
|
||||||
dmConnId_t connection_id = DmConnOpen(
|
|
||||||
DM_CLIENT_ID_APP,
|
|
||||||
HCI_INIT_PHY_LE_1M_BIT,
|
|
||||||
peerAddrType,
|
|
||||||
(uint8_t*) peerAddr
|
|
||||||
);
|
|
||||||
|
|
||||||
if (connection_id == DM_CONN_ID_NONE) {
|
|
||||||
return BLE_ERROR_INTERNAL_STACK_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Gap::getMinAdvertisingInterval() const
|
|
||||||
{
|
|
||||||
return BLE_GAP_ADV_INTERVAL_MIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Gap::getMinNonConnectableAdvertisingInterval() const
|
|
||||||
{
|
|
||||||
return BLE_GAP_ADV_NONCON_INTERVAL_MIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Gap::getMaxAdvertisingInterval() const
|
|
||||||
{
|
|
||||||
return BLE_GAP_ADV_INTERVAL_MAX;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::startAdvertising(const GapAdvertisingParams ¶ms)
|
|
||||||
{
|
|
||||||
/* Make sure we support the advertising type */
|
|
||||||
if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) {
|
|
||||||
/* ToDo: This requires a proper security implementation, etc. */
|
|
||||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check interval range */
|
|
||||||
if (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED) {
|
|
||||||
/* Min delay is slightly longer for unconnectable devices */
|
|
||||||
if ((params.getIntervalInADVUnits() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) ||
|
|
||||||
(params.getIntervalInADVUnits() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ((params.getIntervalInADVUnits() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN) ||
|
|
||||||
(params.getIntervalInADVUnits() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check timeout is zero for Connectable Directed */
|
|
||||||
if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) && (params.getTimeout() != 0)) {
|
|
||||||
/* Timeout must be 0 with this type, although we'll never get here */
|
|
||||||
/* since this isn't implemented yet anyway */
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check timeout for other advertising types */
|
|
||||||
if ((params.getAdvertisingType() != GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
|
|
||||||
(params.getTimeout() > GapAdvertisingParams::GAP_ADV_PARAMS_TIMEOUT_MAX)) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t adv_interval_min = params.getIntervalInADVUnits();
|
|
||||||
if (adv_interval_min == GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX) {
|
|
||||||
--adv_interval_min;
|
|
||||||
}
|
|
||||||
uint16_t adv_interval_max = adv_interval_min + 1;
|
|
||||||
|
|
||||||
DmAdvSetInterval(DM_ADV_HANDLE_DEFAULT, adv_interval_min, adv_interval_max);
|
|
||||||
|
|
||||||
/* Peer Addr Type 0 = Public */
|
|
||||||
uint8_t peerAddrType = 0;
|
|
||||||
uint8_t peerAddr[6] = { 0 };
|
|
||||||
DmAdvConfig(DM_ADV_HANDLE_DEFAULT, params.getAdvertisingType(), peerAddrType, peerAddr);
|
|
||||||
|
|
||||||
uint8_t adv_handles[] = { DM_ADV_HANDLE_DEFAULT };
|
|
||||||
uint16_t adv_durations[] = { (uint16_t) (params.getTimeout() * 1000) };
|
|
||||||
uint8_t max_ea_events[] = { 0 };
|
|
||||||
DmAdvStart(1, adv_handles, adv_durations, max_ea_events);
|
|
||||||
|
|
||||||
state.advertising = 1;
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::stopAdvertising(void)
|
|
||||||
{
|
|
||||||
uint8_t adv_handles[] = { DM_ADV_HANDLE_DEFAULT };
|
|
||||||
DmAdvStop(1, adv_handles);
|
|
||||||
|
|
||||||
state.advertising = 0;
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::disconnect(Handle_t connectionHandle, DisconnectionReason_t reason)
|
|
||||||
{
|
|
||||||
DmConnClose(DM_CLIENT_ID_APP, connectionHandle, reason);
|
|
||||||
|
|
||||||
state.advertising = 0;
|
|
||||||
state.connected = 0;
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::disconnect(DisconnectionReason_t reason)
|
|
||||||
{
|
|
||||||
DmConnClose(DM_CLIENT_ID_APP, m_connectionHandle, reason);
|
|
||||||
|
|
||||||
state.advertising = 0;
|
|
||||||
state.connected = 0;
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setDeviceName(const uint8_t *deviceName)
|
|
||||||
{
|
|
||||||
return GattServer::getInstance().setDeviceName(deviceName);
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::getDeviceName(uint8_t *deviceName, unsigned *lengthP)
|
|
||||||
{
|
|
||||||
const uint8_t* name = NULL;
|
|
||||||
uint16_t length = 0;
|
|
||||||
|
|
||||||
GattServer::getInstance().getDeviceName(name, length);
|
|
||||||
|
|
||||||
if (deviceName != NULL) {
|
|
||||||
memcpy(deviceName, name, std::min((uint16_t) *lengthP, length));
|
|
||||||
}
|
|
||||||
|
|
||||||
*lengthP = length;
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setAppearance(GapAdvertisingData::Appearance appearance)
|
|
||||||
{
|
|
||||||
GattServer::getInstance().setAppearance(appearance);
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::getAppearance(GapAdvertisingData::Appearance *appearanceP)
|
|
||||||
{
|
|
||||||
*appearanceP = GattServer::getInstance().getAppearance();
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setTxPower(int8_t txPower)
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
HciVsSetTxPower(txPower);
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
#else
|
|
||||||
return BLE_ERROR_NOT_IMPLEMENTED;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP)
|
|
||||||
{
|
|
||||||
*valueArrayPP = NULL;
|
|
||||||
*countP = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gap::setConnectionHandle(uint16_t connectionHandle)
|
|
||||||
{
|
|
||||||
m_connectionHandle = connectionHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t Gap::getConnectionHandle(void)
|
|
||||||
{
|
|
||||||
return m_connectionHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::getPreferredConnectionParams(ConnectionParams_t *params)
|
|
||||||
{
|
|
||||||
*params = GattServer::getInstance().getPreferredConnectionParams();
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setPreferredConnectionParams(const ConnectionParams_t *params)
|
|
||||||
{
|
|
||||||
// ensure that parameters are correct
|
|
||||||
// see BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part C]
|
|
||||||
// section 12.3 PERIPHERAL PREFERRED CONNECTION PARAMETERS CHARACTERISTIC
|
|
||||||
if (((0x0006 > params->minConnectionInterval) || (params->minConnectionInterval > 0x0C80)) &&
|
|
||||||
params->minConnectionInterval != 0xFFFF) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((params->minConnectionInterval > params->maxConnectionInterval) || (params->maxConnectionInterval > 0x0C80)) &&
|
|
||||||
params->maxConnectionInterval != 0xFFFF) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params->slaveLatency > 0x01F3) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((0x000A > params->connectionSupervisionTimeout) || (params->connectionSupervisionTimeout > 0x0C80)) &&
|
|
||||||
params->connectionSupervisionTimeout != 0xFFFF) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
GattServer::getInstance().setPreferredConnectionParams(*params);
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::updateConnectionParams(Handle_t handle, const ConnectionParams_t *newParams)
|
|
||||||
{
|
|
||||||
if (DmConnCheckIdle(handle) != 0) {
|
|
||||||
return BLE_STACK_BUSY;
|
|
||||||
}
|
|
||||||
|
|
||||||
hciConnSpec_t connSpec;
|
|
||||||
connSpec.connIntervalMin = newParams->minConnectionInterval;
|
|
||||||
connSpec.connIntervalMax = newParams->maxConnectionInterval;
|
|
||||||
connSpec.connLatency = newParams->slaveLatency;
|
|
||||||
connSpec.supTimeout = newParams->connectionSupervisionTimeout;
|
|
||||||
DmConnUpdate(handle, &connSpec);
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::startRadioScan(const GapScanningParams &scanningParams)
|
|
||||||
{
|
|
||||||
// not needed to start scanning if the whitelist is empty and the scanning
|
|
||||||
// policy filter all the advertising packets
|
|
||||||
if ((whitelist.size == 0) && (scanning_policy_mode == Gap::SCAN_POLICY_FILTER_ALL_ADV)) {
|
|
||||||
return BLE_ERROR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t scan_intervals[] = { scanningParams.getInterval() };
|
|
||||||
uint16_t scan_windows[] = { scanningParams.getWindow() };
|
|
||||||
|
|
||||||
DmScanSetInterval(HCI_SCAN_PHY_LE_1M_BIT, scan_intervals, scan_windows);
|
|
||||||
|
|
||||||
uint8_t scanType = scanningParams.getActiveScanning() ? DM_SCAN_TYPE_ACTIVE : DM_SCAN_TYPE_PASSIVE;
|
|
||||||
uint32_t duration = (uint32_t)scanningParams.getTimeout() * 1000;
|
|
||||||
if (duration > 0xFFFF) {
|
|
||||||
// saturate to 16-bits
|
|
||||||
duration = 0xFFFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
DmScanStart(HCI_SCAN_PHY_LE_1M_BIT, DM_DISC_MODE_NONE, &scanType, TRUE, duration, 0);
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::stopScan(void)
|
|
||||||
{
|
|
||||||
DmScanStop();
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Gap::advertisingStopped(void)
|
|
||||||
{
|
|
||||||
/* If advertising stopped due to a call to stopAdvertising(), state.advertising will
|
|
||||||
* be '0.' Otherwise, advertising must have stopped due to a timeout
|
|
||||||
*/
|
|
||||||
if (state.advertising) {
|
|
||||||
processTimeoutEvent(Gap::TIMEOUT_SRC_ADVERTISING);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t Gap::getMaxWhitelistSize(void) const
|
|
||||||
{
|
|
||||||
return whitelist.capacity;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::getWhitelist(Whitelist_t &other) const
|
|
||||||
{
|
|
||||||
// i is a shorthand for other.size
|
|
||||||
uint8_t& i = other.size;
|
|
||||||
|
|
||||||
for (i = 0; (i < whitelist.capacity) && (i < other.capacity); ++i) {
|
|
||||||
other.addresses[i] = whitelist.addresses[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setWhitelist(const Whitelist_t& other)
|
|
||||||
{
|
|
||||||
if (other.capacity > whitelist.capacity) {
|
|
||||||
return BLE_ERROR_PARAM_OUT_OF_RANGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// note : can be improved by sending the diff instead of the full list
|
|
||||||
|
|
||||||
DmDevWhiteListClear();
|
|
||||||
|
|
||||||
// alias i to whitelist.size
|
|
||||||
uint8_t& i = whitelist.size;
|
|
||||||
|
|
||||||
for (i = 0; (i < other.capacity) && (i < whitelist.capacity); ++i) {
|
|
||||||
whitelist.addresses[i] = other.addresses[i];
|
|
||||||
DmDevWhiteListAdd(
|
|
||||||
(whitelist.addresses[i].type > 1) ? 0xFF : whitelist.addresses[i].type,
|
|
||||||
whitelist.addresses[i].address
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setAdvertisingPolicyMode(AdvertisingPolicyMode_t mode)
|
|
||||||
{
|
|
||||||
bool_t result = DmDevSetFilterPolicy(
|
|
||||||
DM_FILT_POLICY_MODE_ADV,
|
|
||||||
mode
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == false) {
|
|
||||||
return BLE_ERROR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
advertising_policy_mode = mode;
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gap::AdvertisingPolicyMode_t Gap::getAdvertisingPolicyMode(void) const
|
|
||||||
{
|
|
||||||
return advertising_policy_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setScanningPolicyMode(ScanningPolicyMode_t mode)
|
|
||||||
{
|
|
||||||
bool_t result = DmDevSetFilterPolicy(
|
|
||||||
DM_FILT_POLICY_MODE_SCAN,
|
|
||||||
mode
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == false) {
|
|
||||||
return BLE_ERROR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
scanning_policy_mode = mode;
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
Gap::ScanningPolicyMode_t Gap::getScanningPolicyMode(void) const
|
|
||||||
{
|
|
||||||
return scanning_policy_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::setInitiatorPolicyMode(InitiatorPolicyMode_t mode)
|
|
||||||
{
|
|
||||||
bool_t result = DmDevSetFilterPolicy(
|
|
||||||
DM_FILT_POLICY_MODE_INIT,
|
|
||||||
mode
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result == false) {
|
|
||||||
return BLE_ERROR_INVALID_STATE;
|
|
||||||
}
|
|
||||||
|
|
||||||
initiator_policy_mode = mode;
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gap::InitiatorPolicyMode_t Gap::getInitiatorPolicyMode(void) const
|
|
||||||
{
|
|
||||||
return initiator_policy_mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
ble_error_t Gap::reset(void)
|
|
||||||
{
|
|
||||||
this->::Gap::reset();
|
|
||||||
delete[] whitelist.addresses;
|
|
||||||
whitelist.addresses = NULL;
|
|
||||||
whitelist.size = 0;
|
|
||||||
whitelist.capacity = 0;
|
|
||||||
return BLE_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gap::Gap() :
|
|
||||||
::Gap(),
|
|
||||||
m_connectionHandle(DM_CONN_ID_NONE),
|
|
||||||
m_type(BLEProtocol::AddressType::RANDOM_STATIC),
|
|
||||||
m_addr(),
|
|
||||||
advertising_policy_mode(ADV_POLICY_IGNORE_WHITELIST),
|
|
||||||
scanning_policy_mode(SCAN_POLICY_IGNORE_WHITELIST),
|
|
||||||
initiator_policy_mode(INIT_POLICY_IGNORE_WHITELIST),
|
|
||||||
whitelist()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace cordio
|
|
||||||
} // namespace vendor
|
|
||||||
} // namespace ble
|
|
Loading…
Reference in New Issue