Caching the advertising data and the scan response.
Fork of MaximBLE by
Revision 0:b562096246b3, committed 2016-03-03
- Comitter:
- enginerd
- Date:
- Thu Mar 03 14:13:21 2016 +0000
- Child:
- 1:4e764337d5c5
- Commit message:
- Initial commit of Maxim Integrated Bluetooth LE Library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximBLE.cpp Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,321 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "mbed.h" +#include "us_ticker_api.h" +#include "MaximBLE.h" +#include "wsf_types.h" +#include "wsf_msg.h" +#include "wsf_os.h" +#include "wsf_buf.h" +#include "wsf_sec.h" +#include "wsf_timer.h" +#include "hci_handler.h" +#include "dm_handler.h" +#include "l2c_handler.h" +#include "att_handler.h" +#include "smp_handler.h" +#include "l2c_api.h" +#include "att_api.h" +#include "smp_api.h" +#include "hci_drv.h" +#include "hci_vs.h" + +/* Number of WSF buffer pools */ +#define WSF_BUF_POOLS 4 + +/*! Free memory for pool buffers. */ +static uint8_t mainBufMem[768]; + +/*! Default pool descriptor. */ +static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] = +{ + { 16, 8 }, + { 32, 4 }, + { 64, 2 }, + { 128, 2 } +}; + +/*! WSF handler ID */ +wsfHandlerId_t maximHandlerId; +static volatile int reset_complete; + +/* Current mbed SPI API does not support HW slave selects. Configured in HCI driver. */ +static DigitalOut _csn(HCI_CSN, 1); +static SPI _spi(HCI_MOSI, HCI_MISO, HCI_SCK); +static DigitalOut _rst(HCI_RST, 0); +static InterruptIn _irq(HCI_IRQ); + +/** + * The singleton which represents the MaximBLE transport for the BLE. + */ +static MaximBLE deviceInstance; + +/** + * BLE-API requires an implementation of the following function in order to + * obtain its transport handle. + */ +BLEInstanceBase *createBLEInstance(void) +{ + return (&deviceInstance); +} + +MaximBLE::MaximBLE(void) : initialized(false), instanceID(BLE::DEFAULT_INSTANCE) +{ +} + +MaximBLE::~MaximBLE(void) +{ +} + +const char *MaximBLE::getVersion(void) +{ + static char versionString[32]; + + strncpy(versionString, "unknown", sizeof(versionString)); + + return versionString; +} + +static void DmCback(dmEvt_t *pDmEvt) +{ + dmEvt_t *pMsg; + + if ((pMsg = (dmEvt_t*)WsfMsgAlloc(sizeof(dmEvt_t))) != NULL) + { + memcpy(pMsg, pDmEvt, sizeof(dmEvt_t)); + WsfMsgSend(maximHandlerId, pMsg); + } +} + +static void maximHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg) +{ + if (pMsg != NULL) + { + switch(pMsg->event) + { + case DM_RESET_CMPL_IND: + reset_complete = 1; + break; + case DM_ADV_START_IND: + break; + case DM_ADV_STOP_IND: + MaximGap::getInstance().advertisingStopped(); + break; + case DM_SCAN_REPORT_IND: + { + hciLeAdvReportEvt_t *scanReport = (hciLeAdvReportEvt_t*)pMsg; + MaximGap::getInstance().processAdvertisementReport( scanReport->addr, + scanReport->rssi, + (scanReport->eventType == DM_ADV_SCAN_RESPONSE) ? true : false, + (GapAdvertisingParams::AdvertisingType_t)scanReport->eventType, + scanReport->len, + scanReport->pData); + } + break; + case DM_CONN_OPEN_IND: + { + hciLeConnCmplEvt_t *connOpen = (hciLeConnCmplEvt_t*)pMsg; + MaximGap::getInstance().setConnectionHandle(connOpen->handle); + Gap::ConnectionParams_t params = { connOpen->connInterval, connOpen->connInterval, connOpen->connLatency, connOpen->supTimeout }; + Gap::AddressType_t ownAddrType; + Gap::Address_t ownAddr; + MaximGap::getInstance().getAddress(&ownAddrType, ownAddr); + MaximGap::getInstance().processConnectionEvent(connOpen->handle, + Gap::PERIPHERAL, + (Gap::AddressType_t)connOpen->addrType, + connOpen->peerAddr, + ownAddrType, + ownAddr, + ¶ms); + } + break; + case DM_CONN_CLOSE_IND: + { + hciDisconnectCmplEvt_t *connClose = (hciDisconnectCmplEvt_t*)pMsg; + MaximGap::getInstance().setConnectionHandle(DM_CONN_ID_NONE); + MaximGap::getInstance().processDisconnectionEvent(connClose->handle, (Gap::DisconnectionReason_t)connClose->reason); + } + break; + case DM_HW_ERROR_IND: + { + hciHwErrorEvt_t *error = (hciHwErrorEvt_t*)pMsg; + printf("HCI Hardware Error 0x%02x occurred\n", error->code); + } + break; + default: + break; + } + } +} + +static void AppServerConnCback(dmEvt_t *pDmEvt) +{ + dmConnId_t connId = (dmConnId_t)pDmEvt->hdr.param; + + switch (pDmEvt->hdr.event) + { + case DM_CONN_OPEN_IND: + /* set up CCC table with uninitialized (all zero) values */ + AttsCccInitTable(connId, NULL); + break; + case DM_CONN_CLOSE_IND: + /* clear CCC table on connection close */ + AttsCccClearTable(connId); + break; + default: + break; + } +} + +ble_error_t MaximBLE::init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> initCallback) +{ + wsfHandlerId_t handlerId; + + /* init OS subsystems */ + WsfTimerInit(1); + WsfBufInit(sizeof(mainBufMem), mainBufMem, WSF_BUF_POOLS, mainPoolDesc); + WsfSecInit(); + + /* init stack */ + handlerId = WsfOsSetNextHandler(HciHandler); + HciHandlerInit(handlerId); + + handlerId = WsfOsSetNextHandler(DmHandler); + DmAdvInit(); + DmScanInit(); + DmConnInit(); + DmConnSlaveInit(); + DmSecInit(); + DmHandlerInit(handlerId); + + handlerId = WsfOsSetNextHandler(L2cSlaveHandler); + L2cSlaveHandlerInit(handlerId); + L2cInit(); + L2cMasterInit(); + L2cSlaveInit(); + + handlerId = WsfOsSetNextHandler(AttHandler); + AttHandlerInit(handlerId); + AttsInit(); + AttsIndInit(); + AttcInit(); + + handlerId = WsfOsSetNextHandler(SmpHandler); + SmpHandlerInit(handlerId); + SmpiInit(); + SmprInit(); + + /* store handler ID */ + maximHandlerId = WsfOsSetNextHandler(maximHandler); + + /* init HCI */ + _irq.disable_irq(); + _irq.rise(hciDrvIsr); + _irq.fall(NULL); + hciDrvInit(HCI_CSN, HCI_RST, HCI_IRQ); + + /* Register for stack callbacks */ + DmRegister(DmCback); + DmConnRegister(DM_CLIENT_ID_APP, DmCback); + AttConnRegister(AppServerConnCback); + + /* Reset the device */ + reset_complete = 0; + DmDevReset(); + + while (!reset_complete) { + callDispatcher(); + } + + initialized = true; + BLE::InitializationCompleteCallbackContext context = { + BLE::Instance(instanceID), + BLE_ERROR_NONE + }; + initCallback.call(&context); + return BLE_ERROR_NONE; +} + +ble_error_t MaximBLE::shutdown(void) +{ + return BLE_ERROR_NOT_IMPLEMENTED; +} + +void MaximBLE::waitForEvent(void) +{ + static LowPowerTimeout nextTimeout; + timestamp_t nextTimestamp; + bool_t pTimerRunning; + + callDispatcher(); + + if (wsfOsReadyToSleep()) { + // setup an mbed timer for the next Wicentric timeout + nextTimestamp = (timestamp_t)WsfTimerNextExpiration(&pTimerRunning) * 1000; + if (pTimerRunning) { + nextTimeout.attach_us(timeoutCallback, nextTimestamp); + } + + // go to sleep + if (hciDrvReadyToSleep()) { + // go to deep sleep + deepsleep(); + hciDrvResume(); + } + else { + sleep(); + } + } +} + +void MaximBLE::timeoutCallback(void) +{ + // do nothing. just an interrupt for wake up. +} + +void MaximBLE::callDispatcher(void) +{ + static uint32_t lastTimeUs = us_ticker_read(); + uint32_t currTimeUs, deltaTimeMs; + + // Update the current Wicentric time + currTimeUs = us_ticker_read(); + deltaTimeMs = (currTimeUs - lastTimeUs) / 1000; + if (deltaTimeMs > 0) { + WsfTimerUpdate(deltaTimeMs); + lastTimeUs += deltaTimeMs * 1000; + } + + wsfOsDispatcher(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximBLE.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef _MAXIMBLE_H_ +#define _MAXIMBLE_H_ + +#include "ble/BLE.h" +#include "ble/blecommon.h" +#include "ble/BLEInstanceBase.h" + +#include "MaximGap.h" +#include "MaximGattServer.h" +#include "MaximGattClient.h" +#include "MaximSecurityManager.h" + +class MaximBLE : public BLEInstanceBase +{ +public: + MaximBLE(void); + virtual ~MaximBLE(void); + + virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> initCallback); + virtual bool hasInitialized(void) const { + return initialized; + } + virtual ble_error_t shutdown(void); + virtual const char *getVersion(void); + + virtual Gap &getGap() { + return MaximGap::getInstance(); + }; + virtual const Gap &getGap() const { + return MaximGap::getInstance(); + }; + virtual GattServer &getGattServer() { + return MaximGattServer::getInstance(); + }; + virtual const GattServer &getGattServer() const { + return MaximGattServer::getInstance(); + }; + virtual GattClient &getGattClient() { + return MaximGattClient::getInstance(); + }; + virtual SecurityManager &getSecurityManager() { + return MaximSecurityManager::getInstance(); + }; + virtual const SecurityManager &getSecurityManager() const { + return MaximSecurityManager::getInstance(); + }; + + virtual void waitForEvent(void); + +private: + bool initialized; + BLE::InstanceID_t instanceID; + + static void timeoutCallback(void); + void callDispatcher(void); +}; + +#endif /* _MAXIMBLE_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximGap.cpp Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,255 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "MaximGap.h" +#include "mbed.h" +#include "hci_vs.h" + +MaximGap &MaximGap::getInstance() { + static MaximGap m_instance; + return m_instance; +} + +ble_error_t MaximGap::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_DATA_LOC_ADV, advData.getPayloadLen(), (uint8_t*)advData.getPayload()); + DmAdvSetData(DM_DATA_LOC_SCAN, scanResponse.getPayloadLen(), (uint8_t*)scanResponse.getPayload()); + + return BLE_ERROR_NONE; +} + +ble_error_t MaximGap::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.getInterval() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) || + (params.getInterval() > GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MAX)) { + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + } else { + if ((params.getInterval() < GapAdvertisingParams::GAP_ADV_PARAMS_INTERVAL_MIN) || + (params.getInterval() > 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; + } + + DmAdvSetInterval(params.getInterval(), params.getInterval()); + DmAdvStart(params.getAdvertisingType(), params.getTimeout()); + + state.advertising = 1; + + return BLE_ERROR_NONE; +} + +ble_error_t MaximGap::stopAdvertising(void) +{ + DmAdvStop(); + + state.advertising = 0; + + return BLE_ERROR_NONE; +} + +void MaximGap::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); + } +} + +ble_error_t MaximGap::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 MaximGap::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 MaximGap::getPreferredConnectionParams(ConnectionParams_t *params) +{ + return BLE_ERROR_NOT_IMPLEMENTED; +} + +ble_error_t MaximGap::setPreferredConnectionParams(const ConnectionParams_t *params) +{ + return BLE_ERROR_NOT_IMPLEMENTED; +} + +ble_error_t MaximGap::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 MaximGap::startRadioScan(const GapScanningParams &scanningParams) +{ + DmScanSetInterval(scanningParams.getInterval(), scanningParams.getWindow()); + + 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(DM_DISC_MODE_NONE, scanType, TRUE, duration); + + return BLE_ERROR_NONE; +} + +ble_error_t MaximGap::stopScan(void) +{ + DmScanStop(); + return BLE_ERROR_NONE; +} + +void MaximGap::setConnectionHandle(uint16_t connectionHandle) +{ + m_connectionHandle = connectionHandle; +} + +uint16_t MaximGap::getConnectionHandle(void) +{ + return m_connectionHandle; +} + +ble_error_t MaximGap::setAddress(AddressType_t type, const Address_t address) +{ + if ((type != ADDR_TYPE_PUBLIC) && (type != ADDR_TYPE_RANDOM_STATIC)) { + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + + m_type = type; + HciVsSetPublicAddr((uint8_t*)address); + + return BLE_ERROR_NONE; +} + +ble_error_t MaximGap::getAddress(AddressType_t *typeP, Address_t address) +{ + *typeP = m_type; + BdaCpy(address, HciGetBdAddr()); + return BLE_ERROR_NONE; +} + +ble_error_t MaximGap::setDeviceName(const uint8_t *deviceName) +{ + return BLE_ERROR_NOT_IMPLEMENTED; +} + +ble_error_t MaximGap::getDeviceName(uint8_t *deviceName, unsigned *lengthP) +{ + return BLE_ERROR_NOT_IMPLEMENTED; +} + +ble_error_t MaximGap::setAppearance(GapAdvertisingData::Appearance appearance) +{ + return BLE_ERROR_NOT_IMPLEMENTED; +} + +ble_error_t MaximGap::getAppearance(GapAdvertisingData::Appearance *appearanceP) +{ + return BLE_ERROR_NOT_IMPLEMENTED; +} + +ble_error_t MaximGap::setTxPower(int8_t txPower) +{ + HciVsSetTxPower(txPower); + return BLE_ERROR_NONE; +} + +void MaximGap::getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP) +{ + static const int8_t permittedTxValues[] = { + -18, -15, -12, -9, -6, -3, 0, 3 + }; + + *valueArrayPP = permittedTxValues; + *countP = sizeof(permittedTxValues) / sizeof(int8_t); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximGap.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef _MAXIM_GAP_H_ +#define _MAXIM_GAP_H_ + +#include "mbed.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" + +/**************************************************************************/ +/*! + \brief + +*/ +/**************************************************************************/ +class MaximGap : public Gap +{ +public: + static MaximGap &getInstance(); + + /* Functions that must be implemented from Gap */ + virtual ble_error_t setAddress(AddressType_t type, const Address_t address); + virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address); + virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &); + + #define BLE_GAP_ADV_INTERVAL_MIN 0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */ + #define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */ + #define BLE_GAP_ADV_INTERVAL_MAX 0x4000 /**< Maximum Advertising interval in 625 us units, i.e. 10.24 s. */ + + virtual uint16_t getMinAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MIN; } + virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const { return BLE_GAP_ADV_NONCON_INTERVAL_MIN; } + virtual uint16_t getMaxAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MAX; } + + virtual ble_error_t startAdvertising(const GapAdvertisingParams &); + virtual ble_error_t stopAdvertising(void); + virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason); + virtual ble_error_t disconnect(DisconnectionReason_t reason); + + virtual ble_error_t setDeviceName(const uint8_t *deviceName); + virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP); + virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance); + virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP); + + virtual ble_error_t setTxPower(int8_t txPower); + virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP); + + void setConnectionHandle(uint16_t m_connectionHandle); + uint16_t getConnectionHandle(void); + + virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params); + virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params); + virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params); + + virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams); + virtual ble_error_t stopScan(void); + + void advertisingStopped(void); + +private: + uint16_t m_connectionHandle; + addr_type_t m_type; + MaximGap() { + m_connectionHandle = DM_CONN_ID_NONE; + m_type = ADDR_TYPE_RANDOM_STATIC; + } + + MaximGap(MaximGap const &); + void operator=(MaximGap const &); +}; + +#endif /* _MAXIM_GAP_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximGattClient.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef _MAXIM_GATT_CLIENT_H_ +#define _MAXIM_GATT_CLIENT_H_ + +#include <stddef.h> + +#include "ble/GattClient.h" + +class MaximGattClient : public GattClient +{ +public: + static MaximGattClient &getInstance() { + static MaximGattClient m_instance; + return m_instance; + } + +public: + MaximGattClient() { + /* empty */ + } + +private: + +}; + +#endif /* _MAXIM_GATT_CLIENT_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximGattServer.cpp Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,439 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#include "MaximGattServer.h" +#include "mbed.h" +#include "MaximGap.h" +#include "wsf_types.h" +#include "att_api.h" + +typedef struct mxmChar_s { + uint16_t descLen; + mxmChar_s() {} +} mxmChar_t; + +typedef struct mxmService_s mxmService_t; +struct mxmService_s { + uint16_t uuidLen; + mxmChar_t *chars; + attsGroup_t *attGroup; + mxmService_t *next; + mxmService_s() {} +}; + +static uint16_t currentHandle = 0x20; + +static UUID cccUUID(BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG); +static const uint16_t cccSize = sizeof(uint16_t); + +MaximGattServer &MaximGattServer::getInstance() { + static MaximGattServer m_instance; + return m_instance; +} + +ble_error_t MaximGattServer::addService(GattService &service) +{ + currentHandle = (currentHandle + 0xF) & ~0xF; + uint16_t startHandle = currentHandle; + + mxmService_t *mxmSvc = new mxmService_t; + + // Create WiCentric attribute group + mxmSvc->attGroup = new attsGroup_t; + + // Determine the attribute list length + unsigned int attListLen = 1; + for (int i = 0; i < service.getCharacteristicCount(); i++) { + attListLen += 2; + GattCharacteristic *p_char = service.getCharacteristic(i); + + if (p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) { + // add a CCCD + attListLen++; + } + } + + // Create WiCentric attribute list + mxmSvc->attGroup->pAttr = (attsAttr_t*)malloc(attListLen * sizeof(attsAttr_t));; + if (mxmSvc->attGroup->pAttr == NULL) { + return BLE_ERROR_BUFFER_OVERFLOW; + } + + // Create characteristics + mxmSvc->chars = new mxmChar_t [service.getCharacteristicCount()]; + + attsAttr_t *currAtt = mxmSvc->attGroup->pAttr; + + /* Service */ + currAtt->pUuid = attPrimSvcUuid; + if (service.getUUID().shortOrLong() == UUID::UUID_TYPE_LONG) { + mxmSvc->uuidLen = UUID::LENGTH_OF_LONG_UUID; + } else { + mxmSvc->uuidLen = sizeof(UUID::ShortUUIDBytes_t); + } + currAtt->pValue = (uint8_t*)malloc(mxmSvc->uuidLen); + memcpy(currAtt->pValue, service.getUUID().getBaseUUID(), mxmSvc->uuidLen); + currAtt->maxLen = mxmSvc->uuidLen; + currAtt->pLen = &mxmSvc->uuidLen; + currAtt->settings = 0; + currAtt->permissions = ATTS_PERMIT_READ; + + currAtt++; + + /* Add characteristics to the service */ + for (int i = 0; i < service.getCharacteristicCount(); i++) { + GattCharacteristic *p_char = service.getCharacteristic(i); + + /* Skip any incompletely defined, read-only characteristics. */ + if ((p_char->getValueAttribute().getValuePtr() == NULL) && + (p_char->getValueAttribute().getLength() == 0) && + (p_char->getProperties() == GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ)) { + continue; + } + + // Create Characteristic Attribute + currentHandle += 2; + currAtt->pUuid = attChUuid; + + p_char->getValueAttribute().setHandle(currentHandle); + mxmSvc->chars[i].descLen = 1 + sizeof(currentHandle) + p_char->getValueAttribute().getUUID().getLen(); + currAtt->pValue = (uint8_t*)malloc(mxmSvc->chars[i].descLen); + uint8_t *pValue = currAtt->pValue; + *pValue++ = p_char->getProperties(); + memcpy(pValue, ¤tHandle, sizeof(currentHandle)); + pValue += sizeof(currentHandle); + memcpy(pValue, p_char->getValueAttribute().getUUID().getBaseUUID(), p_char->getValueAttribute().getUUID().getLen()); + + currAtt->pLen = &mxmSvc->chars[i].descLen; + currAtt->maxLen = mxmSvc->chars[i].descLen; + currAtt->settings = 0; + currAtt->permissions = ATTS_PERMIT_READ; + currAtt++; + + // Create Value Attribute + currAtt->pUuid = p_char->getValueAttribute().getUUID().getBaseUUID(); + currAtt->pValue = p_char->getValueAttribute().getValuePtr(); + currAtt->pLen = p_char->getValueAttribute().getLengthPtr(); + currAtt->maxLen = p_char->getValueAttribute().getMaxLength(); + currAtt->settings = ATTS_SET_WRITE_CBACK | ATTS_SET_READ_CBACK; + if (p_char->getValueAttribute().getUUID().shortOrLong() == UUID::UUID_TYPE_LONG) { + currAtt->settings |= ATTS_SET_UUID_128; + } + currAtt->permissions = 0; + if (p_char->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ) { currAtt->permissions |= ATTS_PERMIT_READ; } + if (p_char->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE) { currAtt->permissions |= ATTS_PERMIT_WRITE; } + currAtt++; + + bool cccCreated = false; + + for (int i = 0; i < p_char->getDescriptorCount(); i++) { + GattAttribute *p_att = p_char->getDescriptor(i); + + currentHandle++; + + currAtt->pUuid = p_att->getUUID().getBaseUUID(); + currAtt->pValue = p_att->getValuePtr(); + currAtt->pLen = p_att->getLengthPtr(); + currAtt->maxLen = p_att->getMaxLength(); + currAtt->settings = 0; + currAtt->permissions = 0; + if (p_att->getUUID().shortOrLong() == UUID::UUID_TYPE_LONG) { + currAtt->settings |= ATTS_SET_UUID_128; + } + if (p_att->getUUID() == UUID(BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG)) { + cccCreated = true; + currAtt->settings |= ATTS_SET_CCC; + currAtt->permissions |= ATTS_PERMIT_READ; + currAtt->permissions |= ATTS_PERMIT_WRITE; + + if (cccCnt < MAX_CCC_CNT) { + cccSet[cccCnt].handle = currentHandle; + cccSet[cccCnt].valueRange = 0; + if (p_char->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { + cccSet[cccCnt].valueRange |= ATT_CLIENT_CFG_NOTIFY; + } + if (p_char->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE) { + cccSet[cccCnt].valueRange |= ATT_CLIENT_CFG_INDICATE; + } + cccSet[cccCnt].secLevel = DM_SEC_LEVEL_NONE; + cccHandles[cccCnt] = p_char->getValueAttribute().getHandle(); + cccCnt++; + } else { + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + } + currAtt++; + } + + if (!cccCreated && (p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE))) { + /* There was not a CCCD included in the descriptors, but this + * characteristic is notifiable and/or indicatable. A CCCD is + * required so create one now. + */ + if (cccCnt >= MAX_CCC_CNT) { + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + + currentHandle++; + + currAtt->pUuid = cccUUID.getBaseUUID(); + currAtt->pValue = (uint8_t*)&cccValues[cccCnt]; + currAtt->pLen = (uint16_t*)&cccSize; + currAtt->maxLen = sizeof(uint16_t); + currAtt->settings = ATTS_SET_CCC; + currAtt->permissions = (ATTS_PERMIT_READ | ATTS_PERMIT_WRITE); + + cccSet[cccCnt].handle = currentHandle; + cccSet[cccCnt].valueRange = 0; + if (p_char->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) { + cccSet[cccCnt].valueRange |= ATT_CLIENT_CFG_NOTIFY; + } + if (p_char->getProperties() & GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE) { + cccSet[cccCnt].valueRange |= ATT_CLIENT_CFG_INDICATE; + } + cccSet[cccCnt].secLevel = DM_SEC_LEVEL_NONE; + cccHandles[cccCnt] = p_char->getValueAttribute().getHandle(); + + cccCnt++; + currAtt++; + } + } + + mxmSvc->attGroup->pNext = NULL; + mxmSvc->attGroup->readCback = attsReadCback; + mxmSvc->attGroup->writeCback = attsWriteCback; + mxmSvc->attGroup->startHandle = startHandle; + mxmSvc->attGroup->endHandle = currentHandle; + AttsAddGroup(mxmSvc->attGroup); + + AttRegister(attCback); + AttsCccRegister(cccCnt, (attsCccSet_t*)cccSet, cccCback); + + return BLE_ERROR_NONE; +} + +ble_error_t MaximGattServer::read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *const lengthP) +{ + if (AttsGetAttr(attributeHandle, lengthP, &buffer) != ATT_SUCCESS) { + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + + return BLE_ERROR_NONE; +} + +ble_error_t MaximGattServer::read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP) +{ + // Check to see if this is a CCCD + uint8_t idx; + for (idx = 0; idx < cccCnt; idx++) { + if (attributeHandle == cccSet[idx].handle) { + if (connectionHandle == DM_CONN_ID_NONE) { // CCCDs are always 16 bits + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + *((uint16_t*)buffer) = AttsCccGet(connectionHandle, idx); + *lengthP = 2; // CCCDs are always 16 bits + return BLE_ERROR_NONE; + } + } + + // This is not a CCCD. Use the non-connection specific update method. + return read(attributeHandle, buffer, lengthP); +} + +ble_error_t MaximGattServer::write(GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly) +{ + uint16_t connectionHandle = MaximGap::getInstance().getConnectionHandle(); + + if (AttsSetAttr(attributeHandle, len, (uint8_t*)buffer) != ATT_SUCCESS) { + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + + if (!localOnly) { + if (connectionHandle != DM_CONN_ID_NONE) { + + // Check to see if this characteristic has a CCCD attribute + uint8_t idx; + for (idx = 0; idx < cccCnt; idx++) { + if (attributeHandle == cccHandles[idx]) { + break; + } + } + if (idx < cccCnt) { + // This characteristic has a CCCD attribute. Handle notifications and indications. + uint16_t cccEnabled = AttsCccEnabled(connectionHandle, idx); + if (cccEnabled & ATT_CLIENT_CFG_NOTIFY) { + AttsHandleValueNtf(connectionHandle, attributeHandle, len, (uint8_t*)buffer); + } + if (cccEnabled & ATT_CLIENT_CFG_INDICATE) { + AttsHandleValueInd(connectionHandle, attributeHandle, len, (uint8_t*)buffer); + } + } + } + } + + return BLE_ERROR_NONE; +} + +ble_error_t MaximGattServer::write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, const uint8_t buffer[], uint16_t len, bool localOnly) +{ + // Check to see if this is a CCCD + uint8_t idx; + for (idx = 0; idx < cccCnt; idx++) { + if (attributeHandle == cccSet[idx].handle) { + if ((connectionHandle == DM_CONN_ID_NONE) || (len != 2)) { // CCCDs are always 16 bits + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + AttsCccSet(connectionHandle, idx, *((uint16_t*)buffer)); + return BLE_ERROR_NONE; + } + } + + // This is not a CCCD. Use the non-connection specific update method. + return write(attributeHandle, buffer, len, localOnly); +} + +ble_error_t MaximGattServer::areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP) +{ + uint16_t connectionHandle = MaximGap::getInstance().getConnectionHandle(); + + if (connectionHandle != DM_CONN_ID_NONE) { + uint8_t idx; + for (idx = 0; idx < cccCnt; idx++) { + if (characteristic.getValueHandle() == cccHandles[idx]) { + uint16_t cccValue = AttsCccGet(connectionHandle, idx); + if (cccValue & ATT_CLIENT_CFG_NOTIFY) { + *enabledP = true; + } else { + *enabledP = false; + } + return BLE_ERROR_NONE; + } + } + } + + return BLE_ERROR_PARAM_OUT_OF_RANGE; +} + +ble_error_t MaximGattServer::areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP) +{ + if (connectionHandle != DM_CONN_ID_NONE) { + uint8_t idx; + for (idx = 0; idx < cccCnt; idx++) { + if (characteristic.getValueHandle() == cccHandles[idx]) { + uint16_t cccValue = AttsCccGet(connectionHandle, idx); + if (cccValue & ATT_CLIENT_CFG_NOTIFY) { + *enabledP = true; + } else { + *enabledP = false; + } + return BLE_ERROR_NONE; + } + } + } + + return BLE_ERROR_PARAM_OUT_OF_RANGE; +} + +void MaximGattServer::cccCback(attsCccEvt_t *pEvt) +{ + if (pEvt->value & (ATT_CLIENT_CFG_NOTIFY | ATT_CLIENT_CFG_INDICATE)) { + getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, pEvt->handle); + } else { + getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, pEvt->handle); + } +} + +void MaximGattServer::attCback(attEvt_t *pEvt) +{ + if (pEvt->hdr.status == ATT_SUCCESS) { + getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_SENT, pEvt->handle); + } +} + +uint8_t MaximGattServer::attsReadCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, attsAttr_t *pAttr) +{ + GattReadCallbackParams cbParams = { + .connHandle = connId, + .handle = handle, + .offset = offset, + .len = *pAttr->pLen, + .data = pAttr->pValue + }; + getInstance().handleDataReadEvent(&cbParams); + + return ATT_SUCCESS; +} + +uint8_t MaximGattServer::attsWriteCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, uint16_t len, uint8_t *pValue, attsAttr_t *pAttr) +{ + uint8_t err; + + /* TODO: offset is not handled properly */ + if ((err = AttsSetAttr(handle, len, pValue)) != ATT_SUCCESS) { + return err; + } + + GattWriteCallbackParams::WriteOp_t writeOp; + switch (operation) { + case ATT_PDU_WRITE_REQ: + writeOp = GattWriteCallbackParams::OP_WRITE_REQ; + break; + case ATT_PDU_WRITE_CMD: + writeOp = GattWriteCallbackParams::OP_WRITE_CMD; + break; + case ATT_PDU_SIGNED_WRITE_CMD: + writeOp = GattWriteCallbackParams::OP_SIGN_WRITE_CMD; + break; + case ATT_PDU_PREP_WRITE_REQ: + writeOp = GattWriteCallbackParams::OP_PREP_WRITE_REQ; + break; + case ATT_PDU_EXEC_WRITE_REQ: + writeOp = GattWriteCallbackParams::OP_EXEC_WRITE_REQ_NOW; + break; + default: + writeOp = GattWriteCallbackParams::OP_INVALID; + break; + } + + GattWriteCallbackParams cbParams = { + .connHandle = connId, + .handle = handle, + .writeOp = writeOp, + .offset = offset, + .len = len, + .data = pValue + }; + getInstance().handleDataWrittenEvent(&cbParams); + + return ATT_SUCCESS; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximGattServer.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef _MAXIM_GATT_SERVER_H_ +#define _MAXIM_GATT_SERVER_H_ + +#include <stddef.h> + +#include "ble/blecommon.h" +#include "ble/GattServer.h" +#include "wsf_types.h" +#include "att_api.h" + +class MaximGattServer : public GattServer +{ +public: + static MaximGattServer &getInstance(); + + /* Functions that must be implemented from GattServer */ + virtual ble_error_t addService(GattService &); + + virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); + virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); + virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); + virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); + + virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP); + virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP); + + virtual bool isOnDataReadAvailable() const { return true; } + +private: + static void cccCback(attsCccEvt_t *pEvt); + static void attCback(attEvt_t *pEvt); + static uint8_t attsReadCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, attsAttr_t *pAttr); + static uint8_t attsWriteCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, uint16_t len, uint8_t *pValue, attsAttr_t *pAttr); + + /*! client characteristic configuration descriptors settings */ + #define MAX_CCC_CNT 20 + attsCccSet_t cccSet[MAX_CCC_CNT]; + uint16_t cccValues[MAX_CCC_CNT]; + uint16_t cccHandles[MAX_CCC_CNT]; + uint8_t cccCnt; + +private: + MaximGattServer() : GattServer(), cccSet(), cccValues(), cccHandles(), cccCnt(0) { + /* empty */ + } + + MaximGattServer(const MaximGattServer &); + const MaximGattServer& operator=(const MaximGattServer &); +}; + +#endif /* _MAXIM_GATT_SERVER_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MaximSecurityManager.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES + * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name of Maxim Integrated + * Products, Inc. shall not be used except as stated in the Maxim Integrated + * Products, Inc. Branding Policy. + * + * The mere transfer of this software does not imply any licenses + * of trade secrets, proprietary technology, copyrights, patents, + * trademarks, maskwork rights, or any other form of intellectual + * property whatsoever. Maxim Integrated Products, Inc. retains all + * ownership rights. + ******************************************************************************* + */ + +#ifndef _MAXIM_SECURITY_MANAGER_H_ +#define _MAXIM_SECURITY_MANAGER_H_ + +#include <stddef.h> + +#include "ble/SecurityManager.h" + +class MaximSecurityManager : public SecurityManager +{ +public: + static MaximSecurityManager &getInstance() { + static MaximSecurityManager m_instance; + return m_instance; + } + +public: + MaximSecurityManager() { + /* empty */ + } +}; + +#endif /* _MAXIM_SECURITY_MANAGER_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/LES-PRE-20767-ARM-Permissive-Binary-License.txt Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,49 @@ +Permissive Binary License + +Copyright (c) 2016, ARM, Ltd. All rights reserved. + +Redistribution. Redistribution and use in binary form, without +modification, are permitted provided that the following conditions are +met: + +1) Redistributions must reproduce the above copyright notice and the + following disclaimer in the documentation and/or other materials + provided with the distribution. + +2) Unless to the extent explicitly permitted by law, no reverse + engineering, decompilation, or disassembly of this software is + permitted. + +3) Redistribution as part of a software development kit must include the + accompanying file named DEPENDENCIES and any dependencies listed in + that file. + +4) Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +Limited patent license. The copyright holders (and contributors) grant a +worldwide, non-exclusive, no-charge, royalty-free patent license to +make, have made, use, offer to sell, sell, import, and otherwise +transfer this software, where such license applies only to those patent +claims licensable by the copyright holders (and contributors) that are +necessarily infringed by this software. This patent license shall not +apply to any combinations that include this software. No hardware is +licensed hereunder. + +If you institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the software +itself infringes your patent(s), then your rights granted under this +license shall terminate as of the date such litigation is filed. + +DISCLAIMER. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND +CONTRIBUTORS "AS IS." ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT +NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED +TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/hci/maxwsn/hci_drv.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,114 @@ +/*************************************************************************************************/ +/*! + * \file hci_drv.h + * + * \brief HCI driver interface. + * + * $Date: 2013-01-02 22:19:17 -0800 (Wed, 02 Jan 2013) $ + * $Revision: 405 $ + * + * Copyright (c) 2012-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef HCI_DRV_H +#define HCI_DRV_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "PinNames.h" + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn hciDrvInit + * + * \brief Initialize the driver. + * + * \param csn name of the pin connected to CSN + * \param irq name of the pin conntected to IRQ + */ +/*************************************************************************************************/ +void hciDrvInit(PinName csn, PinName rst, PinName irq); + +/*************************************************************************************************/ +/*! + * \fn hciDrvWrite + * + * \brief Write data to the driver. + * + * \param type HCI packet type + * \param len Number of bytes to write. + * \param pData Byte array to write. + * + * \return Return actual number of data bytes written. + * + * \note The type parameter allows the driver layer to prepend the data with a header on the + * same write transaction. + */ +/*************************************************************************************************/ +uint16_t hciDrvWrite(uint8_t type, uint16_t len, uint8_t *pData); + +/*************************************************************************************************/ +/*! + * \fn hciDrvRead + * + * \brief Read data bytes from the driver. + * + * \param len Number of bytes to read. + * \param pData Byte array to store data. + * + * \return Return actual number of data bytes read. + */ +/*************************************************************************************************/ +uint16_t hciDrvRead(uint16_t len, uint8_t *pData, bool_t last); + +/*************************************************************************************************/ +/*! + * \fn hciDrvIsr + * + * \brief Interrupt service routine for IRQ + */ +/*************************************************************************************************/ +void hciDrvIsr(void); + +/*************************************************************************************************/ +/*! + * \fn hciDrvReadyToSleep + * + * \brief Returns TRUE if driver allows MCU to enter low power sleep mode. + * + * \return TRUE if ready to sleep, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t hciDrvReadyToSleep(void); + +void hciDrvResume(void); + +/*************************************************************************************************/ +/*! + * \fn hciDrvReset + * + * \brief Resets the controller + */ +/*************************************************************************************************/ +void hciDrvReset(void); + +#ifdef __cplusplus +}; +#endif + +#endif /* HCI_DRV_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/hci/maxwsn/hci_vs.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,59 @@ +/*************************************************************************************************/ +/*! + * \file hci_drv.h + * + * \brief HCI vendor specific functions for EM Microelectronic. + * + * $Date: 2013-01-02 22:19:17 -0800 (Wed, 02 Jan 2013) $ + * $Revision: 405 $ + * + * Copyright (c) 2012-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef HCI_VS_H +#define HCI_VS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*************************************************************************************************/ +/*! + * \fn HciVsSetPublicAddr + * + * \brief Vendor-specific set public address function. + * + * \param param public address + * + * \return None. + */ +/*************************************************************************************************/ +void HciVsSetPublicAddr(uint8_t *bdAddr); + +/*************************************************************************************************/ +/*! + * \fn HciVsSetTxPower + * + * \brief Vendor-specific set RF output power function + * + * \param param output power in dB + * + * \return None. + */ +/*************************************************************************************************/ +void HciVsSetTxPower(int txPower); + +#ifdef __cplusplus +}; +#endif + +#endif /* HCI_VS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/cfg/cfg_stack.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,71 @@ +/*************************************************************************************************/ +/*! + * \file cfg_stack.h + * + * \brief Stack configuration. + * + * $Date: 2011-10-14 21:35:03 -0700 (Fri, 14 Oct 2011) $ + * $Revision: 191 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + + */ +/*************************************************************************************************/ +#ifndef CFG_STACK_H +#define CFG_STACK_H + + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + HCI +**************************************************************************************************/ + +/*! Vendor specific targets */ +#define HCI_VS_GENERIC 0 +#define HCI_VS_EMM 1 + +/*! Vendor specific target configuration */ +#ifndef HCI_VS_TARGET +#define HCI_VS_TARGET HCI_VS_GENERIC +#endif + +/************************************************************************************************** + DM +**************************************************************************************************/ + +/*! Maximum number of connections */ +#ifndef DM_CONN_MAX +#define DM_CONN_MAX 3 +#endif + +/************************************************************************************************** + L2C +**************************************************************************************************/ + +/************************************************************************************************** + ATT +**************************************************************************************************/ + +/************************************************************************************************** + SMP +**************************************************************************************************/ + + + +#ifdef __cplusplus +}; +#endif + +#endif /* CFG_STACK_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/att_api.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,942 @@ +/*************************************************************************************************/ +/*! + * \file att_api.h + * + * \brief Attribute protocol client and server API. + * + * $Date: 2012-05-07 19:54:28 -0700 (Mon, 07 May 2012) $ + * $Revision: 315 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef ATT_API_H +#define ATT_API_H + +#include "wsf_timer.h" +#include "att_defs.h" +#include "att_uuid.h" +#include "dm_api.h" +#include "cfg_stack.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! ATT server attribute settings */ +#define ATTS_SET_UUID_128 0x01 /*! Set if the UUID is 128 bits in length */ +#define ATTS_SET_WRITE_CBACK 0x02 /*! Set if the group callback is executed when + this attribute is written by a client device */ +#define ATTS_SET_READ_CBACK 0x04 /*! Set if the group callback is executed when + this attribute is read by a client device */ +#define ATTS_SET_VARIABLE_LEN 0x08 /*! Set if the attribute has a variable length */ +#define ATTS_SET_ALLOW_OFFSET 0x10 /*! Set if writes are allowed with an offset */ +#define ATTS_SET_CCC 0x20 /*! Set if the attribute is a client characteristic + configuration descriptor */ +#define ATTS_SET_ALLOW_SIGNED 0x40 /*! Set if signed writes are allowed */ +#define ATTS_SET_REQ_SIGNED 0x80 /*! Set if signed writes are required if link + is not encrypted */ + +/*! ATT server attribute permissions */ +#define ATTS_PERMIT_READ 0x01 /*! Set if attribute can be read */ +#define ATTS_PERMIT_READ_AUTH 0x02 /*! Set if attribute read requires authentication */ +#define ATTS_PERMIT_READ_AUTHORIZ 0x04 /*! Set if attribute read requires authorization */ +#define ATTS_PERMIT_READ_ENC 0x08 /*! Set if attribute read requires encryption */ +#define ATTS_PERMIT_WRITE 0x10 /*! Set if attribute can be written */ +#define ATTS_PERMIT_WRITE_AUTH 0x20 /*! Set if attribute write requires authentication */ +#define ATTS_PERMIT_WRITE_AUTHORIZ 0x40 /*! Set if attribute write requires authorization */ +#define ATTS_PERMIT_WRITE_ENC 0x80 /*! Set if attribute write requires encryption */ + +/*! ATT client characteristic discovery and configuration settings */ +#define ATTC_SET_UUID_128 0x01 /*! Set if the UUID is 128 bits in length */ +#define ATTC_SET_REQUIRED 0x02 /*! Set if characteristic must be discovered */ +#define ATTC_SET_DESCRIPTOR 0x04 /*! Set if this is a characteristic descriptor */ + +/*! ATT callback events */ +#define ATT_CBACK_START 0x02 /*! ATT callback event starting value */ +enum /*! Internal note: event values match method values */ +{ + /*! ATT client callback events */ + ATTC_FIND_INFO_RSP = ATT_CBACK_START, /*! Find information response */ + ATTC_FIND_BY_TYPE_VALUE_RSP, /*! Find by type value response */ + ATTC_READ_BY_TYPE_RSP, /*! Read by type value response */ + ATTC_READ_RSP, /*! Read response */ + ATTC_READ_LONG_RSP, /*! Read long response */ + ATTC_READ_MULTIPLE_RSP, /*! Read multiple response */ + ATTC_READ_BY_GROUP_TYPE_RSP, /*! Read group type response */ + ATTC_WRITE_RSP, /*! Write response */ + ATTC_WRITE_CMD_RSP, /*! Write command response */ + ATTC_PREPARE_WRITE_RSP, /*! Prepare write response */ + ATTC_EXECUTE_WRITE_RSP, /*! Execute write response */ + ATTC_HANDLE_VALUE_NTF, /*! Handle value notification */ + ATTC_HANDLE_VALUE_IND, /*! Handle value indication */ + /*! ATT server callback events */ + ATTS_HANDLE_VALUE_CNF, /*! Handle value confirmation */ + ATTS_CCC_STATE_IND /*! Client chracteristic configuration state change */ +}; + +/*! ATT callback events */ +#define ATT_CBACK_END ATTS_CCC_STATE_IND /*! ATT callback event ending value */ + +/*! Base value for HCI error status values passed through ATT */ +#define ATT_HCI_ERR_BASE 0x20 + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Configurable parameters */ +typedef struct +{ + wsfTimerTicks_t discIdleTimeout; /*! ATT server service discovery connection idle timeout in seconds */ + uint16_t mtu; /*! desired ATT MTU */ + uint8_t transTimeout; /*! transcation timeout in seconds */ + uint8_t numPrepWrites; /*! number of queued prepare writes supported by server */ +} attCfg_t; + +/*! + * Attribute server data types + */ + +/*! Attribute structure */ +typedef struct +{ + uint8_t const *pUuid; /*! Pointer to the attributes UUID */ + uint8_t *pValue; /*! Pointer to the attributes value */ + uint16_t *pLen; /*! Pointer to the length of the attributes value */ + uint16_t maxLen; /*! Maximum length of attributes value */ + uint8_t settings; /*! Attribute settings */ + uint8_t permissions; /*! Attribute permissions */ +} attsAttr_t; + +/*! Attribute group read callback */ +typedef uint8_t (*attsReadCback_t)(dmConnId_t connId, uint16_t handle, uint8_t operation, + uint16_t offset, attsAttr_t *pAttr); + +/*! Attribute group write callback */ +typedef uint8_t (*attsWriteCback_t)(dmConnId_t connId, uint16_t handle, uint8_t operation, + uint16_t offset, uint16_t len, uint8_t *pValue, + attsAttr_t *pAttr); + +/*! Attribute group */ +typedef struct attsGroup_tag +{ + struct attsGroup_tag *pNext; /*! For internal use only */ + attsAttr_t *pAttr; /*! Pointer to attribute list for this group */ + attsReadCback_t readCback; /*! Read callback function */ + attsWriteCback_t writeCback; /*! Write callback function */ + uint16_t startHandle; /*! The handle of the first attribute in this group */ + uint16_t endHandle; /*! The handle of the last attribute in this group */ +} attsGroup_t; + +/*! Client characteristc configuration settings */ +typedef struct +{ + uint16_t handle; /*! Client characteristc configuration descriptor handle */ + uint16_t valueRange; /*! Acceptable value range of the descriptor value */ + uint8_t secLevel; /*! Security level of characteristic value */ +} attsCccSet_t; + +/*! ATT client structure for characteristic and descriptor discovery */ +typedef struct attcDiscChar_tag +{ + uint8_t const *pUuid; /*! Pointer to UUID */ + uint8_t settings; /*! Characteristic discovery settings */ +} attcDiscChar_t; + +/*! ATT client structure for characteristic and descriptor configuration */ +typedef struct +{ + uint8_t const *pValue; /*! Pointer to default value or NULL */ + uint8_t valueLen; /*! Default value length */ + uint8_t hdlIdx; /*! Index of its handle in handle list */ +} attcDiscCfg_t; + +/*! ATT client discovery control block */ +typedef struct +{ + attcDiscChar_t **pCharList; /*! Characterisic list for discovery */ + uint16_t *pHdlList; /*! Characteristic handle list */ + attcDiscCfg_t *pCfgList; /*! Characterisic list for configuration */ + uint8_t charListLen; /*! Characteristic and handle list length */ + uint8_t cfgListLen; /*! Configuration list length */ + + /* the following are for internal use only */ + uint16_t svcStartHdl; + uint16_t svcEndHdl; + uint8_t charListIdx; + uint8_t endHdlIdx; +} attcDiscCb_t; + +/*! + * ATT callback parameters: + * + * \param hdr.event Callback event + * \param hdr.param DM connection ID + * \param hdr.status Event status: ATT_SUCCESS or error status + * \param pValue Pointer to value data, valid if valueLen > 0 + * \param valueLen Length of value data + * \param handle Attribute handle + */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header structure */ + uint8_t *pValue; /*! Value */ + uint16_t valueLen; /*! Value length */ + uint16_t handle; /*! Attribute handle */ + bool_t continuing; /*! TRUE if more response packets expected */ +} attEvt_t; + +/*! ATTS client characteristic configuration callback structure */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header structure */ + uint16_t handle; /*! CCCD handle */ + uint16_t value; /*! CCCD value */ + uint8_t idx; /*! CCCD settings index */ +} attsCccEvt_t; + +/*! ATT callback type */ +typedef void (*attCback_t)(attEvt_t *pEvt); + +/*! ATTS authorization callback type */ +typedef uint8_t (*attsAuthorCback_t)(dmConnId_t connId, uint8_t permit, uint16_t handle); + +/*! ATTS client characteristic configuration callback */ +typedef void (*attsCccCback_t)(attsCccEvt_t *pEvt); + +/************************************************************************************************** + Global Variables +**************************************************************************************************/ + +/*! Configuration pointer */ +extern attCfg_t *pAttCfg; + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn AttRegister + * + * \brief Register a callback with ATT. + * + * \param cback Client callback function. + * + * \return None. + */ +/*************************************************************************************************/ +void AttRegister(attCback_t cback); + +/*************************************************************************************************/ +/*! + * \fn AttConnRegister + * + * \brief Register a connection callback with ATT. The callback is typically used to + * manage the attribute server database. + * + * \param cback Client callback function. + * + * \return None. + */ +/*************************************************************************************************/ +void AttConnRegister(dmCback_t cback); + + +/*************************************************************************************************/ +/*! + * \fn AttGetMtu + * + * \brief Get the attribute protocol MTU of a connection. + * + * \param connId DM connection ID. + * + * \return MTU of the connection. + */ +/*************************************************************************************************/ +uint16_t AttGetMtu(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn AttsInit + * + * \brief Initialize ATT server. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsInit(void); + +/*************************************************************************************************/ +/*! + * \fn AttsIndInit + * + * \brief Initialize ATT server for indications/notifications. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsIndInit(void); + +/*************************************************************************************************/ +/*! + * \fn AttsSignInit + * + * \brief Initialize ATT server for data signing. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsSignInit(void); + +/*************************************************************************************************/ +/*! + * \fn AttsAuthorRegister + * + * \brief Register an authorization callback with the attribute server. + * + * \param cback Client callback function. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsAuthorRegister(attsAuthorCback_t cback); + +/*************************************************************************************************/ +/*! + * \fn AttsAddGroup + * + * \brief Add an attribute group to the attribute server. + * + * \param pGroup Pointer to an attribute group structure. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsAddGroup(attsGroup_t *pGroup); + +/*************************************************************************************************/ +/*! + * \fn AttsRemoveGroup + * + * \brief Remove an attribute group from the attribute server. + * + * \param startHandle Start handle of attribute group to be removed. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsRemoveGroup(uint16_t startHandle); + +/*************************************************************************************************/ +/*! + * \fn AttsSetAttr + * + * \brief Set an attribute value in the attribute server. + * + * \param handle Attribute handle. + * \param valueLen Attribute length. + * \param pValue Attribute value. + * + * \return ATT_SUCCESS if successful otherwise error. + */ +/*************************************************************************************************/ +uint8_t AttsSetAttr(uint16_t handle, uint16_t valueLen, uint8_t *pValue); + +/*************************************************************************************************/ +/*! + * \fn AttsGetAttr + * + * \brief Get an attribute value in the attribute server. + * + * \param handle Attribute handle. + * \param pLen Returned attribute length pointer. + * \param pValue Returned attribute value pointer. + * + * \return ATT_SUCCESS if successful otherwise error. + * \return This function returns the attribute length in pLen and a pointer to the attribute + * value in pValue. + */ +/*************************************************************************************************/ +uint8_t AttsGetAttr(uint16_t handle, uint16_t *pLen, uint8_t **pValue); + +/*************************************************************************************************/ +/*! + * \fn AttsHandleValueInd + * + * \brief Send an attribute protocol Handle Value Indication. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * \param valueLen Length of value data. + * \param pValue Pointer to value data. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsHandleValueInd(dmConnId_t connId, uint16_t handle, uint16_t valueLen, uint8_t *pValue); + +/*************************************************************************************************/ +/*! + * \fn AttsHandleValueNtf + * + * \brief Send an attribute protocol Handle Value Notification. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * \param valueLen Length of value data. + * \param pValue Pointer to value data. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsHandleValueNtf(dmConnId_t connId, uint16_t handle, uint16_t valueLen, uint8_t *pValue); + +/*************************************************************************************************/ +/*! + * \fn AttsCccRegister + * + * \brief Register the utility service for managing client characteristic + * configuration descriptors. This function is typically called once on + * system initialization. + * + * \param setLen Length of settings array. + * \param pSet Array of CCC descriptor settings. + * \param cback Client callback function. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsCccRegister(uint8_t setLen, attsCccSet_t *pSet, attsCccCback_t cback); + +/*************************************************************************************************/ +/*! + * \fn AttsCccInitTable + * + * \brief Initialize the client characteristic configuration descriptor value table for a + * connection. The table is initialized with the values from pCccTbl. If pCccTbl + * is NULL the table will be initialized to zero. + * + * This function must be called when a connection is established or when a + * device is bonded. + * + * \param connId DM connection ID. + * \param pCccTbl Pointer to the descriptor value array. The length of the array + * must equal the value of setLen passed to AttsCccRegister(). + * + * \return None. + */ +/*************************************************************************************************/ +void AttsCccInitTable(dmConnId_t connId, uint16_t *pCccTbl); + +/*************************************************************************************************/ +/*! + * \fn AttsCccClearTable + * + * \brief Clear and deallocate the client characteristic configuration descriptor value + * table for a connection. This function must be called when a connection is closed. + * + * \param connId DM connection ID. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsCccClearTable(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn AttsCccGet + * + * \brief Get the value of a client characteristic configuration descriptor by its index. + * If not found, return zero. + * + * \param connId DM connection ID. + * \param idx Index of descriptor in CCC descriptor handle table. + * + * \return Value of the descriptor. + */ +/*************************************************************************************************/ +uint16_t AttsCccGet(dmConnId_t connId, uint8_t idx); + +/*************************************************************************************************/ +/*! + * \fn AttsCccSet + * + * \brief Set the value of a client characteristic configuration descriptor by its index. + * + * \param connId DM connection ID. + * \param idx Index of descriptor in CCC descriptor handle table. + * \param value Value of the descriptor. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsCccSet(dmConnId_t connId, uint8_t idx, uint16_t value); + +/*************************************************************************************************/ +/*! + * \fn AttsCccEnabled + * + * \brief Check if a client characteristic configuration descriptor is enabled and if + * the characteristic's security level has been met. + * + * \param connId DM connection ID. + * \param idx Index of descriptor in CCC descriptor handle table. + * + * \return Value of the descriptor if security level is met, otherwise zero. + */ +/*************************************************************************************************/ +uint16_t AttsCccEnabled(dmConnId_t connId, uint8_t idx); + +/*************************************************************************************************/ +/*! + * \fn AttsSetCsrk + * + * \brief Set the peer's data signing key on this connection. This function + * is typically called from the ATT connection callback when the connection is + * established. The caller is responsible for maintaining the memory that + * contains the key. + * + * \param connId DM connection ID. + * \param pCsrk Pointer to data signing key (CSRK). + * + * \return None. + */ +/*************************************************************************************************/ +void AttsSetCsrk(dmConnId_t connId, uint8_t *pCsrk); + +/*************************************************************************************************/ +/*! + * \fn AttsSetSignCounter + * + * \brief Set the peer's sign counter on this connection. This function + * is typically called from the ATT connection callback when the connection is + * established. ATT maintains the value of the sign counter internally and + * sets the value when a signed packet is successfully received. + * + * \param connId DM connection ID. + * \param signCounter Sign counter. + * + * \return None. + */ +/*************************************************************************************************/ +void AttsSetSignCounter(dmConnId_t connId, uint32_t signCounter); + +/*************************************************************************************************/ +/*! + * \fn AttsGetSignCounter + * + * \brief Get the current value peer's sign counter on this connection. This function + * is typically called from the ATT connection callback when the connection is + * closed so the application can store the sign counter for use on future + * connections. + * + * \param connId DM connection ID. + * + * \return Sign counter. + */ +/*************************************************************************************************/ +uint32_t AttsGetSignCounter(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn AttcInit + * + * \brief Initialize ATT client. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcInit(void); + +/*************************************************************************************************/ +/*! + * \fn AttcSignInit + * + * \brief Initialize ATT client for data signing. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcSignInit(void); + +/*************************************************************************************************/ +/*! + * \fn AttcFindInfoReq + * + * \brief Initiate an attribute protocol Find Information Request. + * + * \param connId DM connection ID. + * \param startHandle Attribute start handle. + * \param endHandle Attribute end handle. + * \param continuing TRUE if ATTC continues sending requests until complete. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcFindInfoReq(dmConnId_t connId, uint16_t startHandle, uint16_t endHandle, bool_t continuing); + +/*************************************************************************************************/ +/*! + * \fn AttcFindByTypeValueReq + * + * \brief Initiate an attribute protocol Find By Type Value Request. + * + * \param connId DM connection ID. + * \param startHandle Attribute start handle. + * \param endHandle Attribute end handle. + * \param uuid16 16-bit UUID to find. + * \param valueLen Length of value data. + * \param pValue Pointer to value data. + * \param continuing TRUE if ATTC continues sending requests until complete. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcFindByTypeValueReq(dmConnId_t connId, uint16_t startHandle, uint16_t endHandle, + uint16_t uuid16, uint16_t valueLen, uint8_t *pValue, bool_t continuing); + +/*************************************************************************************************/ +/*! + * \fn AttcReadByTypeReq + * + * \brief Initiate an attribute protocol Read By Type Request. + * + * \param connId DM connection ID. + * \param startHandle Attribute start handle. + * \param endHandle Attribute end handle. + * \param uuidLen Length of UUID (2 or 16). + * \param pUuid Pointer to UUID data. + * \param continuing TRUE if ATTC continues sending requests until complete. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcReadByTypeReq(dmConnId_t connId, uint16_t startHandle, uint16_t endHandle, + uint8_t uuidLen, uint8_t *pUuid, bool_t continuing); + +/*************************************************************************************************/ +/*! + * \fn AttcReadReq + * + * \brief Initiate an attribute protocol Read Request. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcReadReq(dmConnId_t connId, uint16_t handle); + +/*************************************************************************************************/ +/*! + * \fn AttcReadLongReq + * + * \brief Initiate an attribute protocol Read Long Request. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * \param offset Read attribute data starting at this offset. + * \param continuing TRUE if ATTC continues sending requests until complete. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcReadLongReq(dmConnId_t connId, uint16_t handle, uint16_t offset, bool_t continuing); + +/*************************************************************************************************/ +/*! + * \fn AttcReadMultipleReq + * + * \brief Initiate an attribute protocol Read Multiple Request. + * + * \param connId DM connection ID. + * \param numHandles Number of handles in attribute handle list. + * \param pHandles List of attribute handles. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcReadMultipleReq(dmConnId_t connId, uint8_t numHandles, uint16_t *pHandles); + +/*************************************************************************************************/ +/*! + * \fn AttcReadByGroupTypeReq + * + * \brief Initiate an attribute protocol Read By Group Type Request. + * + * \param connId DM connection ID. + * \param startHandle Attribute start handle. + * \param endHandle Attribute end handle. + * \param uuidLen Length of UUID (2 or 16). + * \param pUuid Pointer to UUID data. + * \param continuing TRUE if ATTC continues sending requests until complete. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcReadByGroupTypeReq(dmConnId_t connId, uint16_t startHandle, uint16_t endHandle, + uint8_t uuidLen, uint8_t *pUuid, bool_t continuing); + +/*************************************************************************************************/ +/*! + * \fn AttcWriteReq + * + * \brief Initiate an attribute protocol Write Request. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * \param valueLen Length of value data. + * \param pValue Pointer to value data. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcWriteReq(dmConnId_t connId, uint16_t handle, uint16_t valueLen, uint8_t *pValue); + +/*************************************************************************************************/ +/*! + * \fn AttcWriteCmd + * + * \brief Initiate an attribute protocol Write Command. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * \param valueLen Length of value data. + * \param pValue Pointer to value data. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcWriteCmd(dmConnId_t connId, uint16_t handle, uint16_t valueLen, uint8_t *pValue); + +/*************************************************************************************************/ +/*! + * \fn AttcSignedWriteCmd + * + * \brief Initiate an attribute protocol signed Write Command. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * \param signCounter Value of the sign counter. + * \param valueLen Length of value data. + * \param pValue Pointer to value data. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcSignedWriteCmd(dmConnId_t connId, uint16_t handle, uint32_t signCounter, + uint16_t valueLen, uint8_t *pValue); + +/*************************************************************************************************/ +/*! + * \fn AttcPrepareWriteReq + * + * \brief Initiate an attribute protocol Prepare Write Request. + * + * \param connId DM connection ID. + * \param handle Attribute handle. + * \param offset Write attribute data starting at this offset. + * \param valueLen Length of value data. + * \param pValue Pointer to value data. + * \param valueByRef TRUE if pValue data is accessed by reference rather than copied. + * \param continuing TRUE if ATTC continues sending requests until complete. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcPrepareWriteReq(dmConnId_t connId, uint16_t handle, uint16_t offset, uint16_t valueLen, + uint8_t *pValue, bool_t valueByRef, bool_t continuing); + +/*************************************************************************************************/ +/*! + * \fn AttcExecuteWriteReq + * + * \brief Initiate an attribute protocol Execute Write Request. + * + * \param connId DM connection ID. + * \param writeAll TRUE to write all queued writes, FALSE to cancel all queued writes. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcExecuteWriteReq(dmConnId_t connId, bool_t writeAll); + +/*************************************************************************************************/ +/*! + * \fn AttcCancelReq + * + * \brief Cancel an attribute protocol request in progress. + * + * \param connId DM connection ID. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcCancelReq(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn AttcDiscService + * + * \brief This utility function discovers the given service on a peer device. Function + * AttcFindByTypeValueReq() is called to initiate the discovery procedure. + * + * \param connId DM connection ID. + * \param pCb Pointer to discovery control block. + * \param uuidLen Length of service UUID (2 or 16). + * \param pUuid Pointer to service UUID. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcDiscService(dmConnId_t connId, attcDiscCb_t *pCb, uint8_t uuidLen, uint8_t *pUuid); + +/*************************************************************************************************/ +/*! + * \fn AttcDiscServiceCmpl + * + * \brief This utility function processes a service discovery result. It should be called + * when an ATTC_FIND_BY_TYPE_VALUE_RSP callback event is received after service + * discovery is initiated by calling AttcDiscService(). + * + * \param pCb Pointer to discovery control block. + * \param pMsg ATT callback event message. + * + * \return ATT_SUCCESS if successful otherwise error. + */ +/*************************************************************************************************/ +uint8_t AttcDiscServiceCmpl(attcDiscCb_t *pCb, attEvt_t *pMsg); + +/*************************************************************************************************/ +/*! + * \fn AttcDiscCharStart + * + * \brief This utility function starts characteristic and characteristic descriptor + * discovery for a service on a peer device. The service must have been previously + * discovered by calling AttcDiscService() and AttcDiscServiceCmpl(). + * + * \param connId DM connection ID. + * \param pCb Pointer to discovery control block. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcDiscCharStart(dmConnId_t connId, attcDiscCb_t *pCb); + +/*************************************************************************************************/ +/*! + * \fn AttcDiscCharCmpl + * + * \brief This utility function processes a characteristic discovery result. It should be + * called when an ATTC_READ_BY_TYPE_RSP or ATTC_FIND_INFO_RSP callback event is + * received after characteristic discovery is initiated by calling AttcDiscCharStart(). + * + * \param pCb Pointer to discovery control block. + * \param pMsg ATT callback event message. + * + * \return ATT_CONTINUING if successful and the discovery procedure is continuing. + * ATT_SUCCESS if the discovery procedure completed successfully. + * Otherwise the discovery procedure failed. + */ +/*************************************************************************************************/ +uint8_t AttcDiscCharCmpl(attcDiscCb_t *pCb, attEvt_t *pMsg); + +/*************************************************************************************************/ +/*! + * \fn AttcDiscConfigStart + * + * \brief This utility function starts characteristic configuration for characteristics on a + * peer device. The characteristics must have been previously discovered by calling + * AttcDiscCharStart() and AttcDiscCharCmpl(). + * + * \param connId DM connection ID. + * \param pCb Pointer to discovery control block. + * + * \return ATT_CONTINUING if successful and configuration procedure is continuing. + * ATT_SUCCESS if nothing to configure. + */ +/*************************************************************************************************/ +uint8_t AttcDiscConfigStart(dmConnId_t connId, attcDiscCb_t *pCb); + +/*************************************************************************************************/ +/*! + * \fn AttcDiscConfigCmpl + * + * \brief This utility function initiates the next characteristic configuration procedure. + * It should be called when an ATTC_READ_RSP or ATTC_WRITE_RSP callback event is received + * after characteristic configuration is initiated by calling AttcDiscConfigStart(). + * + * \param connId DM connection ID. + * \param pCb Pointer to discovery control block. + * + * \return ATT_CONTINUING if successful and configuration procedure is continuing. + * ATT_SUCCESS if configuration procedure completed successfully. + */ +/*************************************************************************************************/ +uint8_t AttcDiscConfigCmpl(dmConnId_t connId, attcDiscCb_t *pCb); + +/*************************************************************************************************/ +/*! + * \fn AttcDiscConfigResume + * + * \brief This utility function resumes the characteristic configuration procedure. It can + * be called when an ATTC_READ_RSP or ATTC_WRITE_RSP callback event is received + * with failure status to attempt the read or write procedure again. + * + * \param connId DM connection ID. + * \param pCb Pointer to discovery control block. + * + * \return ATT_CONTINUING if successful and configuration procedure is continuing. + * ATT_SUCCESS if configuration procedure completed successfully. + */ +/*************************************************************************************************/ +uint8_t AttcDiscConfigResume(dmConnId_t connId, attcDiscCb_t *pCb); + +/*************************************************************************************************/ +/*! + * \fn AttcMtuReq + * + * \brief For internal use only. + * + * \param connId DM connection ID. + * \param mtu Attribute protocol MTU. + * + * \return None. + */ +/*************************************************************************************************/ +void AttcMtuReq(dmConnId_t connId, uint16_t mtu); + +/*************************************************************************************************/ +/*! + * \fn AttsErrorTest + * + * \brief For testing purposes only. + * + * \param status ATT status + * + * \return None. + */ +/*************************************************************************************************/ +void AttsErrorTest(uint8_t status); + +#ifdef __cplusplus +}; +#endif + +#endif /* ATT_API_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/att_defs.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,221 @@ +/*************************************************************************************************/ +/*! + * \file att_defs.h + * + * \brief Attribute protocol constants and definitions from the Bluetooth specification. + * + * $Date: 2012-09-11 16:18:57 -0700 (Tue, 11 Sep 2012) $ + * $Revision: 349 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef ATT_DEFS_H +#define ATT_DEFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Attribute PDU format */ +#define ATT_HDR_LEN 1 /*! Attribute PDU header length */ +#define ATT_AUTH_SIG_LEN 12 /*! Authentication signature length */ +#define ATT_DEFAULT_MTU 23 /*! Default value of ATT_MTU */ +#define ATT_MAX_MTU 517 /*! Maximum value of ATT_MTU */ +#define ATT_DEFAULT_PAYLOAD_LEN 20 /*! Default maximum payload length for most PDUs */ + +/*! Attribute value parameters */ +#define ATT_VALUE_MAX_LEN 512 /*! Maximum attribute value length */ +#define ATT_VALUE_MAX_OFFSET 511 /*! Maximum attribute value offset */ + +/*! Transaction timeout */ +#define ATT_MAX_TRANS_TIMEOUT 30 /*! Maximum transaction timeout in seconds */ + +/*! Error codes */ +#define ATT_SUCCESS 0x00 /*! Operation successful */ +#define ATT_ERR_HANDLE 0x01 /*! Invalid handle */ +#define ATT_ERR_READ 0x02 /*! Read not permitted */ +#define ATT_ERR_WRITE 0x03 /*! Write not permitted */ +#define ATT_ERR_INVALID_PDU 0x04 /*! Invalid pdu */ +#define ATT_ERR_AUTH 0x05 /*! Insufficient authentication */ +#define ATT_ERR_NOT_SUP 0x06 /*! Request not supported */ +#define ATT_ERR_OFFSET 0x07 /*! Invalid offset */ +#define ATT_ERR_AUTHOR 0x08 /*! Insufficient authorization */ +#define ATT_ERR_QUEUE_FULL 0x09 /*! Prepare queue full */ +#define ATT_ERR_NOT_FOUND 0x0A /*! Attribute not found */ +#define ATT_ERR_NOT_LONG 0x0B /*! Attribute not long */ +#define ATT_ERR_KEY_SIZE 0x0C /*! Insufficient encryption key size */ +#define ATT_ERR_LENGTH 0x0D /*! Invalid attribute value length */ +#define ATT_ERR_UNLIKELY 0x0E /*! Other unlikely error */ +#define ATT_ERR_ENC 0x0F /*! Insufficient encryption */ +#define ATT_ERR_GROUP_TYPE 0x10 /*! Unsupported group type */ +#define ATT_ERR_RESOURCES 0x11 /*! Insufficient resources */ +#define ATT_ERR_CCCD 0xFD /*! CCCD improperly configured */ +#define ATT_ERR_IN_PROGRESS 0xFE /*! Procedure already in progress */ +#define ATT_ERR_RANGE 0xFF /*! Value out of range */ + +/*! Proprietary internal error codes */ +#define ATT_ERR_MEMORY 0x70 /*! Out of memory */ +#define ATT_ERR_TIMEOUT 0x71 /*! Transaction timeout */ +#define ATT_ERR_OVERFLOW 0x72 /*! Transaction overflow */ +#define ATT_ERR_INVALID_RSP 0x73 /*! Invalid response PDU */ +#define ATT_ERR_CANCELLED 0x74 /*! Request cancelled */ +#define ATT_ERR_UNDEFINED 0x75 /*! Other undefined error */ +#define ATT_ERR_REQ_NOT_FOUND 0x76 /*! Required characteristic not found */ +#define ATT_CONTINUING 0x77 /*! Procedure continuing */ + +/*! Application error codes */ +#define ATT_ERR_VALUE_RANGE 0x80 /*! Value out of range */ + +/*! PDU types */ +#define ATT_PDU_ERR_RSP 0x01 /*! Error response */ +#define ATT_PDU_MTU_REQ 0x02 /*! Exchange mtu request */ +#define ATT_PDU_MTU_RSP 0x03 /*! Exchange mtu response */ +#define ATT_PDU_FIND_INFO_REQ 0x04 /*! Find information request */ +#define ATT_PDU_FIND_INFO_RSP 0x05 /*! Find information response */ +#define ATT_PDU_FIND_TYPE_REQ 0x06 /*! Find by type value request */ +#define ATT_PDU_FIND_TYPE_RSP 0x07 /*! Find by type value response */ +#define ATT_PDU_READ_TYPE_REQ 0x08 /*! Read by type request */ +#define ATT_PDU_READ_TYPE_RSP 0x09 /*! Read by type response */ +#define ATT_PDU_READ_REQ 0x0A /*! Read request */ +#define ATT_PDU_READ_RSP 0x0B /*! Read response */ +#define ATT_PDU_READ_BLOB_REQ 0x0C /*! Read blob request */ +#define ATT_PDU_READ_BLOB_RSP 0x0D /*! Read blob response */ +#define ATT_PDU_READ_MULT_REQ 0x0E /*! Read multiple request */ +#define ATT_PDU_READ_MULT_RSP 0x0F /*! Read multiple response */ +#define ATT_PDU_READ_GROUP_TYPE_REQ 0x10 /*! Read by group type request */ +#define ATT_PDU_READ_GROUP_TYPE_RSP 0x11 /*! Read by group type response */ +#define ATT_PDU_WRITE_REQ 0x12 /*! Write request */ +#define ATT_PDU_WRITE_RSP 0x13 /*! Write response */ +#define ATT_PDU_WRITE_CMD 0x52 /*! Write command */ +#define ATT_PDU_SIGNED_WRITE_CMD 0xD2 /*! Signed write command */ +#define ATT_PDU_PREP_WRITE_REQ 0x16 /*! Prepare write request */ +#define ATT_PDU_PREP_WRITE_RSP 0x17 /*! Prepare write response */ +#define ATT_PDU_EXEC_WRITE_REQ 0x18 /*! Execute write request */ +#define ATT_PDU_EXEC_WRITE_RSP 0x19 /*! Execute write response */ +#define ATT_PDU_VALUE_NTF 0x1B /*! Handle value notification */ +#define ATT_PDU_VALUE_IND 0x1D /*! Handle value indication */ +#define ATT_PDU_VALUE_CNF 0x1E /*! Handle value confirmation */ +#define ATT_PDU_MAX 0x1F /*! PDU Maximum */ + +/*! Length of PDU fixed length fields */ +#define ATT_ERR_RSP_LEN 5 +#define ATT_MTU_REQ_LEN 3 +#define ATT_MTU_RSP_LEN 3 +#define ATT_FIND_INFO_REQ_LEN 5 +#define ATT_FIND_INFO_RSP_LEN 2 +#define ATT_FIND_TYPE_REQ_LEN 7 +#define ATT_FIND_TYPE_RSP_LEN 1 +#define ATT_READ_TYPE_REQ_LEN 5 +#define ATT_READ_TYPE_RSP_LEN 2 +#define ATT_READ_REQ_LEN 3 +#define ATT_READ_RSP_LEN 1 +#define ATT_READ_BLOB_REQ_LEN 5 +#define ATT_READ_BLOB_RSP_LEN 1 +#define ATT_READ_MULT_REQ_LEN 1 +#define ATT_READ_MULT_RSP_LEN 1 +#define ATT_READ_GROUP_TYPE_REQ_LEN 5 +#define ATT_READ_GROUP_TYPE_RSP_LEN 2 +#define ATT_WRITE_REQ_LEN 3 +#define ATT_WRITE_RSP_LEN 1 +#define ATT_WRITE_CMD_LEN 3 +#define ATT_SIGNED_WRITE_CMD_LEN (ATT_WRITE_CMD_LEN + ATT_AUTH_SIG_LEN) +#define ATT_PREP_WRITE_REQ_LEN 5 +#define ATT_PREP_WRITE_RSP_LEN 5 +#define ATT_EXEC_WRITE_REQ_LEN 2 +#define ATT_EXEC_WRITE_RSP_LEN 1 +#define ATT_VALUE_NTF_LEN 3 +#define ATT_VALUE_IND_LEN 3 +#define ATT_VALUE_CNF_LEN 1 + +/*! Find information response format */ +#define ATT_FIND_HANDLE_16_UUID 0x01 /*! Handle and 16 bit UUID */ +#define ATT_FIND_HANDLE_128_UUID 0x02 /*! Handle and 128 bit UUID */ + +/*! Execute write request flags */ +#define ATT_EXEC_WRITE_CANCEL 0x00 /*! Cancel all prepared writes */ +#define ATT_EXEC_WRITE_ALL 0x01 /*! Write all pending prepared writes */ + +/*! PDU masks */ +#define ATT_PDU_MASK_SERVER 0x01 /*! Server bit mask */ +#define ATT_PDU_MASK_COMMAND 0x40 /*! Command bit mask */ +#define ATT_PDU_MASK_SIGNED 0x80 /*! Auth signature bit mask */ + +/*! Handles */ +#define ATT_HANDLE_NONE 0x0000 +#define ATT_HANDLE_START 0x0001 +#define ATT_HANDLE_MAX 0xFFFF + +/*! UUID lengths */ +#define ATT_NO_UUID_LEN 0 /*! Length when no UUID is present ;-) */ +#define ATT_16_UUID_LEN 2 /*! Length in bytes of a 16 bit UUID */ +#define ATT_128_UUID_LEN 16 /*! Length in bytes of a 128 bit UUID */ + +/*! GATT characteristic properties */ +#define ATT_PROP_BROADCAST 0x01 /*! Permit broadcasts */ +#define ATT_PROP_READ 0x02 /*! Permit reads */ +#define ATT_PROP_WRITE_NO_RSP 0x04 /*! Permit writes without response */ +#define ATT_PROP_WRITE 0x08 /*! Permit writes with response */ +#define ATT_PROP_NOTIFY 0x10 /*! Permit notifications */ +#define ATT_PROP_INDICATE 0x20 /*! Permit indications */ +#define ATT_PROP_AUTHENTICATED 0x40 /*! Permit signed writes */ +#define ATT_PROP_EXTENDED 0x80 /*! More properties defined in extended properties */ + +/*! GATT characteristic extended properties */ +#define ATT_EXT_PROP_RELIABLE_WRITE 0x0001 /*! Permit reliable writes */ +#define ATT_EXT_PROP_WRITEABLE_AUX 0x0002 /*! Permit write to characteristic descriptor */ + +/*! GATT client characteristic configuration */ +#define ATT_CLIENT_CFG_NOTIFY 0x0001 /*! Notify the value */ +#define ATT_CLIENT_CFG_INDICATE 0x0002 /*! Indicate the value */ + +/*! GATT server characteristic configuration */ +#define ATT_SERVER_CFG_BROADCAST 0x0001 /*! Broadcast the value */ + +/*! GATT characteristic format */ +#define ATT_FORMAT_BOOLEAN 0x01 /*! Boolean */ +#define ATT_FORMAT_2BIT 0x02 /*! Unsigned 2 bit integer */ +#define ATT_FORMAT_NIBBLE 0x03 /*! Unsigned 4 bit integer */ +#define ATT_FORMAT_UINT8 0x04 /*! Unsigned 8 bit integer */ +#define ATT_FORMAT_UINT12 0x05 /*! Unsigned 12 bit integer */ +#define ATT_FORMAT_UINT16 0x06 /*! Unsigned 16 bit integer */ +#define ATT_FORMAT_UINT24 0x07 /*! Unsigned 24 bit integer */ +#define ATT_FORMAT_UINT32 0x08 /*! Unsigned 32 bit integer */ +#define ATT_FORMAT_UINT48 0x09 /*! Unsigned 48 bit integer */ +#define ATT_FORMAT_UINT64 0x0A /*! Unsigned 64 bit integer */ +#define ATT_FORMAT_UINT128 0x0B /*! Unsigned 128 bit integer */ +#define ATT_FORMAT_SINT8 0x0C /*! Signed 8 bit integer */ +#define ATT_FORMAT_SINT12 0x0D /*! Signed 12 bit integer */ +#define ATT_FORMAT_SINT16 0x0E /*! Signed 16 bit integer */ +#define ATT_FORMAT_SINT24 0x0F /*! Signed 24 bit integer */ +#define ATT_FORMAT_SINT32 0x10 /*! Signed 32 bit integer */ +#define ATT_FORMAT_SINT48 0x11 /*! Signed 48 bit integer */ +#define ATT_FORMAT_SINT64 0x12 /*! Signed 64 bit integer */ +#define ATT_FORMAT_SINT128 0x13 /*! Signed 128 bit integer */ +#define ATT_FORMAT_FLOAT32 0x14 /*! IEEE-754 32 bit floating point */ +#define ATT_FORMAT_FLOAT64 0x15 /*! IEEE-754 64 bit floating point */ +#define ATT_FORMAT_SFLOAT 0x16 /*! IEEE-11073 16 bit SFLOAT */ +#define ATT_FORMAT_FLOAT 0x17 /*! IEEE-11073 32 bit FLOAT */ +#define ATT_FORMAT_DUINT16 0x18 /*! IEEE-20601 format */ +#define ATT_FORMAT_UTF8 0x19 /*! UTF-8 string */ +#define ATT_FORMAT_UTF16 0x1A /*! UTF-16 string */ +#define ATT_FORMAT_STRUCT 0x1B /*! Opaque structure */ + +#ifdef __cplusplus +}; +#endif + +#endif /* ATT_DEFS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/att_handler.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,67 @@ +/*************************************************************************************************/ +/*! + * \file att_handler.h + * + * \brief Interface to ATT event handler. + * + * $Date: 2012-03-29 13:24:04 -0700 (Thu, 29 Mar 2012) $ + * $Revision: 287 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef ATT_HANDLER_H +#define ATT_HANDLER_H + +#include "wsf_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn AttHandlerInit + * + * \brief ATT handler init function called during system initialization. + * + * \param handlerID WSF handler ID for ATT. + * + * \return None. + */ +/*************************************************************************************************/ +void AttHandlerInit(wsfHandlerId_t handlerId); + + +/*************************************************************************************************/ +/*! + * \fn AttHandler + * + * \brief WSF event handler for ATT. + * + * \param event WSF event mask. + * \param pMsg WSF message. + * + * \return None. + */ +/*************************************************************************************************/ +void AttHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg); + +#ifdef __cplusplus +}; +#endif + +#endif /* ATT_HANDLER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/att_uuid.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,431 @@ +/*************************************************************************************************/ +/*! + * \file att_uuid.h + * + * \brief Attribute protocol UUIDs from the Bluetooth specification. + * + * $Date: 2014-08-11 17:41:56 -0500 (Mon, 11 Aug 2014) $ + * $Revision: 14613 $ + * + * Copyright (c) 2011-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef ATT_UUID_H +#define ATT_UUID_H + +#include "att_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Service UUIDs */ +#define ATT_UUID_GAP_SERVICE 0x1800 /*! Generic Access Profile Service */ +#define ATT_UUID_GATT_SERVICE 0x1801 /*! Generic Attribute Profile Service */ +#define ATT_UUID_IMMEDIATE_ALERT_SERVICE 0x1802 /*! Immediate Alert Service */ +#define ATT_UUID_LINK_LOSS_SERVICE 0x1803 /*! Link Loss Service */ +#define ATT_UUID_TX_POWER_SERVICE 0x1804 /*! Tx Power Service */ +#define ATT_UUID_CURRENT_TIME_SERVICE 0x1805 /*! Current Time Service */ +#define ATT_UUID_REF_TIME_UPDATE_SERVICE 0x1806 /*! Reference Time Update Service */ +#define ATT_UUID_DST_CHANGE_SERVICE 0x1807 /*! Next DST Change Service */ +#define ATT_UUID_GLUCOSE_SERVICE 0x1808 /*! Glucose Service */ +#define ATT_UUID_HEALTH_THERM_SERVICE 0x1809 /*! Health Thermometer Service */ +#define ATT_UUID_DEVICE_INFO_SERVICE 0x180A /*! Device Information Service */ +#define ATT_UUID_NETWORK_AVAIL_SERVICE 0x180B /*! Network Availability Service */ +#define ATT_UUID_WATCHDOG_SERVICE 0x180C /*! Watchdog Service */ +#define ATT_UUID_HEART_RATE_SERVICE 0x180D /*! Heart Rate Service */ +#define ATT_UUID_PHONE_ALERT_SERVICE 0x180E /*! Phone Alert Status Service */ +#define ATT_UUID_BATTERY_SERVICE 0x180F /*! Battery Service */ +#define ATT_UUID_BLOOD_PRESSURE_SERVICE 0x1810 /*! Blood Pressure Service */ +#define ATT_UUID_ALERT_NOTIF_SERVICE 0x1811 /*! Alert Notification Service */ +#define ATT_UUID_HID_SERVICE 0x1812 /*! Human Interface Device Service */ +#define ATT_UUID_SCAN_PARAM_SERVICE 0x1813 /*! Scan Parameter Service */ +#define ATT_UUID_WEIGHT_SCALE_SERVICE 0x181D /*! Weight Scale Service */ + +/*! GATT UUIDs */ +#define ATT_UUID_PRIMARY_SERVICE 0x2800 /*! Primary Service */ +#define ATT_UUID_SECONDARY_SERVICE 0x2801 /*! Secondary Service */ +#define ATT_UUID_INCLUDE 0x2802 /*! Include */ +#define ATT_UUID_CHARACTERISTIC 0x2803 /*! Characteristic */ + +/*! Descriptor UUIDs */ +#define ATT_UUID_CHARACTERISTIC_EXT 0x2900 /*! Characteristic Extended Properties */ +#define ATT_UUID_CHAR_USER_DESC 0x2901 /*! Characteristic User Description */ +#define ATT_UUID_CLIENT_CHAR_CONFIG 0x2902 /*! Client Characteristic Configuration */ +#define ATT_UUID_SERVER_CHAR_CONFIG 0x2903 /*! Server Characteristic Configuration */ +#define ATT_UUID_CHAR_PRES_FORMAT 0x2904 /*! Characteristic Presentation Format */ +#define ATT_UUID_AGGREGATE_FORMAT 0x2905 /*! Characteristic Aggregate Format */ +#define ATT_UUID_VALID_RANGE 0x2906 /*! Valid Range */ +#define ATT_UUID_HID_REPORT_ID_MAPPING 0x2908 /*! HID Report ID Mapping */ + +/*! Characteristic UUIDs */ +#define ATT_UUID_DEVICE_NAME 0x2A00 /*! Device Name */ +#define ATT_UUID_APPEARANCE 0x2A01 /*! Appearance */ +#define ATT_UUID_PERIPH_PRIVACY_FLAG 0x2A02 /*! Peripheral Privacy Flag */ +#define ATT_UUID_RECONN_ADDR 0x2A03 /*! Reconnection Address */ +#define ATT_UUID_PREF_CONN_PARAM 0x2A04 /*! Peripheral Preferred Connection Parameters */ +#define ATT_UUID_SERVICE_CHANGED 0x2A05 /*! Service Changed */ +#define ATT_UUID_ALERT_LEVEL 0x2A06 /*! Alert Level */ +#define ATT_UUID_TX_POWER_LEVEL 0x2A07 /*! Tx Power Level */ +#define ATT_UUID_DATE_TIME 0x2A08 /*! Date Time */ +#define ATT_UUID_DAY_OF_WEEK 0x2A09 /*! Day of Week */ +#define ATT_UUID_DAY_DATE_TIME 0x2A0A /*! Day Date Time */ +#define ATT_UUID_EXACT_TIME_100 0x2A0B /*! Exact Time 100 */ +#define ATT_UUID_EXACT_TIME_256 0x2A0C /*! Exact Time 256 */ +#define ATT_UUID_DST_OFFSET 0x2A0D /*! DST Offset */ +#define ATT_UUID_TIME_ZONE 0x2A0E /*! Time Zone */ +#define ATT_UUID_LOCAL_TIME_INFO 0x2A0F /*! Local Time Information */ +#define ATT_UUID_SECONDARY_TIME_ZONE 0x2A10 /*! Secondary Time Zone */ +#define ATT_UUID_TIME_WITH_DST 0x2A11 /*! Time with DST */ +#define ATT_UUID_TIME_ACCURACY 0x2A12 /*! Time Accuracy */ +#define ATT_UUID_TIME_SOURCE 0x2A13 /*! Time Source */ +#define ATT_UUID_REFERENCE_TIME_INFO 0x2A14 /*! Reference Time Information */ +#define ATT_UUID_TIME_BROADCAST 0x2A15 /*! Time Broadcast */ +#define ATT_UUID_TIME_UPDATE_CP 0x2A16 /*! Time Update Control Point */ +#define ATT_UUID_TIME_UPDATE_STATE 0x2A17 /*! Time Update State */ +#define ATT_UUID_GLUCOSE_MEAS 0x2A18 /*! Glucose Measurement */ +#define ATT_UUID_BATTERY_LEVEL 0x2A19 /*! Battery Level */ +#define ATT_UUID_BATTERY_POWER_STATE 0x2A1A /*! Battery Power State */ +#define ATT_UUID_BATTERY_LEVEL_STATE 0x2A1B /*! Battery Level State */ +#define ATT_UUID_TEMP_MEAS 0x2A1C /*! Temperature Measurement */ +#define ATT_UUID_TEMP_TYPE 0x2A1D /*! Temperature Type */ +#define ATT_UUID_INTERMEDIATE_TEMP 0x2A1E /*! Intermediate Temperature */ +#define ATT_UUID_TEMP_C 0x2A1F /*! Temperature Celsius */ +#define ATT_UUID_TEMP_F 0x2A20 /*! Temperature Fahrenheit */ +#define ATT_UUID_MEAS_INTERVAL 0x2A21 /*! Measurement Interval */ +#define ATT_UUID_HID_BOOT_REPORT_MAP 0x2A22 /*! HID Boot Report Mapping */ +#define ATT_UUID_SYSTEM_ID 0x2A23 /*! System ID */ +#define ATT_UUID_MODEL_NUMBER 0x2A24 /*! Model Number String */ +#define ATT_UUID_SERIAL_NUMBER 0x2A25 /*! Serial Number String */ +#define ATT_UUID_FIRMWARE_REV 0x2A26 /*! Firmware Revision String */ +#define ATT_UUID_HARDWARE_REV 0x2A27 /*! Hardware Revision String */ +#define ATT_UUID_SOFTWARE_REV 0x2A28 /*! Software Revision String */ +#define ATT_UUID_MANUFACTURER_NAME 0x2A29 /*! Manufacturer Name String */ +#define ATT_UUID_11073_CERT_DATA 0x2A2A /*! IEEE 11073-20601 Regulatory Certification Data List */ +#define ATT_UUID_CURRENT_TIME 0x2A2B /*! Current Time */ +#define ATT_UUID_ELEVATION 0x2A2C /*! Elevation */ +#define ATT_UUID_LATITUDE 0x2A2D /*! Latitude */ +#define ATT_UUID_LONGITUDE 0x2A2E /*! Longitude */ +#define ATT_UUID_POSITION_2D 0x2A2F /*! Position 2D */ +#define ATT_UUID_POSITION_3D 0x2A30 /*! Position 3D */ +#define ATT_UUID_VENDOR_ID 0x2A31 /*! Vendor ID */ +#define ATT_UUID_PRODUCT_ID 0x2A32 /*! Product ID */ +#define ATT_UUID_HID_VERSION 0x2A33 /*! HID Version */ +#define ATT_UUID_GLUCOSE_MEAS_CONTEXT 0x2A34 /*! Glucose Measurement Context */ +#define ATT_UUID_BP_MEAS 0x2A35 /*! Blood Pressure Measurement */ +#define ATT_UUID_INTERMEDIATE_BP 0x2A36 /*! Intermediate Cuff Pressure */ +#define ATT_UUID_HR_MEAS 0x2A37 /*! Heart Rate Measurement */ +#define ATT_UUID_HR_SENSOR_LOC 0x2A38 /*! Body Sensor Location */ +#define ATT_UUID_HR_CP 0x2A39 /*! Heart Rate Control Point */ +#define ATT_UUID_REMOVABLE 0x2A3A /*! Removable */ +#define ATT_UUID_SERVICE_REQ 0x2A3B /*! Service Required */ +#define ATT_UUID_SCI_TEMP_C 0x2A3C /*! Scientific Temperature in Celsius */ +#define ATT_UUID_STRING 0x2A3D /*! String */ +#define ATT_UUID_NETWORK_AVAIL 0x2A3E /*! Network Availability */ +#define ATT_UUID_ALERT_STATUS 0x2A3F /*! Alert Status */ +#define ATT_UUID_RINGER_CP 0x2A40 /*! Ringer Control Point */ +#define ATT_UUID_RINGER_SETTING 0x2A41 /*! Ringer Setting */ +#define ATT_UUID_ALERT_CAT_ID_MASK 0x2A42 /*! Alert Category ID Bit Mask */ +#define ATT_UUID_ALERT_CAT_ID 0x2A43 /*! Alert Category ID */ +#define ATT_UUID_ALERT_NOTIF_CP 0x2A44 /*! Alert Notification Control Point */ +#define ATT_UUID_UNREAD_ALERT_STATUS 0x2A45 /*! Unread Alert Status */ +#define ATT_UUID_NEW_ALERT 0x2A46 /*! New Alert */ +#define ATT_UUID_SUP_NEW_ALERT_CAT 0x2A47 /*! Supported New Alert Category */ +#define ATT_UUID_SUP_UNREAD_ALERT_CAT 0x2A48 /*! Supported Unread Alert Category */ +#define ATT_UUID_BP_FEATURE 0x2A49 /*! Blood Pressure Feature */ +#define ATT_UUID_HID_INFO 0x2A4A /*! HID Information */ +#define ATT_UUID_REPORT_MAP 0x2A4B /*! Report Map */ +#define ATT_UUID_HID_CP 0x2A4C /*! HID Control Point */ +#define ATT_UUID_REPORT 0x2A4D /*! Report */ +#define ATT_UUID_PROTOCOL_MODE 0x2A4E /*! Protocol Mode */ +#define ATT_UUID_SCAN_INT_WIND 0x2A4F /*! Scan Interval Window */ +#define ATT_UUID_PNP_ID 0x2A50 /*! PnP ID */ +#define ATT_UUID_GLUCOSE_FEATURE 0x2A51 /*! Glucose Feature */ +#define ATT_UUID_RACP 0x2A52 /*! Record Access Control Point */ +#define ATT_UUID_WEIGHT_MEAS 0x2A9D /*! Weight Measurement */ +#define ATT_UUID_WEIGHT_SCALE_FEATURE 0x2A9E /*! Weight Scale Feature */ + +/* remove when adopted */ +#define ATT_UUID_GENERIC_CTRL_SERVICE 0xF011 +#define ATT_UUID_COMMAND_ENUM 0xE010 /*! Command Enumeration */ +#define ATT_UUID_GENERIC_COMMAND_CP 0xE011 /*! Generic Command Control Point */ + +/*! Unit UUIDs */ +#define ATT_UUID_UNITLESS 0x2700 /*! unitless */ +#define ATT_UUID_LENGTH_M 0x2701 /*! length metre */ +#define ATT_UUID_MASS_KG 0x2702 /*! mass kilogram */ +#define ATT_UUID_TIME_SEC 0x2703 /*! time second */ +#define ATT_UUID_ELECTRIC_CURRENT_AMP 0x2704 /*! electric current ampere */ +#define ATT_UUID_THERMO_TEMP_K 0x2705 /*! thermodynamic temperature kelvin */ +#define ATT_UUID_AMOUNT_OF_SUBSTANCE_MOLE 0x2706 /*! amount of substance mole */ +#define ATT_UUID_LUMINOUS_INTENSITY_CAND 0x2707 /*! luminous intensity candela */ +#define ATT_UUID_AREA_SQ_M 0x2710 /*! area square metres */ +#define ATT_UUID_VOLUME_CU_M 0x2711 /*! volume cubic metres */ +#define ATT_UUID_VELOCITY_MPS 0x2712 /*! velocity metres per second */ +#define ATT_UUID_ACCELERATION_MPS_SQ 0x2713 /*! acceleration metres per second squared */ +#define ATT_UUID_WAVENUMBER_RECIPROCAL_M 0x2714 /*! wavenumber reciprocal metre */ +#define ATT_UUID_DENSITY_KG_PER_CU_M 0x2715 /*! density kilogram per cubic metre */ +#define ATT_UUID_SURFACE_DENS_KG_PER_SQ_M 0x2716 /*! surface density kilogram per square metre */ +#define ATT_UUID_SPECIFIC_VOL_CU_M_PER_KG 0x2717 /*! specific volume cubic metre per kilogram */ +#define ATT_UUID_CURRENT_DENS_AMP_PER_SQ_M 0x2718 /*! current density ampere per square metre */ +#define ATT_UUID_MAG_FIELD_STR_AMP_PER_M 0x2719 /*! magnetic field strength ampere per metre */ +#define ATT_UUID_AMOUNT_CONC_MOLE_PER_CU_M 0x271A /*! amount concentration mole per cubic metre */ +#define ATT_UUID_MASS_CONC_KG_PER_CU_M 0x271B /*! mass concentration kilogram per cubic metre */ +#define ATT_UUID_LUM_CAND_PER_SQ_M 0x271C /*! luminance candela per square metre */ +#define ATT_UUID_REFRACTIVE_INDEX 0x271D /*! refractive index */ +#define ATT_UUID_RELATIVE_PERMEABILITY 0x271E /*! relative permeability */ +#define ATT_UUID_PLANE_ANGLE_R 0x2720 /*! plane angle radian */ +#define ATT_UUID_SOLID_ANGLE_STER 0x2721 /*! solid angle steradian */ +#define ATT_UUID_FREQUENCY_HERTZ 0x2722 /*! frequency hertz */ +#define ATT_UUID_FORCE_NEWT 0x2723 /*! force newton */ +#define ATT_UUID_PRESSURE_PASCAL 0x2724 /*! pressure pascal */ +#define ATT_UUID_ENERGY_J 0x2725 /*! energy joule */ +#define ATT_UUID_POWER_W 0x2726 /*! power watt */ +#define ATT_UUID_ELECTRIC_CHG_C 0x2727 /*! electric charge coulomb */ +#define ATT_UUID_ELECTRIC_POTENTIAL_VOLT 0x2728 /*! electric potential difference volt */ +#define ATT_UUID_CAPACITANCE_F 0x2729 /*! capacitance farad */ +#define ATT_UUID_ELECTRIC_RESISTANCE_OHM 0x272A /*! electric resistance ohm */ +#define ATT_UUID_ELECTRIC_COND_SIEMENS 0x272B /*! electric conductance siemens */ +#define ATT_UUID_MAGNETIC_FLEX_WEBER 0x272C /*! magnetic flex weber */ +#define ATT_UUID_MAGNETIC_FLEX_DENS_TESLA 0x272D /*! magnetic flex density tesla */ +#define ATT_UUID_INDUCTANCE_H 0x272E /*! inductance henry */ +#define ATT_UUID_C_TEMP_DEG_C 0x272F /*! Celsius temperature degree Celsius */ +#define ATT_UUID_LUMINOUS_FLUX_LUMEN 0x2730 /*! luminous flux lumen */ +#define ATT_UUID_ILLUMINANCE_LUX 0x2731 /*! illuminance lux */ +#define ATT_UUID_RADIONUCLIDE_BECQUEREL 0x2732 /*! activity referred to a radionuclide becquerel */ +#define ATT_UUID_ABSORBED_DOSE_GRAY 0x2733 /*! absorbed dose gray */ +#define ATT_UUID_DOSE_EQUIVALENT_SIEVERT 0x2734 /*! dose equivalent sievert */ +#define ATT_UUID_CATALYTIC_ACTIVITY_KATAL 0x2735 /*! catalytic activity katal */ +#define ATT_UUID_DYNAMIC_VISC_PASCAL_SEC 0x2740 /*! dynamic viscosity pascal second */ +#define ATT_UUID_MOMENT_OF_FORCE_NEWT_M 0x2741 /*! moment of force newton metre */ +#define ATT_UUID_SURFACE_TENSION_NEWT_PER_M 0x2742 /*! surface tension newton per metre */ +#define ATT_UUID_ANG_VELOCITY_R_PER_SEC 0x2743 /*! angular velocity radian per second */ +#define ATT_UUID_ANG_ACCEL_R_PER_SEC_SQD 0x2744 /*! angular acceleration radian per second squared */ +#define ATT_UUID_HEAT_FLUX_DEN_W_PER_SQ_M 0x2745 /*! heat flux density watt per square metre */ +#define ATT_UUID_HEAT_CAP_J_PER_K 0x2746 /*! heat capacity joule per kelvin */ +#define ATT_UUID_SPEC_HEAT_CAP_J_PER_KG_K 0x2747 /*! specific heat capacity joule per kilogram kelvin */ +#define ATT_UUID_SPEC_ENERGY_J_PER_KG 0x2748 /*! specific energy joule per kilogram */ +#define ATT_UUID_THERMAL_COND_W_PER_M_K 0x2749 /*! thermal conductivity watt per metre kelvin */ +#define ATT_UUID_ENERGY_DENSITY_J_PER_CU_M 0x274A /*! energy density joule per cubic metre */ +#define ATT_UUID_ELEC_FIELD_STR_VOLT_PER_M 0x274B /*! electric field strength volt per metre */ +#define ATT_UUID_ELEC_CHG_DENS_C_PER_CU_M 0x274C /*! electric charge density coulomb per cubic metre */ +#define ATT_UUID_SURF_CHG_DENS_C_PER_SQ_M 0x274D /*! surface charge density coulomb per square metre */ +#define ATT_UUID_ELEC_FLUX_DENS_C_PER_SQ_M 0x274E /*! electric flux density coulomb per square metre */ +#define ATT_UUID_PERMITTIVITY_F_PER_M 0x274F /*! permittivity farad per metre */ +#define ATT_UUID_PERMEABILITY_H_PER_M 0x2750 /*! permeability henry per metre */ +#define ATT_UUID_MOLAR_ENERGY_J_PER_MOLE 0x2751 /*! molar energy joule per mole */ +#define ATT_UUID_MOLAR_ENTROPY_J_PER_MOLE_K 0x2752 /*! molar entropy joule per mole kelvin */ +#define ATT_UUID_EXPOSURE_C_PER_KG 0x2753 /*! exposure coulomb per kilogram */ +#define ATT_UUID_DOSE_RATE_GRAY_PER_SEC 0x2754 /*! absorbed dose rate gray per second */ +#define ATT_UUID_RT_INTENSITY_W_PER_STER 0x2755 /*! radiant intensity watt per steradian */ +#define ATT_UUID_RCE_W_PER_SQ_METER_STER 0x2756 /*! radiance watt per square meter steradian */ +#define ATT_UUID_CATALYTIC_KATAL_PER_CU_M 0x2757 /*! catalytic activity concentration katal per cubic metre */ +#define ATT_UUID_TIME_MIN 0x2760 /*! time minute */ +#define ATT_UUID_TIME_HR 0x2761 /*! time hour */ +#define ATT_UUID_TIME_DAY 0x2762 /*! time day */ +#define ATT_UUID_PLANE_ANGLE_DEG 0x2763 /*! plane angle degree */ +#define ATT_UUID_PLANE_ANGLE_MIN 0x2764 /*! plane angle minute */ +#define ATT_UUID_PLANE_ANGLE_SEC 0x2765 /*! plane angle second */ +#define ATT_UUID_AREA_HECTARE 0x2766 /*! area hectare */ +#define ATT_UUID_VOLUME_L 0x2767 /*! volume litre */ +#define ATT_UUID_MASS_TONNE 0x2768 /*! mass tonne */ +#define ATT_UUID_PRESSURE_BAR 0x2780 /*! pressure bar */ +#define ATT_UUID_PRESSURE_MM 0x2781 /*! pressure millimetre of mercury */ +#define ATT_UUID_LENGTH_ANGSTROM 0x2782 /*! length angstrom */ +#define ATT_UUID_LENGTH_NAUTICAL_MILE 0x2783 /*! length nautical mile */ +#define ATT_UUID_AREA_BARN 0x2784 /*! area barn */ +#define ATT_UUID_VELOCITY_KNOT 0x2785 /*! velocity knot */ +#define ATT_UUID_LOG_RADIO_QUANT_NEPER 0x2786 /*! logarithmic radio quantity neper */ +#define ATT_UUID_LOG_RADIO_QUANT_BEL 0x2787 /*! logarithmic radio quantity bel */ +#define ATT_UUID_LOG_RADIO_QUANT_DB 0x2788 /*! logarithmic radio quantity decibel */ +#define ATT_UUID_LENGTH_YARD 0x27A0 /*! length yard */ +#define ATT_UUID_LENGTH_PARSEC 0x27A1 /*! length parsec */ +#define ATT_UUID_LENGTH_IN 0x27A2 /*! length inch */ +#define ATT_UUID_LENGTH_FOOT 0x27A3 /*! length foot */ +#define ATT_UUID_LENGTH_MILE 0x27A4 /*! length mile */ +#define ATT_UUID_PRESSURE_POUND_PER_SQ_IN 0x27A5 /*! pressure pound-force per square inch */ +#define ATT_UUID_VELOCITY_KPH 0x27A6 /*! velocity kilometre per hour */ +#define ATT_UUID_VELOCITY_MPH 0x27A7 /*! velocity mile per hour */ +#define ATT_UUID_ANG_VELOCITY_RPM 0x27A8 /*! angular velocity revolution per minute */ +#define ATT_UUID_ENERGY_GRAM_CALORIE 0x27A9 /*! energy gram calorie */ +#define ATT_UUID_ENERGY_KG_CALORIE 0x27AA /*! energy kilogram calorie */ +#define ATT_UUID_ENERGY_KILOWATT_HR 0x27AB /*! energy kilowatt hour */ +#define ATT_UUID_THERM_TEMP_F 0x27AC /*! thermodynamic temperature degree Fahrenheit */ +#define ATT_UUID_PERCENTAGE 0x27AD /*! percentage */ +#define ATT_UUID_PER_MILLE 0x27AE /*! per mille */ +#define ATT_UUID_PERIOD_BEATS_PER_MIN 0x27AF /*! period beats per minute */ +#define ATT_UUID_ELECTRIC_CHG_AMP_HRS 0x27B0 /*! electric charge ampere hours */ +#define ATT_UUID_MASS_DENSITY_MG_PER_DL 0x27B1 /*! mass density milligram per decilitre */ +#define ATT_UUID_MASS_DENSITY_MMOLE_PER_L 0x27B2 /*! mass density millimole per litre */ +#define ATT_UUID_TIME_YEAR 0x27B3 /*! time year */ +#define ATT_UUID_TIME_MONTH 0x27B4 /*! time month */ + +/*! Wicentric proprietary UUIDs */ + +/*! Base UUID: E0262760-08C2-11E1-9073-0E8AC72EXXXX */ +#define ATT_UUID_WICENTRIC_BASE 0x2E, 0xC7, 0x8A, 0x0E, 0x73, 0x90, \ + 0xE1, 0x11, 0xC2, 0x08, 0x60, 0x27, 0x26, 0xE0 + +/*! Macro for building Wicentric UUIDs */ +#define ATT_UUID_WICENTRIC_BUILD(part) UINT16_TO_BYTES(part), ATT_UUID_WICENTRIC_BASE + +/*! Partial proprietary service UUIDs */ +#define ATT_UUID_P1_SERVICE_PART 0x1001 /*! Proprietary service P1 */ + +/*! Partial proprietary characteristic UUIDs */ +#define ATT_UUID_D1_DATA_PART 0x0001 /*! Proprietary data D1 */ + +/* Proprietary services */ +#define ATT_UUID_P1_SERVICE ATT_UUID_WICENTRIC_BUILD(ATT_UUID_P1_SERVICE_PART) + +/* Proprietary characteristics */ +#define ATT_UUID_D1_DATA ATT_UUID_WICENTRIC_BUILD(ATT_UUID_D1_DATA_PART) + +/************************************************************************************************** + Global Variables +**************************************************************************************************/ + +/*! Service UUIDs */ +extern const uint8_t attGapSvcUuid[ATT_16_UUID_LEN]; /*! Generic Access Profile Service */ +extern const uint8_t attGattSvcUuid[ATT_16_UUID_LEN]; /*! Generic Attribute Profile Service */ +extern const uint8_t attIasSvcUuid[ATT_16_UUID_LEN]; /*! Immediate Alert Service */ +extern const uint8_t attLlsSvcUuid[ATT_16_UUID_LEN]; /*! Link Loss Service */ +extern const uint8_t attTpsSvcUuid[ATT_16_UUID_LEN]; /*! Tx Power Service */ +extern const uint8_t attCtsSvcUuid[ATT_16_UUID_LEN]; /*! Current Time Service */ +extern const uint8_t attRtusSvcUuid[ATT_16_UUID_LEN]; /*! Reference Time Update Service */ +extern const uint8_t attNdcsSvcUuid[ATT_16_UUID_LEN]; /*! Next DST Change Service */ +extern const uint8_t attGlsSvcUuid[ATT_16_UUID_LEN]; /*! Glucose Service */ +extern const uint8_t attHtsSvcUuid[ATT_16_UUID_LEN]; /*! Health Thermometer Service */ +extern const uint8_t attDisSvcUuid[ATT_16_UUID_LEN]; /*! Device Information Service */ +extern const uint8_t attNwaSvcUuid[ATT_16_UUID_LEN]; /*! Network Availability Service */ +extern const uint8_t attWdsSvcUuid[ATT_16_UUID_LEN]; /*! Watchdog Service */ +extern const uint8_t attHrsSvcUuid[ATT_16_UUID_LEN]; /*! Heart Rate Service */ +extern const uint8_t attPassSvcUuid[ATT_16_UUID_LEN]; /*! Phone Alert Status Service */ +extern const uint8_t attBasSvcUuid[ATT_16_UUID_LEN]; /*! Battery Service */ +extern const uint8_t attBpsSvcUuid[ATT_16_UUID_LEN]; /*! Blood Pressure Service */ +extern const uint8_t attAnsSvcUuid[ATT_16_UUID_LEN]; /*! Alert Notification Service */ +extern const uint8_t attHidSvcUuid[ATT_16_UUID_LEN]; /*! Human Interface Device Service */ +extern const uint8_t attSpsSvcUuid[ATT_16_UUID_LEN]; /*! Scan Parameter Service */ +extern const uint8_t attWssSvcUuid[ATT_16_UUID_LEN]; /*! Weight scale service */ + +/*! GATT UUIDs */ +extern const uint8_t attPrimSvcUuid[ATT_16_UUID_LEN]; /*! Primary Service */ +extern const uint8_t attSecSvcUuid[ATT_16_UUID_LEN]; /*! Secondary Service */ +extern const uint8_t attIncUuid[ATT_16_UUID_LEN]; /*! Include */ +extern const uint8_t attChUuid[ATT_16_UUID_LEN]; /*! Characteristic */ + +/*! Descriptor UUIDs */ +extern const uint8_t attChExtUuid[ATT_16_UUID_LEN]; /*! Characteristic Extended Properties */ +extern const uint8_t attChUserDescUuid[ATT_16_UUID_LEN]; /*! Characteristic User Description */ +extern const uint8_t attCliChCfgUuid[ATT_16_UUID_LEN]; /*! Client Characteristic Configuration */ +extern const uint8_t attSrvChCfgUuid[ATT_16_UUID_LEN]; /*! Server Characteristic Configuration */ +extern const uint8_t attChPresFmtUuid[ATT_16_UUID_LEN]; /*! Characteristic Presentation Format */ +extern const uint8_t attAggFmtUuid[ATT_16_UUID_LEN]; /*! Characteristic Aggregate Format */ +extern const uint8_t attValRangeUuid[ATT_16_UUID_LEN]; /*! Valid Range */ +extern const uint8_t attHidRimUuid[ATT_16_UUID_LEN]; /*! HID Report ID Mapping */ + +/*! Characteristic UUIDs */ +extern const uint8_t attDnChUuid[ATT_16_UUID_LEN]; /*! Device Name */ +extern const uint8_t attApChUuid[ATT_16_UUID_LEN]; /*! Appearance */ +extern const uint8_t attPpfChUuid[ATT_16_UUID_LEN]; /*! Peripheral Privacy Flag */ +extern const uint8_t attRaChUuid[ATT_16_UUID_LEN]; /*! Reconnection Address */ +extern const uint8_t attPpcpChUuid[ATT_16_UUID_LEN]; /*! Peripheral Preferred Connection Parameters */ +extern const uint8_t attScChUuid[ATT_16_UUID_LEN]; /*! Service Changed */ +extern const uint8_t attAlChUuid[ATT_16_UUID_LEN]; /*! Alert Level */ +extern const uint8_t attTxpChUuid[ATT_16_UUID_LEN]; /*! Tx Power Level */ +extern const uint8_t attDtChUuid[ATT_16_UUID_LEN]; /*! Date Time */ +extern const uint8_t attDwChUuid[ATT_16_UUID_LEN]; /*! Day of Week */ +extern const uint8_t attDdtChUuid[ATT_16_UUID_LEN]; /*! Day Date Time */ +extern const uint8_t attEt100ChUuid[ATT_16_UUID_LEN]; /*! Exact Time 100 */ +extern const uint8_t attEt256ChUuid[ATT_16_UUID_LEN]; /*! Exact Time 256 */ +extern const uint8_t attDstoChUuid[ATT_16_UUID_LEN]; /*! DST Offset */ +extern const uint8_t attTzChUuid[ATT_16_UUID_LEN]; /*! Time Zone */ +extern const uint8_t attLtiChUuid[ATT_16_UUID_LEN]; /*! Local Time Information */ +extern const uint8_t attStzChUuid[ATT_16_UUID_LEN]; /*! Secondary Time Zone */ +extern const uint8_t attTdstChUuid[ATT_16_UUID_LEN]; /*! Time with DST */ +extern const uint8_t attTaChUuid[ATT_16_UUID_LEN]; /*! Time Accuracy */ +extern const uint8_t attTsChUuid[ATT_16_UUID_LEN]; /*! Time Source */ +extern const uint8_t attRtiChUuid[ATT_16_UUID_LEN]; /*! Reference Time Information */ +extern const uint8_t attTbChUuid[ATT_16_UUID_LEN]; /*! Time Broadcast */ +extern const uint8_t attTucpChUuid[ATT_16_UUID_LEN]; /*! Time Update Control Point */ +extern const uint8_t attTusChUuid[ATT_16_UUID_LEN]; /*! Time Update State */ +extern const uint8_t attGlmChUuid[ATT_16_UUID_LEN]; /*! Glucose Measurement */ +extern const uint8_t attBlChUuid[ATT_16_UUID_LEN]; /*! Battery Level */ +extern const uint8_t attBpsChUuid[ATT_16_UUID_LEN]; /*! Battery Power State */ +extern const uint8_t attBlsChUuid[ATT_16_UUID_LEN]; /*! Battery Level State */ +extern const uint8_t attTmChUuid[ATT_16_UUID_LEN]; /*! Temperature Measurement */ +extern const uint8_t attTtChUuid[ATT_16_UUID_LEN]; /*! Temperature Type */ +extern const uint8_t attItChUuid[ATT_16_UUID_LEN]; /*! Intermediate Temperature */ +extern const uint8_t attTcelChUuid[ATT_16_UUID_LEN]; /*! Temperature Celsius */ +extern const uint8_t attTfahChUuid[ATT_16_UUID_LEN]; /*! Temperature Fahrenheit */ +extern const uint8_t attMiChUuid[ATT_16_UUID_LEN]; /*! Measurement Interval */ +extern const uint8_t attHbrpChUuid[ATT_16_UUID_LEN]; /*! HID Boot Report Mapping */ +extern const uint8_t attSidChUuid[ATT_16_UUID_LEN]; /*! System ID */ +extern const uint8_t attMnsChUuid[ATT_16_UUID_LEN]; /*! Model Number String */ +extern const uint8_t attSnsChUuid[ATT_16_UUID_LEN]; /*! Serial Number String */ +extern const uint8_t attFrsChUuid[ATT_16_UUID_LEN]; /*! Firmware Revision String */ +extern const uint8_t attHrsChUuid[ATT_16_UUID_LEN]; /*! Hardware Revision String */ +extern const uint8_t attSrsChUuid[ATT_16_UUID_LEN]; /*! Software Revision String */ +extern const uint8_t attMfnsChUuid[ATT_16_UUID_LEN]; /*! Manufacturer Name String */ +extern const uint8_t attIeeeChUuid[ATT_16_UUID_LEN]; /*! IEEE 11073-20601 Regulatory Certification Data List */ +extern const uint8_t attCtChUuid[ATT_16_UUID_LEN]; /*! Current Time */ +extern const uint8_t attElChUuid[ATT_16_UUID_LEN]; /*! Elevation */ +extern const uint8_t attLatChUuid[ATT_16_UUID_LEN]; /*! Latitude */ +extern const uint8_t attLongChUuid[ATT_16_UUID_LEN]; /*! Longitude */ +extern const uint8_t attP2dChUuid[ATT_16_UUID_LEN]; /*! Position 2D */ +extern const uint8_t attP3dChUuid[ATT_16_UUID_LEN]; /*! Position 3D */ +extern const uint8_t attVidChUuid[ATT_16_UUID_LEN]; /*! Vendor ID */ +extern const uint8_t attPidChUuid[ATT_16_UUID_LEN]; /*! Product ID */ +extern const uint8_t attHidvChUuid[ATT_16_UUID_LEN]; /*! HID Version */ +extern const uint8_t attGlmcChUuid[ATT_16_UUID_LEN]; /*! Glucose Measurement Context */ +extern const uint8_t attBpmChUuid[ATT_16_UUID_LEN]; /*! Blood Pressure Measurement */ +extern const uint8_t attIcpChUuid[ATT_16_UUID_LEN]; /*! Intermediate Cuff Pressure */ +extern const uint8_t attHrmChUuid[ATT_16_UUID_LEN]; /*! Heart Rate Measurement */ +extern const uint8_t attBslChUuid[ATT_16_UUID_LEN]; /*! Body Sensor Location */ +extern const uint8_t attHrcpChUuid[ATT_16_UUID_LEN]; /*! Heart Rate Control Point */ +extern const uint8_t attRemChUuid[ATT_16_UUID_LEN]; /*! Removable */ +extern const uint8_t attSrChUuid[ATT_16_UUID_LEN]; /*! Service Required */ +extern const uint8_t attStcChUuid[ATT_16_UUID_LEN]; /*! Scientific Temperature in Celsius */ +extern const uint8_t attStrChUuid[ATT_16_UUID_LEN]; /*! String */ +extern const uint8_t attNwaChUuid[ATT_16_UUID_LEN]; /*! Network Availability */ +extern const uint8_t attAsChUuid[ATT_16_UUID_LEN]; /*! Alert Status */ +extern const uint8_t attRcpChUuid[ATT_16_UUID_LEN]; /*! Ringer Control Point */ +extern const uint8_t attRsChUuid[ATT_16_UUID_LEN]; /*! Ringer Setting */ +extern const uint8_t attAcbmChUuid[ATT_16_UUID_LEN]; /*! Alert Category ID Bit Mask */ +extern const uint8_t attAcChUuid[ATT_16_UUID_LEN]; /*! Alert Category ID */ +extern const uint8_t attAncpChUuid[ATT_16_UUID_LEN]; /*! Alert Notification Control Point */ +extern const uint8_t attUasChUuid[ATT_16_UUID_LEN]; /*! Unread Alert Status */ +extern const uint8_t attNaChUuid[ATT_16_UUID_LEN]; /*! New Alert */ +extern const uint8_t attSnacChUuid[ATT_16_UUID_LEN]; /*! Supported New Alert Category */ +extern const uint8_t attSuacChUuid[ATT_16_UUID_LEN]; /*! Supported Unread Alert Category */ +extern const uint8_t attBpfChUuid[ATT_16_UUID_LEN]; /*! Blood Pressure Feature */ +extern const uint8_t attHidiChUuid[ATT_16_UUID_LEN]; /*! HID Information */ +extern const uint8_t attRmChUuid[ATT_16_UUID_LEN]; /*! Report Map */ +extern const uint8_t attHidcpChUuid[ATT_16_UUID_LEN]; /*! HID Control Point */ +extern const uint8_t attRepChUuid[ATT_16_UUID_LEN]; /*! Report */ +extern const uint8_t attPmChUuid[ATT_16_UUID_LEN]; /*! Protocol Mode */ +extern const uint8_t attSiwChUuid[ATT_16_UUID_LEN]; /*! Scan Interval Window */ +extern const uint8_t attPnpChUuid[ATT_16_UUID_LEN]; /*! PnP ID */ +extern const uint8_t attGlfChUuid[ATT_16_UUID_LEN]; /*! Glucose Feature */ +extern const uint8_t attRacpChUuid[ATT_16_UUID_LEN]; /*! Record Access Control Point */ +extern const uint8_t attWmChUuid[ATT_16_UUID_LEN]; /*! Weight measurement */ +extern const uint8_t attWsfChUuid[ATT_16_UUID_LEN]; /*! Weight scale feature */ + +#ifdef __cplusplus +}; +#endif + +#endif /* ATT_UUID_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/dm_api.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,1235 @@ +/*************************************************************************************************/ +/*! + * \file dm_api.h + * + * \brief Device Manager subsystem API. + * + * $Date: 2012-09-11 16:18:57 -0700 (Tue, 11 Sep 2012) $ + * $Revision: 349 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef DM_API_H +#define DM_API_H + +#include "hci_api.h" +#include "cfg_stack.h" +#include "smp_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Device role */ +#define DM_ROLE_MASTER HCI_ROLE_MASTER /*! Role is master */ +#define DM_ROLE_SLAVE HCI_ROLE_SLAVE /*! Role is slave */ + +/*! The GAP discovery mode */ +#define DM_DISC_MODE_NONE 0 /*! GAP non-discoverable */ +#define DM_DISC_MODE_LIMITED 1 /*! GAP limited discoverable mode */ +#define DM_DISC_MODE_GENERAL 2 /*! GAP general discoverable mode */ + +/*! The type of connectable or discoverable of advertising */ +#define DM_ADV_CONN_UNDIRECT 0 /*! Connectable undirected advertising */ +#define DM_ADV_CONN_DIRECT 1 /*! Connectable directed advertising */ +#define DM_ADV_DISC_UNDIRECT 2 /*! Discoverable undirected advertising */ +#define DM_ADV_NONCONN_UNDIRECT 3 /*! Non-connectable undirected advertising */ +#define DM_ADV_SCAN_RESPONSE 4 /*! Scan response */ +#define DM_ADV_NONE 255 /*! For internal use only */ + +/*! Whether data is located in the advertising data or the scan response data */ +#define DM_DATA_LOC_ADV 0 /*! Locate data in the advertising data */ +#define DM_DATA_LOC_SCAN 1 /*! Locate data in the scan response data */ + +/*! The scan type */ +#define DM_SCAN_TYPE_PASSIVE 0 /*! Passive scan */ +#define DM_SCAN_TYPE_ACTIVE 1 /*! Active scan */ + +/*! Advertising channel map */ +#define DM_ADV_CHAN_37 HCI_ADV_CHAN_37 /*! Advertising channel 37 */ +#define DM_ADV_CHAN_38 HCI_ADV_CHAN_38 /*! Advertising channel 38 */ +#define DM_ADV_CHAN_39 HCI_ADV_CHAN_39 /*! Advertising channel 39 */ +#define DM_ADV_CHAN_ALL (HCI_ADV_CHAN_37 | HCI_ADV_CHAN_38 | HCI_ADV_CHAN_39) + +/*! The client ID parameter to function DmConnRegister() */ +#define DM_CLIENT_ID_ATT 0 /*! Identifier for attribute protocol, for internal use only */ +#define DM_CLIENT_ID_SMP 1 /*! Identifier for security manager protocol, for internal use only */ +#define DM_CLIENT_ID_DM 2 /*! Identifier for device manager, for internal use only */ +#define DM_CLIENT_ID_APP 3 /*! Identifier for the application */ +#define DM_CLIENT_ID_MAX 4 /*! For internal use only */ + +/*! Unknown connection ID or other error */ +#define DM_CONN_ID_NONE 0 + +/*! The address type */ +#define DM_ADDR_PUBLIC 0 /*! Public address */ +#define DM_ADDR_RANDOM 1 /*! Random address */ + +/*! Advertising data types */ +#define DM_ADV_TYPE_FLAGS 0x01 /*! Flag bits */ +#define DM_ADV_TYPE_16_UUID_PART 0x02 /*! Partial list of 16 bit UUIDs */ +#define DM_ADV_TYPE_16_UUID 0x03 /*! Complete list of 16 bit UUIDs */ +#define DM_ADV_TYPE_128_UUID_PART 0x06 /*! Partial list of 128 bit UUIDs */ +#define DM_ADV_TYPE_128_UUID 0x07 /*! Complete list of 128 bit UUIDs */ +#define DM_ADV_TYPE_SHORT_NAME 0x08 /*! Shortened local name */ +#define DM_ADV_TYPE_LOCAL_NAME 0x09 /*! Complete local name */ +#define DM_ADV_TYPE_TX_POWER 0x0A /*! TX power level */ +#define DM_ADV_TYPE_CONN_INTERVAL 0x12 /*! Slave preferred connection interval */ +#define DM_ADV_TYPE_SIGNED_DATA 0x13 /*! Signed data */ +#define DM_ADV_TYPE_16_SOLICIT 0x14 /*! Service soliticiation list of 16 bit UUIDs */ +#define DM_ADV_TYPE_128_SOLICIT 0x15 /*! Service soliticiation list of 128 bit UUIDs */ +#define DM_ADV_TYPE_SERVICE_DATA 0x16 /*! Service data */ +#define DM_ADV_TYPE_PUBLIC_TARGET 0x17 /*! Public target address */ +#define DM_ADV_TYPE_RANDOM_TARGET 0x18 /*! Random target address */ +#define DM_ADV_TYPE_APPEARANCE 0x19 /*! Device appearance */ +#define DM_ADV_TYPE_MANUFACTURER 0xFF /*! Manufacturer specific data */ + +/*! Bit mask for flags advertising data type */ +#define DM_FLAG_LE_LIMITED_DISC 0x01 /*! Limited discoverable flag */ +#define DM_FLAG_LE_GENERAL_DISC 0x02 /*! General discoverable flag */ +#define DM_FLAG_LE_BREDR_NOT_SUP 0x04 /*! BR/EDR not supported flag */ + +/*! Advertising data element indexes */ +#define DM_AD_LEN_IDX 0 /*! Advertising data element len */ +#define DM_AD_TYPE_IDX 1 /*! Advertising data element type */ +#define DM_AD_DATA_IDX 2 /*! Advertising data element data */ + +/*! Timeouts defined by the GAP specification; in units of milliseconds */ +#define DM_GAP_LIM_ADV_TIMEOUT 180000 /*! Maximum advertising duration in limited discoverable mode */ +#define DM_GAP_GEN_DISC_SCAN_MIN 10240 /*! Minimum scan duration for general discovery */ +#define DM_GAP_LIM_DISC_SCAN_MIN 10240 /*! Minimum scan duration for limited discovery */ +#define DM_GAP_CONN_PARAM_TIMEOUT 30000 /*! Connection parameter update timeout */ +#define DM_GAP_SCAN_FAST_PERIOD 30720 /*! Minimum time to perform scanning when user initiated */ +#define DM_GAP_ADV_FAST_PERIOD 30000 /*! Minimum time to perform advertising when user initiated */ + +/*! + * Advertising, scanning, and connection parameters defined in the GAP specification. + * In units of 625 microseconds. + */ +#define DM_GAP_SCAN_FAST_INT_MIN 48 /*! Minimum scan interval when user initiated */ +#define DM_GAP_SCAN_FAST_INT_MAX 96 /*! Maximum scan interval when user initiated */ +#define DM_GAP_SCAN_FAST_WINDOW 48 /*! Scan window when user initiated */ +#define DM_GAP_SCAN_SLOW_INT_1 2048 /*! Scan interval 1 when background scannning */ +#define DM_GAP_SCAN_SLOW_WINDOW_1 18 /*! Scan window 1 when background scanning */ +#define DM_GAP_SCAN_SLOW_INT_2 4096 /*! Scan interval 2 when background scannning */ +#define DM_GAP_SCAN_SLOW_WINDOW_2 18 /*! Scan window 2 when background scanning */ +#define DM_GAP_ADV_FAST_INT_MIN 48 /*! Minimum advertising interval when user initiated */ +#define DM_GAP_ADV_FAST_INT_MAX 96 /*! Maximum advertising interval when user initiated */ +#define DM_GAP_ADV_SLOW_INT_MIN 1600 /*! Minimum advertising interval when background advertising */ +#define DM_GAP_ADV_SLOW_INT_MAX 1920 /*! Maximum advertising interval when background advertising */ + +/*! GAP connection establishment latency */ +#define DM_GAP_CONN_EST_LATENCY 0 + +/*! GAP connection intervals in 1.25ms units */ +#define DM_GAP_INITIAL_CONN_INT_MIN 24 /*! Minimum initial connection interval */ +#define DM_GAP_INITIAL_CONN_INT_MAX 40 /*! Maximum initial onnection interval */ + +/*! GAP connection establishment minimum and maximum connection event lengths */ +#define DM_GAP_CONN_EST_MIN_CE_LEN 0 +#define DM_GAP_CONN_EST_MAX_CE_LEN 0 + +/*! GAP peripheral privacy flag characteristic values */ +#define DM_GAP_PRIV_DISABLED 0 +#define DM_GAP_PRIV_ENABLED 1 + +/*! Connection establishment supervision timeout default, in 10ms units */ +#define DM_DEFAULT_EST_SUP_TIMEOUT 2000 + +/*! Pairing authentication/security properties bit mask */ +#define DM_AUTH_BOND_FLAG SMP_AUTH_BOND_FLAG /*! Bonding requested */ +#define DM_AUTH_MITM_FLAG SMP_AUTH_MITM_FLAG /*! MITM (authenticated pairing) requested */ + +/*! Key distribution bit mask */ +#define DM_KEY_DIST_LTK SMP_KEY_DIST_ENC /*! Distribute LTK used for encryption */ +#define DM_KEY_DIST_IRK SMP_KEY_DIST_ID /*! Distribute IRK used for privacy */ +#define DM_KEY_DIST_CSRK SMP_KEY_DIST_SIGN /*! Distribute CSRK used for signed data */ + +/*! Key type used in DM_SEC_KEY_IND */ +#define DM_KEY_LOCAL_LTK 0x01 /*! LTK generated locally for this device */ +#define DM_KEY_PEER_LTK 0x02 /*! LTK received from peer device */ +#define DM_KEY_IRK 0x04 /*! IRK and identity info of peer device */ +#define DM_KEY_CSRK 0x08 /*! CSRK of peer device */ + +/*! Base value for HCI error status values for DM_SEC_PAIR_CMPL_IND */ +#define DM_SEC_HCI_ERR_BASE 0x20 + +#define DM_SEC_LEVEL_NONE 0 /*! Connection has no security */ +#define DM_SEC_LEVEL_ENC 1 /*! Connection is encrypted with unauthenticated key */ +#define DM_SEC_LEVEL_ENC_AUTH 2 /*! Connection is encrypted with authenticated key */ + +/*! Random address types */ +#define DM_RAND_ADDR_STATIC 0xC0 /*! Static address */ +#define DM_RAND_ADDR_RESOLV 0x80 /*! Resolvable private address */ +#define DM_RAND_ADDR_NONRESOLV 0x00 /*! Non-resolvable private address */ + +/*! Get the type of random address */ +#define DM_RAND_ADDR_GET(addr) ((addr)[5] & 0xC0) + +/*! Set the type of random address */ +#define DM_RAND_ADDR_SET(addr, type) {(addr)[5] = ((addr)[5] & 0x3F) | (type);} + +/*! Connection busy/idle state */ +#define DM_CONN_IDLE 0 /*! Connection is idle */ +#define DM_CONN_BUSY 1 /*! Connection is busy */ + +/*! Connection busy/idle state bitmask */ +#define DM_IDLE_SMP_PAIR 0x0001 /*! SMP pairing in progress */ +#define DM_IDLE_DM_ENC 0x0002 /*! DM Encryption setup in progress */ +#define DM_IDLE_ATTS_DISC 0x0004 /*! ATTS service discovery in progress */ +#define DM_IDLE_APP_DISC 0x0008 /*! App framework service discovery in progress */ +#define DM_IDLE_USER_1 0x0010 /*! For use by user application */ +#define DM_IDLE_USER_2 0x0020 /*! For use by user application */ +#define DM_IDLE_USER_3 0x0040 /*! For use by user application */ +#define DM_IDLE_USER_4 0x0080 /*! For use by user application */ + +/*! DM callback events */ +#define DM_CBACK_START 0x20 /*! DM callback event starting value */ +enum +{ + DM_RESET_CMPL_IND = DM_CBACK_START, /*! Reset complete */ + DM_ADV_START_IND, /*! Advertising started */ + DM_ADV_STOP_IND, /*! Advertising stopped */ + DM_ADV_NEW_ADDR_IND, /*! New resolvable address has been generated */ + DM_SCAN_START_IND, /*! Scanning started */ + DM_SCAN_STOP_IND, /*! Scanning stopped */ + DM_SCAN_REPORT_IND, /*! Scan data received from peer device */ + DM_CONN_OPEN_IND, /*! Connection opened */ + DM_CONN_CLOSE_IND, /*! Connection closed */ + DM_CONN_UPDATE_IND, /*! Connection update complete */ + DM_SEC_PAIR_CMPL_IND, /*! Pairing completed successfully */ + DM_SEC_PAIR_FAIL_IND, /*! Pairing failed or other security failure */ + DM_SEC_ENCRYPT_IND, /*! Connection encrypted */ + DM_SEC_ENCRYPT_FAIL_IND, /*! Encryption failed */ + DM_SEC_AUTH_REQ_IND, /*! PIN or OOB data requested for pairing */ + DM_SEC_KEY_IND, /*! Security key indication */ + DM_SEC_LTK_REQ_IND, /*! LTK requested for encyption */ + DM_SEC_PAIR_IND, /*! Incoming pairing request from master */ + DM_SEC_SLAVE_REQ_IND, /*! Incoming security request from slave */ + DM_PRIV_RESOLVED_ADDR_IND, /*! Private address resolved */ + DM_HW_ERROR_IND, /*! Hardware Error */ + DM_VENDOR_SPEC_IND, /*! Vendor specific event */ +}; + +#define DM_CBACK_END DM_VENDOR_SPEC_IND /*! DM callback event ending value */ + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Connection identifier */ +typedef uint8_t dmConnId_t; + +/*! Configuration structure */ +typedef struct +{ + uint8_t dummy; +} dmCfg_t; + +/*! LTK data type */ +typedef struct +{ + uint8_t key[SMP_KEY_LEN]; + uint8_t rand[SMP_RAND8_LEN]; + uint16_t ediv; +} dmSecLtk_t; + +/*! IRK data type */ +typedef struct +{ + uint8_t key[SMP_KEY_LEN]; + bdAddr_t bdAddr; + uint8_t addrType; +} dmSecIrk_t; + +/*! CSRK data type */ +typedef struct +{ + uint8_t key[SMP_KEY_LEN]; +} dmSecCsrk_t; + +/*! union of key types */ +typedef union +{ + dmSecLtk_t ltk; + dmSecIrk_t irk; + dmSecCsrk_t csrk; +} dmSecKey_t; + +/*! Data type for DM_SEC_PAIR_CMPL_IND */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header */ + uint8_t auth; /*! Authentication and bonding flags */ +} dmSecPairCmplIndEvt_t; + +/*! Data type for DM_SEC_ENCRYPT_IND */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header */ + bool_t usingLtk; /*! TRUE if connection encrypted with LTK */ +} dmSecEncryptIndEvt_t; + +/*! Data type for DM_SEC_AUTH_REQ_IND */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header */ + bool_t oob; /*! Out-of-band data requested */ + bool_t display; /*! TRUE if pin is to be displayed */ +} dmSecAuthReqIndEvt_t; + +/*! Data type for DM_SEC_PAIR_IND */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header */ + uint8_t auth; /*! Authentication and bonding flags */ + bool_t oob; /*! Out-of-band pairing data present or not present */ + uint8_t iKeyDist; /*! Initiator key distribution flags */ + uint8_t rKeyDist; /*! Responder key distribution flags */ +} dmSecPairIndEvt_t; + +/*! Data type for DM_SEC_SLAVE_REQ_IND */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header */ + uint8_t auth; /*! Authentication and bonding flags */ +} dmSecSlaveIndEvt_t; + +/*! Data type for DM_SEC_KEY_IND */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header */ + dmSecKey_t keyData; /*! Key data */ + uint8_t type; /*! Key type */ + uint8_t secLevel; /*! Security level of pairing when key was exchanged */ + uint8_t encKeyLen; /*! Length of encryption key used when data was transferred */ +} dmSecKeyIndEvt_t; + +/*! Data type for DM_ADV_NEW_ADDR_IND */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! Header */ + bdAddr_t addr; /*! New resolvable private address */ + bool_t firstTime; /*! TRUE when address is generated for the first time */ +} dmAdvNewAddrIndEvt_t; + +/*! Union of DM callback event data types */ +typedef union +{ + wsfMsgHdr_t hdr; + hciLeAdvReportEvt_t scanReport; + hciLeConnCmplEvt_t connOpen; + hciLeConnUpdateCmplEvt_t connUpdate; + hciDisconnectCmplEvt_t connClose; + dmSecPairCmplIndEvt_t pairCmpl; + dmSecEncryptIndEvt_t encryptInd; + dmSecAuthReqIndEvt_t authReq; + dmSecPairIndEvt_t pairInd; + dmSecSlaveIndEvt_t slaveInd; + dmSecKeyIndEvt_t keyInd; + hciLeLtkReqEvt_t ltkReqInd; + hciVendorSpecEvt_t vendorSpec; + dmAdvNewAddrIndEvt_t advNewAddr; +} dmEvt_t; + +/*! Callback type */ +typedef void (*dmCback_t)(dmEvt_t *pDmEvt); + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn DmRegister + * + * \brief Register a callback with DM for scan and advertising events. + * + * \param cback Client callback function. + * + * \return None. + */ +/*************************************************************************************************/ +void DmRegister(dmCback_t cback); + +/*************************************************************************************************/ +/*! + * \fn DmFindAdType + * + * \brief Find an advertising data element in the given advertising or scan response data. + * + * \param adType Advertising data element type to find. + * \param dataLen Data length. + * \param pData Pointer to advertising or scan response data. + * + * \return Pointer to the advertising data element byte array or NULL if not found. + */ +/*************************************************************************************************/ +uint8_t *DmFindAdType(uint8_t adType, uint8_t dataLen, uint8_t *pData); + +/*************************************************************************************************/ +/*! + * \fn DmAdvInit + * + * \brief Initialize DM advertising. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmAdvStart + * + * \brief Start advertising using the given advertising type and duration. + * + * \param advType Advertising type. + * \param duration The advertising duration, in milliseconds. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvStart(uint8_t advType, uint16_t duration); + +/*************************************************************************************************/ +/*! + * \fn DmAdvStop + * + * \brief Stop advertising. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvStop(void); + +/*************************************************************************************************/ +/*! + * \fn DmAdvSetInterval + * + * \brief Set the minimum and maximum advertising intervals. + * + * \param intervalMin Minimum advertising interval. + * \param intervalMax Maximum advertising interval. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvSetInterval(uint16_t intervalMin, uint16_t intervalMax); + +/*************************************************************************************************/ +/*! + * \fn DmAdvSetChannelMap + * + * \brief Include or exclude certain channels from the advertising channel map. + * + * \param channelMap Advertising channel map. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvSetChannelMap(uint8_t channelMap); + +/*************************************************************************************************/ +/*! + * \fn DmAdvSetData + * + * \brief Set the advertising or scan response data to the given data. + * + * \param location Data location. + * \param len Length of the data. Maximum length is 31 bytes. + * \param pData Pointer to the data. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvSetData(uint8_t location, uint8_t len, uint8_t *pData); + +/*************************************************************************************************/ +/*! + * \fn DmAdvSetAddrType + * + * \brief Set the local address type used while advertising. This function can be used to + * configure advertising to use a random address. + * + * \param addrType Address type. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvSetAddrType(uint8_t addrType); + +/*************************************************************************************************/ +/*! + * \fn DmAdvSetAdValue + * + * \brief Set the value of an advertising data element in the given advertising or + * scan response data. If the element already exists in the data then it is replaced + * with the new value. If the element does not exist in the data it is appended + * to it, space permitting. + * + * \param adType Advertising data element type. + * \param len Length of the value. Maximum length is 29 bytes. + * \param pValue Pointer to the value. + * \param pAdvDataLen Advertising or scan response data length. The new length is returned + * in this parameter. + * \param pAdvData Pointer to advertising or scan response data. + * + * \return TRUE if the element was successfully added to the data, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t DmAdvSetAdValue(uint8_t adType, uint8_t len, uint8_t *pValue, uint8_t *pAdvDataLen, + uint8_t *pAdvData); + +/*************************************************************************************************/ +/*! + * \fn DmAdvSetName + * + * \brief Set the device name in the given advertising or scan response data. If the + * name can only fit in the data if it is shortened, the name is shortened + * and the AD type is changed to DM_ADV_TYPE_SHORT_NAME. + * + * \param len Length of the name. Maximum length is 29 bytes. + * \param pValue Pointer to the name in UTF-8 format. + * \param pAdvDataLen Advertising or scan response data length. The new length is returned + * in this parameter. + * \param pAdvData Pointer to advertising or scan response data. + * + * \return TRUE if the element was successfully added to the data, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t DmAdvSetName(uint8_t len, uint8_t *pValue, uint8_t *pAdvDataLen, uint8_t *pAdvData); + +/*************************************************************************************************/ +/*! + * \fn DmAdvPrivInit + * + * \brief Initialize private advertising. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvPrivInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmAdvPrivStart + * + * \brief Start using a private resolvable address. + * + * \param changeInterval Interval between automatic address changes, in seconds. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvPrivStart(uint16_t changeInterval); + +/*************************************************************************************************/ +/*! + * \fn DmAdvPrivStop + * + * \brief Stop using a private resolvable address. + * + * \return None. + */ +/*************************************************************************************************/ +void DmAdvPrivStop(void); + +/*************************************************************************************************/ +/*! + * \fn DmScanInit + * + * \brief Initialize DM scanning. + * + * \return None. + */ +/*************************************************************************************************/ +void DmScanInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmScanStart + * + * \brief Start scanning. + * + * \param mode Discoverability mode. + * \param scanType Scan type. + * \param filterDup Filter duplicates. Set to TRUE to filter duplicate responses received + * from the same device. Set to FALSE to receive all responses. + * \param duration The scan duration, in milliseconds. If set to zero, scanning will + * continue until DmScanStop() is called. + * + * \return None. + */ +/*************************************************************************************************/ +void DmScanStart(uint8_t mode, uint8_t scanType, bool_t filterDup, uint16_t duration); + +/*************************************************************************************************/ +/*! + * \fn DmScanStop + * + * \brief Stop scanning. + * + * \return None. + */ +/*************************************************************************************************/ +void DmScanStop(void); + +/*************************************************************************************************/ +/*! + * \fn DmScanSetInterval + * + * \brief Set the scan interval and window. + * + * \param scanInterval The scan interval. + * \param scanWindow The scan window. + * + * \return None. + */ +/*************************************************************************************************/ +void DmScanSetInterval(uint16_t scanInterval, uint16_t scanWindow); + +/*************************************************************************************************/ +/*! + * \fn DmScanSetAddrType + * + * \brief Set the local address type used while scanning. This function can be used to + * configure scanning to use a random address. + * + * \param addrType Address type. + * + * \return None. + */ +/*************************************************************************************************/ +void DmScanSetAddrType(uint8_t addrType); + +/*************************************************************************************************/ +/*! + * \fn DmConnInit + * + * \brief Initialize DM connection manager. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmConnMasterInit + * + * \brief Initialize DM connection manager for operation as master. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnMasterInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmConnSlaveInit + * + * \brief Initialize DM connection manager for operation as slave. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnSlaveInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmConnRegister + * + * \brief Register with the DM connection manager. + * + * \param clientId The client identifier. + * \param cback Client callback function. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnRegister(uint8_t clientId, dmCback_t cback); + +/*************************************************************************************************/ +/*! + * \fn DmConnOpen + * + * \brief Open a connection to a peer device with the given address. + * + * \param clientId The client identifier. + * \param addrType Address type. + * \param pAddr Peer device address. + * + * \return Connection identifier. + */ +/*************************************************************************************************/ +dmConnId_t DmConnOpen(uint8_t clientId, uint8_t addrType, uint8_t *pAddr); + +/*************************************************************************************************/ +/*! + * \fn DmConnClose + * + * \brief Close the connection with the give connection identifier. + * + * \param clientId The client identifier. + * \param connId Connection identifier. + * \param reason Reason connection is being closed. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnClose(uint8_t clientId, dmConnId_t connId, uint8_t reason); + +/*************************************************************************************************/ +/*! + * \fn DmConnAccept + * + * \brief Accept a connection from the given peer device by initiating directed advertising. + * + * \param clientId The client identifier. + * \param addrType Address type. + * \param pAddr Peer device address. + * + * \return Connection identifier. + */ +/*************************************************************************************************/ +dmConnId_t DmConnAccept(uint8_t clientId, uint8_t addrType, uint8_t *pAddr); + +/*************************************************************************************************/ +/*! + * \fn DmConnUpdate + * + * \brief Update the connection parameters of an open connection + * + * \param connId Connection identifier. + * \param pConnSpec Connection specification. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnUpdate(dmConnId_t connId, hciConnSpec_t *pConnSpec); + +/*************************************************************************************************/ +/*! + * \fn DmConnSetScanInterval + * + * \brief Set the scan interval and window for created connections created with DmConnOpen(). + * + * \param scanInterval The scan interval. + * \param scanWindow The scan window. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnSetScanInterval(uint16_t scanInterval, uint16_t scanWindow); + +/*************************************************************************************************/ +/*! + * \fn DmConnSetConnSpec + * + * \brief Set the connection specification parameters for connections created with DmConnOpen(). + * + * \param pConnSpec Connection spec parameters. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnSetConnSpec(hciConnSpec_t *pConnSpec); + +/*************************************************************************************************/ +/*! + * \fn DmConnSetAddrType + * + * \brief Set the local address type used for connections created with DmConnOpen(). + * + * \param addrType Address type. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnSetAddrType(uint8_t addrType); + +/*************************************************************************************************/ +/*! + * \fn DmConnSetIdle + * + * \brief Configure a bit in the connection idle state mask as busy or idle. + * + * \param connId Connection identifier. + * \param idleMask Bit in the idle state mask to configure. + * \param idle DM_CONN_BUSY or DM_CONN_IDLE. + * + * \return None. + */ +/*************************************************************************************************/ +void DmConnSetIdle(dmConnId_t connId, uint16_t idleMask, uint8_t idle); + +/*************************************************************************************************/ +/*! + * \fn DmConnCheckIdle + * + * \brief Check if a connection is idle. + * + * \param connId Connection identifier. + * + * \return Zero if connection is idle, nonzero if busy. + */ +/*************************************************************************************************/ +uint16_t DmConnCheckIdle(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn DmDevReset + * + * \brief Reset the device. + * + * \return None. + */ +/*************************************************************************************************/ +void DmDevReset(void); + +/*************************************************************************************************/ +/*! + * \fn DmDevRole + * + * \brief Return the device role indicating master or slave. + * + * \return Device role. + */ +/*************************************************************************************************/ +uint8_t DmDevRole(void); + +/*************************************************************************************************/ +/*! + * \fn DmDevSetRandAddr + * + * \brief Set the random address to be used by the local device. + * + * \param pAddr Random address. + * + * \return None. + */ +/*************************************************************************************************/ +void DmDevSetRandAddr(uint8_t *pAddr); + +/*************************************************************************************************/ +/*! + * \fn DmDevWhiteListAdd + * + * \brief Add a peer device to the white list. Note that this function cannot be called + * while advertising, scanning, or connecting with white list filtering active. + * + * \param addrType Address type. + * \param pAddr Peer device address. + * + * \return None. + */ +/*************************************************************************************************/ +void DmDevWhiteListAdd(uint8_t addrType, uint8_t *pAddr); + +/*************************************************************************************************/ +/*! + * \fn DmDevWhiteListRemove + * + * \brief Remove a peer device from the white list. Note that this function cannot be called + * while advertising, scanning, or connecting with white list filtering active. + * + * \param addrType Address type. + * \param pAddr Peer device address. + * + * \return None. + */ +/*************************************************************************************************/ +void DmDevWhiteListRemove(uint8_t addrType, uint8_t *pAddr); + +/*************************************************************************************************/ +/*! + * \fn DmDevWhiteListClear + * + * \brief Clear the white list. Note that this function cannot be called while + * advertising, scanning, or connecting with white list filtering active. + * + * \return None. + */ +/*************************************************************************************************/ +void DmDevWhiteListClear(void); + +/*************************************************************************************************/ +/*! + * \fn DmDevVsInit + * + * \brief Vendor-specific controller initialization function. + * + * \param param Vendor-specific parameter. + * + * \return None. + */ +/*************************************************************************************************/ +void DmDevVsInit(uint8_t param); + +/*************************************************************************************************/ +/*! + * \fn DmSecInit + * + * \brief Initialize DM security. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmSecPairReq + * + * \brief This function is called by a master device to initiate pairing. + * + * \param connId DM connection ID. + * \param oob Out-of-band pairing data present or not present. + * \param auth Authentication and bonding flags. + * \param iKeyDist Initiator key distribution flags. + * \param rKeyDist Responder key distribution flags. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecPairReq(dmConnId_t connId, bool_t oob, uint8_t auth, uint8_t iKeyDist, uint8_t rKeyDist); + +/*************************************************************************************************/ +/*! + * \fn DmSecPairRsp + * + * \brief This function is called by a slave device to proceed with pairing after a + * DM_SEC_PAIR_IND event is received. + * + * \param connId DM connection ID. + * \param oob Out-of-band pairing data present or not present. + * \param auth Authentication and bonding flags. + * \param iKeyDist Initiator key distribution flags. + * \param rKeyDist Responder key distribution flags. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecPairRsp(dmConnId_t connId, bool_t oob, uint8_t auth, uint8_t iKeyDist, uint8_t rKeyDist); + +/*************************************************************************************************/ +/*! + * \fn DmSecCancelReq + * + * \brief This function is called to cancel the pairing process. + * + * \param connId DM connection ID. + * \param reason Failure reason. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecCancelReq(dmConnId_t connId, uint8_t reason); + +/*************************************************************************************************/ +/*! + * \fn DmSecAuthRsp + * + * \brief This function is called in response to a DM_SEC_AUTH_REQ_IND event to provide + * PIN or OOB data during pairing. + * + * \param connId DM connection ID. + * \param authDataLen Length of PIN or OOB data. + * \param pAuthData pointer to PIN or OOB data. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecAuthRsp(dmConnId_t connId, uint8_t authDataLen, uint8_t *pAuthData); + +/*************************************************************************************************/ +/*! + * \fn DmSecSlaveReq + * + * \brief This function is called by a slave device to request that the master initiates + * pairing or link encryption. + * + * \param connId DM connection ID. + * \param auth Authentication flags. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecSlaveReq(dmConnId_t connId, uint8_t auth); + +/*************************************************************************************************/ +/*! + * \fn DmSecEncryptReq + * + * \brief This function is called by a master device to initiate link encryption. + * + * \param connId DM connection ID. + * \param secLevel Security level of pairing when LTK was exchanged. + * \param pLtk Pointer to LTK parameter structure. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecEncryptReq(dmConnId_t connId, uint8_t secLevel, dmSecLtk_t *pLtk); + +/*************************************************************************************************/ +/*! + * \fn DmSecLtkRsp + * + * \brief This function is called by a slave in response to a DM_SEC_LTK_REQ_IND event + * to provide the long term key used for encryption. + * + * \param connId DM connection ID. + * \param keyFound TRUE if key found. + * \param secLevel Security level of pairing when key was exchanged. + * \param pKey Pointer to the key, if found. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecLtkRsp(dmConnId_t connId, bool_t keyFound, uint8_t secLevel, uint8_t *pKey); + +/*************************************************************************************************/ +/*! + * \fn DmSecSetLocalCsrk + * + * \brief This function sets the local CSRK used by the device. + * + * \param pCsrk Pointer to CSRK. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecSetLocalCsrk(uint8_t *pCsrk); + +/*************************************************************************************************/ +/*! + * \fn DmSecSetLocalIrk + * + * \brief This function sets the local IRK used by the device. + * + * \param pCsrk Pointer to IRK. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSecSetLocalIrk(uint8_t *pIrk); + +/*************************************************************************************************/ +/*! + * \fn DmPrivInit + * + * \brief Initialize DM privacy module. + * + * \return None. + */ +/*************************************************************************************************/ +void DmPrivInit(void); + +/*************************************************************************************************/ +/*! + * \fn DmPrivResolveAddr + * + * \brief Resolve a private resolvable address. When complete the client's callback function + * is called with a DM_PRIV_RESOLVED_ADDR_IND event. The client must wait to receive + * this event before executing this function again. + * + * \param pAddr Peer device address. + * \param pIrk The peer's identity resolving key. + * \param param Client-defined parameter returned with callback event. + * + * \return None. + */ +/*************************************************************************************************/ +void DmPrivResolveAddr(uint8_t *pAddr, uint8_t *pIrk, uint16_t param); + +/*************************************************************************************************/ +/*! + * \fn DmL2cConnUpdateCnf + * + * \brief For internal use only. L2C calls this function to send the result of an L2CAP + * connection update response to DM. + * + * \param handle Connection handle. + * \param reason Connection update response reason code. + * \return None. + */ +/*************************************************************************************************/ +void DmL2cConnUpdateCnf(uint16_t handle, uint16_t reason); + +/*************************************************************************************************/ +/*! + * \fn DmL2cConnUpdateInd + * + * \brief For internal use only. L2C calls this function when it receives a connection update + * request from a peer device. + * + * \param identifier Identifier value. + * \param handle Connection handle. + * \param pConnSpec Connection spec parameters. + * \return None. + */ +/*************************************************************************************************/ +void DmL2cConnUpdateInd(uint8_t identifier, uint16_t handle, hciConnSpec_t *pConnSpec); + +/*************************************************************************************************/ +/*! + * \fn DmConnIdByHandle + * + * \brief For internal use only. Find the connection ID with matching handle. + * + * \param handle Handle to find. + * + * \return Connection ID or DM_CONN_ID_NONE if error. + */ +/*************************************************************************************************/ +dmConnId_t DmConnIdByHandle(uint16_t handle); + +/*************************************************************************************************/ +/*! + * \fn DmConnInUse + * + * \brief For internal use only. Return TRUE if the connection is in use. + * + * \param connId Connection ID. + * + * \return TRUE if the connection is in use, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t DmConnInUse(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn DmConnPeerAddrType + * + * \brief For internal use only. Return the peer address type. + * + * \param connId Connection ID. + * + * \return Peer address type. + */ +/*************************************************************************************************/ +uint8_t DmConnPeerAddrType(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn DmConnPeerAddr + * + * \brief For internal use only. Return the peer device address. + * + * \param connId Connection ID. + * + * \return Pointer to peer device address. + */ +/*************************************************************************************************/ +uint8_t *DmConnPeerAddr(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn DmConnLocalAddrType + * + * \brief For internal use only. Return the local address type. + * + * \param connId Connection ID. + * + * \return Local address type. + */ +/*************************************************************************************************/ +uint8_t DmConnLocalAddrType(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn DmConnLocalAddr + * + * \brief For internal use only. Return the local address. + * + * \param connId Connection ID. + * + * \return Pointer to local address. + */ +/*************************************************************************************************/ +uint8_t *DmConnLocalAddr(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn DmConnSecLevel + * + * \brief For internal use only. Return the security level of the connection. + * + * \param connId Connection ID. + * + * \return Security level of the connection. + */ +/*************************************************************************************************/ +uint8_t DmConnSecLevel(dmConnId_t connId); + +/*************************************************************************************************/ +/*! + * \fn DmSmpEncryptReq + * + * \brief For internal use only. This function is called by SMP to request encryption. + * + * \param connId DM connection ID. + * \param secLevel Security level of pairing when key was exchanged. + * \param pKey Pointer to key. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSmpEncryptReq(dmConnId_t connId, uint8_t secLevel, uint8_t *pKey); + +/*************************************************************************************************/ +/*! + * \fn DmSmpCbackExec + * + * \brief For internal use only. Execute DM callback from SMP procedures. + * + * \param pDmEvt Pointer to callback event data. + * + * \return None. + */ +/*************************************************************************************************/ +void DmSmpCbackExec(dmEvt_t *pDmEvt); + +/*************************************************************************************************/ +/*! + * \fn DmSecGetLocalCsrk + * + * \brief For internal use only. This function gets the local CSRK used by the device. + * + * \return Pointer to CSRK. + */ +/*************************************************************************************************/ +uint8_t *DmSecGetLocalCsrk(void); + +/*************************************************************************************************/ +/*! + * \fn DmSecGetLocalIrk + * + * \brief For internal use only. This function gets the local IRK used by the device. + * + * \return Pointer to IRK. + */ +/*************************************************************************************************/ +uint8_t *DmSecGetLocalIrk(void); + +#ifdef __cplusplus +}; +#endif + +#endif /* DM_API_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/dm_handler.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,67 @@ +/*************************************************************************************************/ +/*! + * \file dm_handler.h + * + * \brief Interface to DM event handler. + * + * $Date: 2012-03-29 13:24:04 -0700 (Thu, 29 Mar 2012) $ + * $Revision: 287 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef DM_HANDLER_H +#define DM_HANDLER_H + +#include "wsf_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn DmHandlerInit + * + * \brief DM handler init function called during system initialization. + * + * \param handlerID WSF handler ID for DM. + * + * \return None. + */ +/*************************************************************************************************/ +void DmHandlerInit(wsfHandlerId_t handlerId); + + +/*************************************************************************************************/ +/*! + * \fn DmHandler + * + * \brief WSF event handler for DM. + * + * \param event WSF event mask. + * \param pMsg WSF message. + * + * \return None. + */ +/*************************************************************************************************/ +void DmHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg); + +#ifdef __cplusplus +}; +#endif + +#endif /* DM_HANDLER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/hci_api.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,375 @@ +/*************************************************************************************************/ +/*! + * \file hci_api.h + * + * \brief HCI subsystem API. + * + * $Date: 2011-10-14 21:35:03 -0700 (Fri, 14 Oct 2011) $ + * $Revision: 191 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef HCI_API_H +#define HCI_API_H + +#include "wsf_types.h" +#include "hci_defs.h" +#include "wsf_os.h" +#include "bda.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Internal event values for the HCI event and sec callbacks */ +#define HCI_RESET_SEQ_CMPL_CBACK_EVT 0 /*! Reset sequence complete */ +#define HCI_LE_CONN_CMPL_CBACK_EVT 1 /*! LE connection complete */ +#define HCI_DISCONNECT_CMPL_CBACK_EVT 2 /*! LE disconnect complete */ +#define HCI_LE_CONN_UPDATE_CMPL_CBACK_EVT 3 /*! LE connection update complete */ +#define HCI_LE_CREATE_CONN_CANCEL_CMD_CMPL_CBACK_EVT 4 /*! LE create connection cancel command complete */ +#define HCI_LE_ADV_REPORT_CBACK_EVT 5 /*! LE advertising report */ +#define HCI_READ_RSSI_CMD_CMPL_CBACK_EVT 6 /*! Read RSSI command complete */ +#define HCI_LE_READ_CHAN_MAP_CMD_CMPL_CBACK_EVT 7 /*! LE Read channel map command complete */ +#define HCI_READ_TX_PWR_LVL_CMD_CMPL_CBACK_EVT 8 /*! Read transmit power level command complete */ +#define HCI_READ_REMOTE_VER_INFO_CMPL_CBACK_EVT 9 /*! Read remote version information complete */ +#define HCI_LE_READ_REMOTE_FEAT_CMPL_CBACK_EVT 10 /*! LE read remote features complete */ +#define HCI_LE_LTK_REQ_REPL_CMD_CMPL_CBACK_EVT 11 /*! LE LTK request reply command complete */ +#define HCI_LE_LTK_REQ_NEG_REPL_CMD_CMPL_CBACK_EVT 12 /*! LE LTK request negative reply command complete */ +#define HCI_ENC_KEY_REFRESH_CMPL_CBACK_EVT 13 /*! Encryption key refresh complete */ +#define HCI_ENC_CHANGE_CBACK_EVT 14 /*! Encryption change */ +#define HCI_LE_LTK_REQ_CBACK_EVT 15 /*! LE LTK request */ +#define HCI_VENDOR_SPEC_CMD_STATUS_CBACK_EVT 16 /*! Vendor specific command status */ +#define HCI_VENDOR_SPEC_CMD_CMPL_CBACK_EVT 17 /*! Vendor specific command complete */ +#define HCI_VENDOR_SPEC_CBACK_EVT 18 /*! Vendor specific */ +#define HCI_HW_ERROR_CBACK_EVT 19 /*! Hardware error */ +#define HCI_LE_ENCRYPT_CMD_CMPL_CBACK_EVT 20 /*! LE encrypt command complete */ +#define HCI_LE_RAND_CMD_CMPL_CBACK_EVT 21 /*! LE rand command complete */ + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Connection specification type */ +typedef struct +{ + uint16_t connIntervalMin; + uint16_t connIntervalMax; + uint16_t connLatency; + uint16_t supTimeout; + uint16_t minCeLen; + uint16_t maxCeLen; +} hciConnSpec_t; + +/*! LE connection complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; + uint8_t role; + uint8_t addrType; + bdAddr_t peerAddr; + uint16_t connInterval; + uint16_t connLatency; + uint16_t supTimeout; + uint8_t clockAccuracy; +} hciLeConnCmplEvt_t; + +/*! Disconnect complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; + uint8_t reason; +} hciDisconnectCmplEvt_t; + +/*! LE connection update complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; + uint16_t connInterval; + uint16_t connLatency; + uint16_t supTimeout; +} hciLeConnUpdateCmplEvt_t; + +/*! LE create connection cancel command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; +} hciLeCreateConnCancelCmdCmplEvt_t; + +/*! LE advertising report event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t *pData; + uint8_t len; + int8_t rssi; + uint8_t eventType; + uint8_t addrType; + bdAddr_t addr; +} hciLeAdvReportEvt_t; + +/*! Read RSSI command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint8_t handle; + int8_t rssi; +} hciReadRssiCmdCmplEvt_t; + +/*! LE Read channel map command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; + uint8_t chanMap[HCI_CHAN_MAP_LEN]; +} hciReadChanMapCmdCmplEvt_t; + +/*! Read transmit power level command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint8_t handle; + int8_t pwrLvl; +} hciReadTxPwrLvlCmdCmplEvt_t; + +/*! Read remote version information complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; + uint8_t version; + uint16_t mfrName; + uint16_t subversion; +} hciReadRemoteVerInfoCmplEvt_t; + +/*! LE read remote features complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; + uint8_t features[HCI_FEAT_LEN]; +} hciLeReadRemoteFeatCmplEvt_t; + +/*! LE LTK request reply command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; +} hciLeLtkReqReplCmdCmplEvt_t; + +/*! LE LTK request negative reply command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; +} hciLeLtkReqNegReplCmdCmplEvt_t; + +/*! Encryption key refresh complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; +} hciEncKeyRefreshCmpl_t; + +/*! Encryption change event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint16_t handle; + uint8_t enabled; +} hciEncChangeEvt_t; + +/*! LE LTK request event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint16_t handle; + uint8_t randNum[HCI_RAND_LEN]; + uint16_t encDiversifier; +} hciLeLtkReqEvt_t; + +/*! Vendor specific command status event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint16_t opcode; +} hciVendorSpecCmdStatusEvt_t; + +/*! Vendor specific command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint16_t opcode; + uint8_t param[1]; +} hciVendorSpecCmdCmplEvt_t; + +/*! Vendor specific event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t param[1]; +} hciVendorSpecEvt_t; + +/*! Hardware error event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t code; +} hciHwErrorEvt_t; + +/*! LE encrypt command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint8_t data[HCI_ENCRYPT_DATA_LEN]; +} hciLeEncryptCmdCmplEvt_t; + +/*! LE rand command complete event */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t status; + uint8_t randNum[HCI_RAND_LEN]; +} hciLeRandCmdCmplEvt_t; + + +/*! Union of all event types */ +typedef union +{ + wsfMsgHdr_t hdr; + wsfMsgHdr_t resetSeqCmpl; + hciLeConnCmplEvt_t leConnCmpl; + hciDisconnectCmplEvt_t disconnectCmpl; + hciLeConnUpdateCmplEvt_t leConnUpdateCmpl; + hciLeCreateConnCancelCmdCmplEvt_t leCreateConnCancelCmdCmpl; + hciLeAdvReportEvt_t leAdvReport; + hciReadRssiCmdCmplEvt_t readRssiCmdCmpl; + hciReadChanMapCmdCmplEvt_t readChanMapCmdCmpl; + hciReadTxPwrLvlCmdCmplEvt_t readTxPwrLvlCmdCmpl; + hciReadRemoteVerInfoCmplEvt_t readRemoteVerInfoCmpl; + hciLeReadRemoteFeatCmplEvt_t leReadRemoteFeatCmpl; + hciLeLtkReqReplCmdCmplEvt_t leLtkReqReplCmdCmpl; + hciLeLtkReqNegReplCmdCmplEvt_t leLtkReqNegReplCmdCmpl; + hciEncKeyRefreshCmpl_t encKeyRefreshCmpl; + hciEncChangeEvt_t encChange; + hciLeLtkReqEvt_t leLtkReq; + hciVendorSpecCmdStatusEvt_t vendorSpecCmdStatus; + hciVendorSpecCmdCmplEvt_t vendorSpecCmdCmpl; + hciVendorSpecEvt_t vendorSpec; + hciHwErrorEvt_t hwError; + hciLeEncryptCmdCmplEvt_t leEncryptCmdCmpl; + hciLeRandCmdCmplEvt_t leRandCmdCmpl; +} hciEvt_t; + +/************************************************************************************************** + Callback Function Types +**************************************************************************************************/ + +typedef void (*hciEvtCback_t)(hciEvt_t *pEvent); +typedef void (*hciSecCback_t)(hciEvt_t *pEvent); +typedef void (*hciAclCback_t)(uint8_t *pData); +typedef void (*hciFlowCback_t)(uint16_t handle, bool_t flowDisabled); + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*! Initialization, registration, and reset */ +void HciEvtRegister(hciEvtCback_t evtCback); +void HciSecRegister(hciSecCback_t secCback); +void HciAclRegister(hciAclCback_t aclCback, hciFlowCback_t flowCback); +void HciResetSequence(void); +void HciVsInit(uint8_t param); + +/*! Optimization interface */ +uint8_t *HciGetBdAddr(void); +uint8_t HciGetWhiteListSize(void); +int8_t HciGetAdvTxPwr(void); +uint16_t HciGetBufSize(void); +uint8_t HciGetNumBufs(void); +uint8_t *HciGetSupStates(void); +uint8_t HciGetLeSupFeat(void); + +/*! ACL data interface */ +void HciSendAclData(uint8_t *pAclData); + +/*! Command interface */ +void HciDisconnectCmd(uint16_t handle, uint8_t reason); +void HciLeAddDevWhiteListCmd(uint8_t addrType, uint8_t *pAddr); +void HciLeClearWhiteListCmd(void); +void HciLeConnUpdateCmd(uint16_t handle, hciConnSpec_t *pConnSpec); +void HciLeCreateConnCmd(uint16_t scanInterval, uint16_t scanWindow, uint8_t filterPolicy, + uint8_t peerAddrType, uint8_t *pPeerAddr, uint8_t ownAddrType, + hciConnSpec_t *pConnSpec); +void HciLeCreateConnCancelCmd(void); +void HciLeEncryptCmd(uint8_t *pKey, uint8_t *pData); +void HciLeLtkReqNegReplCmd(uint16_t handle); +void HciLeLtkReqReplCmd(uint16_t handle, uint8_t *pKey); +void HciLeRandCmd(void); +void HciLeReadAdvTXPowerCmd(void); +void HciLeReadBufSizeCmd(void); +void HciLeReadChanMapCmd(uint16_t handle); +void HciLeReadLocalSupFeatCmd(void); +void HciLeReadRemoteFeatCmd(uint16_t handle); +void HciLeReadSupStatesCmd(void); +void HciLeReadWhiteListSizeCmd(void); +void HciLeRemoveDevWhiteListCmd(uint8_t addrType, uint8_t *pAddr); +void HciLeSetAdvEnableCmd(uint8_t enable); +void HciLeSetAdvDataCmd(uint8_t len, uint8_t *pData); +void HciLeSetAdvParamCmd(uint16_t advIntervalMin, uint16_t advIntervalMax, uint8_t advType, + uint8_t ownAddrType, uint8_t directAddrType, uint8_t *pDirectAddr, + uint8_t advChanMap, uint8_t advFiltPolicy); +void HciLeSetEventMaskCmd(uint8_t *pLeEventMask); +void HciLeSetHostChanClassCmd(uint8_t *pChanMap); +void HciLeSetRandAddrCmd(uint8_t *pAddr); +void HciLeSetScanEnableCmd(uint8_t enable, uint8_t filterDup); +void HciLeSetScanParamCmd(uint8_t scanType, uint16_t scanInterval, uint16_t scanWindow, + uint8_t ownAddrType, uint8_t scanFiltPolicy); +void HciLeSetScanRespDataCmd(uint8_t len, uint8_t *pData); +void HciLeStartEncryptionCmd(uint16_t handle, uint8_t *pRand, uint16_t diversifier, uint8_t *pKey); +void HciReadBdAddrCmd(void); +void HciReadBufSizeCmd(void); +void HciReadLocalSupFeatCmd(void); +void HciReadLocalVerInfoCmd(void); +void HciReadRemoteVerInfoCmd(uint16_t handle); +void HciReadRssiCmd(uint16_t handle); +void HciReadTxPwrLvlCmd(uint16_t handle, uint8_t type); +void HciResetCmd(void); +void HciSetEventMaskCmd(uint8_t *pEventMask); +void HciVendorSpecificCmd(uint16_t opcode, uint8_t len, uint8_t *pData); + +#ifdef __cplusplus +}; +#endif + +#endif /* HCI_API_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/hci_defs.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,462 @@ +/*************************************************************************************************/ +/*! + * \file hci_defs.h + * + * \brief HCI constants and definitions from the Bluetooth specification. + * + * $Date: 2012-06-26 21:53:53 -0700 (Tue, 26 Jun 2012) $ + * $Revision: 337 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef HCI_DEFS_H +#define HCI_DEFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/*! Packet definitions */ +#define HCI_CMD_HDR_LEN 3 /*! Command packet header length */ +#define HCI_ACL_HDR_LEN 4 /*! ACL packet header length */ +#define HCI_EVT_HDR_LEN 2 /*! Event packet header length */ +#define HCI_EVT_PARAM_MAX_LEN 255 /*! Maximum length of event packet parameters */ +#define HCI_PB_FLAG_MASK 0x1000 /*! ACL packet boundary flag mask */ +#define HCI_PB_START 0x0000 /*! Packet boundary flag, start */ +#define HCI_PB_CONTINUE 0x1000 /*! Packet boundary flag, continue */ +#define HCI_HANDLE_MASK 0x0FFF /*! Mask for handle bits in ACL packet */ +#define HCI_HANDLE_NONE 0xFFFF /*! Value for invalid handle */ + +/*! Packet types */ +#define HCI_CMD_TYPE 1 /*! HCI command packet */ +#define HCI_ACL_TYPE 2 /*! HCI ACL data packet */ +#define HCI_EVT_TYPE 4 /*! HCI event packet */ + +/*! Error codes */ +#define HCI_SUCCESS 0x00 /*! Success */ +#define HCI_ERR_UNKNOWN_CMD 0x01 /*! Unknown HCI command */ +#define HCI_ERR_UNKNOWN_HANDLE 0x02 /*! Unknown connection identifier */ +#define HCI_ERR_HARDWARE_FAILURE 0x03 /*! Hardware failure */ +#define HCI_ERR_PAGE_TIMEOUT 0x04 /*! Page timeout */ +#define HCI_ERR_AUTH_FAILURE 0x05 /*! Authentication failure */ +#define HCI_ERR_KEY_MISSING 0x06 /*! PIN or key missing */ +#define HCI_ERR_MEMORY_EXCEEDED 0x07 /*! Memory capacity exceeded */ +#define HCI_ERR_CONN_TIMEOUT 0x08 /*! Connection timeout */ +#define HCI_ERR_CONN_LIMIT 0x09 /*! Connection limit exceeded */ +#define HCI_ERR_SYNCH_CONN_LIMIT 0x0A /*! Synchronous connection limit exceeded */ +#define HCI_ERR_ACL_CONN_EXISTS 0x0B /*! ACL connection already exists */ +#define HCI_ERR_CMD_DISALLOWED 0x0C /*! Command disallowed */ +#define HCI_ERR_REJ_RESOURCES 0x0D /*! Connection rejected limited resources */ +#define HCI_ERR_REJ_SECURITY 0x0E /*! Connection rejected security reasons */ +#define HCI_ERR_REJ_BD_ADDR 0x0F /*! Connection rejected unacceptable BD_ADDR */ +#define HCI_ERR_ACCEPT_TIMEOUT 0x10 /*! Connection accept timeout exceeded */ +#define HCI_ERR_UNSUP_FEAT 0x11 /*! Unsupported feature or parameter value */ +#define HCI_ERR_INVALID_PARAM 0x12 /*! Invalid HCI command parameters */ +#define HCI_ERR_REMOTE_TERMINATED 0x13 /*! Remote user terminated connection */ +#define HCI_ERR_REMOTE_RESOURCES 0x14 /*! Remote device low resources */ +#define HCI_ERR_REMOTE_POWER_OFF 0x15 /*! Remote device power off */ +#define HCI_ERR_LOCAL_TERMINATED 0x16 /*! Connection terminated by local host */ +#define HCI_ERR_REPEATED_ATTEMPTS 0x17 /*! Repeated attempts */ +#define HCI_ERR_PAIRING_NOT_ALLOWED 0x18 /*! Pairing not allowed */ +#define HCI_ERR_UNKNOWN_LMP_PDU 0x19 /*! Unknown LMP PDU */ +#define HCI_ERR_UNSUP_REMOTE_FEAT 0x1A /*! Unsupported remote feature */ +#define HCI_ERR_SCO_OFFSET 0x1B /*! SCO offset rejected */ +#define HCI_ERR_SCO_INTERVAL 0x1C /*! SCO interval rejected */ +#define HCI_ERR_SCO_MODE 0x1D /*! SCO air mode rejected */ +#define HCI_ERR_LMP_PARAM 0x1E /*! Invalid LMP parameters */ +#define HCI_ERR_UNSPECIFIED 0x1F /*! Unspecified error */ +#define HCI_ERR_UNSUP_LMP_PARAM 0x20 /*! Unsupported LMP parameter value */ +#define HCI_ERR_ROLE_CHANGE 0x21 /*! Role change not allowed */ +#define HCI_ERR_LL_RESP_TIMEOUT 0x22 /*! LL response timeout */ +#define HCI_ERR_LMP_COLLISION 0x23 /*! LMP error transaction collision */ +#define HCI_ERR_LMP_PDU 0x24 /*! LMP pdu not allowed */ +#define HCI_ERR_ENCRYPT_MODE 0x25 /*! Encryption mode not acceptable */ +#define HCI_ERR_LINK_KEY 0x26 /*! Link key can not be changed */ +#define HCI_ERR_UNSUP_QOS 0x27 /*! Requested qos not supported */ +#define HCI_ERR_INSTANT_PASSED 0x28 /*! Instant passed */ +#define HCI_ERR_UNSUP_UNIT_KEY 0x29 /*! Pairing with unit key not supported */ +#define HCI_ERR_TRANSACT_COLLISION 0x2A /*! Different transaction collision */ +#define HCI_ERR_CHANNEL_CLASS 0x2E /*! Channel classification not supported */ +#define HCI_ERR_MEMORY 0x2F /*! Insufficient security */ +#define HCI_ERR_PARAMETER_RANGE 0x30 /*! Parameter out of mandatory range */ +#define HCI_ERR_ROLE_SWITCH_PEND 0x32 /*! Role switch pending */ +#define HCI_ERR_RESERVED_SLOT 0x34 /*! Reserved slot violation */ +#define HCI_ERR_ROLE_SWITCH 0x35 /*! Role switch failed */ +#define HCI_ERR_INQ_TOO_LARGE 0x36 /*! Extended inquiry response too large */ +#define HCI_ERR_UNSUP_SSP 0x37 /*! Secure simple pairing not supported by host */ +#define HCI_ERR_HOST_BUSY_PAIRING 0x38 /*! Host busy - pairing */ +#define HCI_ERR_NO_CHANNEL 0x39 /*! Connection rejected no suitable channel */ +#define HCI_ERR_CONTROLLER_BUSY 0x3A /*! Controller busy */ +#define HCI_ERR_CONN_INTERVAL 0x3B /*! Unacceptable connection interval */ +#define HCI_ERR_ADV_TIMEOUT 0x3C /*! Directed advertising timeout */ +#define HCI_ERR_MIC_FAILURE 0x3D /*! Connection terminated due to MIC failure */ +#define HCI_ERR_CONN_FAIL 0x3E /*! Connection failed to be established */ +#define HCI_ERR_MAC_CONN_FAIL 0x3F /*! MAC connection failed */ + +/*! Command groups */ +#define HCI_OGF_NOP 0x00 /*! No operation */ +#define HCI_OGF_LINK_CONTROL 0x01 /*! Link control */ +#define HCI_OGF_LINK_POLICY 0x02 /*! Link policy */ +#define HCI_OGF_CONTROLLER 0x03 /*! Controller and baseband */ +#define HCI_OGF_INFORMATIONAL 0x04 /*! Informational parameters */ +#define HCI_OGF_STATUS 0x05 /*! Status parameters */ +#define HCI_OGF_TESTING 0x06 /*! Testing */ +#define HCI_OGF_LE_CONTROLLER 0x08 /*! LE controller */ +#define HCI_OGF_VENDOR_SPEC 0x3F /*! Vendor specific */ + +/*! NOP command */ +#define HCI_OCF_NOP 0x00 + +/*! Link control commands */ +#define HCI_OCF_DISCONNECT 0x06 +#define HCI_OCF_READ_REMOTE_VER_INFO 0x1D + +/*! Link policy commands (none used for LE) */ + +/*! Controller and baseband commands */ +#define HCI_OCF_SET_EVENT_MASK 0x01 +#define HCI_OCF_RESET 0x03 +#define HCI_OCF_READ_TX_PWR_LVL 0x2D +#define HCI_OCF_SET_CONTROLLER_TO_HOST_FC 0x31 +#define HCI_OCF_HOST_BUFFER_SIZE 0x33 +#define HCI_OCF_HOST_NUM_CMPL_PKTS 0x35 + +/*! Informational commands */ +#define HCI_OCF_READ_LOCAL_VER_INFO 0x01 +#define HCI_OCF_READ_LOCAL_SUP_CMDS 0x02 +#define HCI_OCF_READ_LOCAL_SUP_FEAT 0x03 +#define HCI_OCF_READ_BUF_SIZE 0x05 +#define HCI_OCF_READ_BD_ADDR 0x09 + +/*! Status commands */ +#define HCI_OCF_READ_RSSI 0x05 + +/*! LE controller commands */ +#define HCI_OCF_LE_SET_EVENT_MASK 0x01 +#define HCI_OCF_LE_READ_BUF_SIZE 0x02 +#define HCI_OCF_LE_READ_LOCAL_SUP_FEAT 0x03 +#define HCI_OCF_LE_SET_RAND_ADDR 0x05 +#define HCI_OCF_LE_SET_ADV_PARAM 0x06 +#define HCI_OCF_LE_READ_ADV_TX_POWER 0x07 +#define HCI_OCF_LE_SET_ADV_DATA 0x08 +#define HCI_OCF_LE_SET_SCAN_RESP_DATA 0x09 +#define HCI_OCF_LE_SET_ADV_ENABLE 0x0A +#define HCI_OCF_LE_SET_SCAN_PARAM 0x0B +#define HCI_OCF_LE_SET_SCAN_ENABLE 0x0C +#define HCI_OCF_LE_CREATE_CONN 0x0D +#define HCI_OCF_LE_CREATE_CONN_CANCEL 0x0E +#define HCI_OCF_LE_READ_WHITE_LIST_SIZE 0x0F +#define HCI_OCF_LE_CLEAR_WHITE_LIST 0x10 +#define HCI_OCF_LE_ADD_DEV_WHITE_LIST 0x11 +#define HCI_OCF_LE_REMOVE_DEV_WHITE_LIST 0x12 +#define HCI_OCF_LE_CONN_UPDATE 0x13 +#define HCI_OCF_LE_SET_HOST_CHAN_CLASS 0x14 +#define HCI_OCF_LE_READ_CHAN_MAP 0x15 +#define HCI_OCF_LE_READ_REMOTE_FEAT 0x16 +#define HCI_OCF_LE_ENCRYPT 0x17 +#define HCI_OCF_LE_RAND 0x18 +#define HCI_OCF_LE_START_ENCRYPTION 0x19 +#define HCI_OCF_LE_LTK_REQ_REPL 0x1A +#define HCI_OCF_LE_LTK_REQ_NEG_REPL 0x1B +#define HCI_OCF_LE_READ_SUP_STATES 0x1C +#define HCI_OCF_LE_RECEIVER_TEST 0x1D +#define HCI_OCF_LE_TRANSMITTER_TEST 0x1E +#define HCI_OCF_LE_TEST_END 0x1F + +/*! Opcode manipulation macros */ +#define HCI_OPCODE(ogf, ocf) (((ogf) << 10) + (ocf)) +#define HCI_OGF(opcode) ((opcode) >> 10) +#define HCI_OCF(opcode) ((opcode) & 0x03FF) + +/*! Command opcodes */ +#define HCI_OPCODE_NOP HCI_OPCODE(HCI_OGF_NOP, HCI_OCF_NOP) + +#define HCI_OPCODE_DISCONNECT HCI_OPCODE(HCI_OGF_LINK_CONTROL, HCI_OCF_DISCONNECT) +#define HCI_OPCODE_READ_REMOTE_VER_INFO HCI_OPCODE(HCI_OGF_LINK_CONTROL, HCI_OCF_READ_REMOTE_VER_INFO) + +#define HCI_OPCODE_SET_EVENT_MASK HCI_OPCODE(HCI_OGF_CONTROLLER, HCI_OCF_SET_EVENT_MASK) +#define HCI_OPCODE_RESET HCI_OPCODE(HCI_OGF_CONTROLLER, HCI_OCF_RESET) +#define HCI_OPCODE_READ_TX_PWR_LVL HCI_OPCODE(HCI_OGF_CONTROLLER, HCI_OCF_READ_TX_PWR_LVL) +#define HCI_OPCODE_SET_CONTROLLER_TO_HOST_FC HCI_OPCODE(HCI_OGF_CONTROLLER, HCI_OCF_SET_CONTROLLER_TO_HOST_FC) +#define HCI_OPCODE_HOST_BUFFER_SIZE HCI_OPCODE(HCI_OGF_CONTROLLER, HCI_OCF_HOST_BUFFER_SIZE) +#define HCI_OPCODE_HOST_NUM_CMPL_PKTS HCI_OPCODE(HCI_OGF_CONTROLLER, HCI_OCF_HOST_NUM_CMPL_PKTS) + +#define HCI_OPCODE_READ_LOCAL_VER_INFO HCI_OPCODE(HCI_OGF_INFORMATIONAL, HCI_OCF_READ_LOCAL_VER_INFO) +#define HCI_OPCODE_READ_LOCAL_SUP_CMDS HCI_OPCODE(HCI_OGF_INFORMATIONAL, HCI_OCF_READ_LOCAL_SUP_CMDS) +#define HCI_OPCODE_READ_LOCAL_SUP_FEAT HCI_OPCODE(HCI_OGF_INFORMATIONAL, HCI_OCF_READ_LOCAL_SUP_FEAT) +#define HCI_OPCODE_READ_BUF_SIZE HCI_OPCODE(HCI_OGF_INFORMATIONAL, HCI_OCF_READ_BUF_SIZE) +#define HCI_OPCODE_READ_BD_ADDR HCI_OPCODE(HCI_OGF_INFORMATIONAL, HCI_OCF_READ_BD_ADDR) + +#define HCI_OPCODE_READ_RSSI HCI_OPCODE(HCI_OGF_STATUS, HCI_OCF_READ_RSSI) + +#define HCI_OPCODE_LE_SET_EVENT_MASK HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_EVENT_MASK) +#define HCI_OPCODE_LE_READ_BUF_SIZE HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_READ_BUF_SIZE) +#define HCI_OPCODE_LE_READ_LOCAL_SUP_FEAT HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_READ_LOCAL_SUP_FEAT) +#define HCI_OPCODE_LE_SET_RAND_ADDR HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_RAND_ADDR) +#define HCI_OPCODE_LE_SET_ADV_PARAM HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_ADV_PARAM) +#define HCI_OPCODE_LE_READ_ADV_TX_POWER HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_READ_ADV_TX_POWER) +#define HCI_OPCODE_LE_SET_ADV_DATA HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_ADV_DATA) +#define HCI_OPCODE_LE_SET_SCAN_RESP_DATA HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_SCAN_RESP_DATA) +#define HCI_OPCODE_LE_SET_ADV_ENABLE HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_ADV_ENABLE) +#define HCI_OPCODE_LE_SET_SCAN_PARAM HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_SCAN_PARAM) +#define HCI_OPCODE_LE_SET_SCAN_ENABLE HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_SCAN_ENABLE) +#define HCI_OPCODE_LE_CREATE_CONN HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_CREATE_CONN) +#define HCI_OPCODE_LE_CREATE_CONN_CANCEL HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_CREATE_CONN_CANCEL) +#define HCI_OPCODE_LE_READ_WHITE_LIST_SIZE HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_READ_WHITE_LIST_SIZE) +#define HCI_OPCODE_LE_CLEAR_WHITE_LIST HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_CLEAR_WHITE_LIST) +#define HCI_OPCODE_LE_ADD_DEV_WHITE_LIST HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_ADD_DEV_WHITE_LIST) +#define HCI_OPCODE_LE_REMOVE_DEV_WHITE_LIST HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_REMOVE_DEV_WHITE_LIST) +#define HCI_OPCODE_LE_CONN_UPDATE HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_CONN_UPDATE) +#define HCI_OPCODE_LE_SET_HOST_CHAN_CLASS HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_SET_HOST_CHAN_CLASS) +#define HCI_OPCODE_LE_READ_CHAN_MAP HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_READ_CHAN_MAP) +#define HCI_OPCODE_LE_READ_REMOTE_FEAT HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_READ_REMOTE_FEAT) +#define HCI_OPCODE_LE_ENCRYPT HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_ENCRYPT) +#define HCI_OPCODE_LE_RAND HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_RAND) +#define HCI_OPCODE_LE_START_ENCRYPTION HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_START_ENCRYPTION) +#define HCI_OPCODE_LE_LTK_REQ_REPL HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_LTK_REQ_REPL) +#define HCI_OPCODE_LE_LTK_REQ_NEG_REPL HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_LTK_REQ_NEG_REPL) +#define HCI_OPCODE_LE_READ_SUP_STATES HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_READ_SUP_STATES) +#define HCI_OPCODE_LE_RECEIVER_TEST HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_RECEIVER_TEST) +#define HCI_OPCODE_LE_TRANSMITTER_TEST HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_TRANSMITTER_TEST) +#define HCI_OPCODE_LE_TEST_END HCI_OPCODE(HCI_OGF_LE_CONTROLLER, HCI_OCF_LE_TEST_END) + +/*! Command parameter lengths */ +#define HCI_LEN_NOP 0 + +#define HCI_LEN_DISCONNECT 3 +#define HCI_LEN_READ_REMOTE_VER_INFO 2 + +#define HCI_LEN_SET_EVENT_MASK 8 +#define HCI_LEN_RESET 0 +#define HCI_LEN_READ_TX_PWR_LVL 3 +#define HCI_LEN_SET_CONTROLLER_TO_HOST_FC 1 +#define HCI_LEN_HOST_BUFFER_SIZE 8 +#define HCI_LEN_HOST_NUM_CMPL_PKTS 1 + +#define HCI_LEN_READ_LOCAL_VER_INFO 0 +#define HCI_LEN_READ_LOCAL_SUP_CMDS 0 +#define HCI_LEN_READ_LOCAL_SUP_FEAT 0 +#define HCI_LEN_READ_BUF_SIZE 0 +#define HCI_LEN_READ_BD_ADDR 0 + +#define HCI_LEN_READ_RSSI 2 + +#define HCI_LEN_LE_SET_EVENT_MASK 8 +#define HCI_LEN_LE_READ_BUF_SIZE 0 +#define HCI_LEN_LE_READ_LOCAL_SUP_FEAT 0 +#define HCI_LEN_LE_SET_RAND_ADDR 6 +#define HCI_LEN_LE_SET_ADV_PARAM 15 +#define HCI_LEN_LE_READ_ADV_TX_POWER 0 +#define HCI_LEN_LE_SET_ADV_DATA 32 +#define HCI_LEN_LE_SET_SCAN_RESP_DATA 32 +#define HCI_LEN_LE_SET_ADV_ENABLE 1 +#define HCI_LEN_LE_SET_SCAN_PARAM 7 +#define HCI_LEN_LE_SET_SCAN_ENABLE 2 +#define HCI_LEN_LE_CREATE_CONN 25 +#define HCI_LEN_LE_CREATE_CONN_CANCEL 0 +#define HCI_LEN_LE_READ_WHITE_LIST_SIZE 0 +#define HCI_LEN_LE_CLEAR_WHITE_LIST 0 +#define HCI_LEN_LE_ADD_DEV_WHITE_LIST 7 +#define HCI_LEN_LE_REMOVE_DEV_WHITE_LIST 7 +#define HCI_LEN_LE_CONN_UPDATE 14 +#define HCI_LEN_LE_SET_HOST_CHAN_CLASS 5 +#define HCI_LEN_LE_READ_CHAN_MAP 2 +#define HCI_LEN_LE_READ_REMOTE_FEAT 2 +#define HCI_LEN_LE_ENCRYPT 32 +#define HCI_LEN_LE_RAND 0 +#define HCI_LEN_LE_START_ENCRYPTION 28 +#define HCI_LEN_LE_LTK_REQ_REPL 18 +#define HCI_LEN_LE_LTK_REQ_NEG_REPL 2 +#define HCI_LEN_LE_READ_SUP_STATES 0 +#define HCI_LEN_LE_RECEIVER_TEST 1 +#define HCI_LEN_LE_TRANSMITTER_TEST 3 +#define HCI_LEN_LE_TEST_END 0 + +/*! Events */ +#define HCI_DISCONNECT_CMPL_EVT 0x05 +#define HCI_ENC_CHANGE_EVT 0x08 +#define HCI_READ_REMOTE_VER_INFO_CMPL_EVT 0x0C +#define HCI_CMD_CMPL_EVT 0x0E +#define HCI_CMD_STATUS_EVT 0x0F +#define HCI_HW_ERROR_EVT 0x10 +#define HCI_NUM_CMPL_PKTS_EVT 0x13 +#define HCI_DATA_BUF_OVERFLOW_EVT 0x1A +#define HCI_ENC_KEY_REFRESH_CMPL_EVT 0x30 +#define HCI_LE_META_EVT 0x3E +#define HCI_VENDOR_SPEC_EVT 0xFF + +/*! LE Subevents */ +#define HCI_LE_CONN_CMPL_EVT 0x01 +#define HCI_LE_ADV_REPORT_EVT 0x02 +#define HCI_LE_CONN_UPDATE_CMPL_EVT 0x03 +#define HCI_LE_READ_REMOTE_FEAT_CMPL_EVT 0x04 +#define HCI_LE_LTK_REQ_EVT 0x05 + +/*! Event parameter lengths */ +#define HCI_LEN_DISCONNECT_CMPL 4 +#define HCI_LEN_ENC_CHANGE 5 +#define HCI_LEN_LE_CONN_CMPL 19 +#define HCI_LEN_LE_CONN_UPDATE_CMPL 9 +#define HCI_LEN_LE_READ_REMOTE_FEAT_CMPL 12 +#define HCI_LEN_LE_LTK_REQ 13 + +/*! Supported commands */ +#define HCI_SUP_DISCONNECT 0x20 /*! Byte 0 */ +#define HCI_SUP_READ_REMOTE_VER_INFO 0x80 /*! Byte 2 */ +#define HCI_SUP_SET_EVENT_MASK 0x40 /*! Byte 5 */ +#define HCI_SUP_RESET 0x80 /*! Byte 5 */ +#define HCI_SUP_READ_TX_PWR_LVL 0x04 /*! Byte 10 */ +#define HCI_SUP_SET_CONTROLLER_TO_HOST_FC 0x20 /*! Byte 10 */ +#define HCI_SUP_HOST_BUFFER_SIZE 0x40 /*! Byte 10 */ +#define HCI_SUP_HOST_NUM_CMPL_PKTS 0x80 /*! Byte 10 */ +#define HCI_SUP_READ_LOCAL_VER_INFO 0x08 /*! Byte 14 */ +#define HCI_SUP_READ_LOCAL_SUP_FEAT 0x20 /*! Byte 14 */ +#define HCI_SUP_READ_BD_ADDR 0x02 /*! Byte 15 */ +#define HCI_SUP_READ_RSSI 0x20 /*! Byte 15 */ +#define HCI_SUP_LE_SET_EVENT_MASK 0x01 /*! Byte 25 */ +#define HCI_SUP_LE_READ_BUF_SIZE 0x02 /*! Byte 25 */ +#define HCI_SUP_LE_READ_LOCAL_SUP_FEAT 0x04 /*! Byte 25 */ +#define HCI_SUP_LE_SET_RAND_ADDR 0x10 /*! Byte 25 */ +#define HCI_SUP_LE_SET_ADV_PARAM 0x20 /*! Byte 25 */ +#define HCI_SUP_LE_READ_ADV_TX_POWER 0x40 /*! Byte 25 */ +#define HCI_SUP_LE_SET_ADV_DATA 0x80 /*! Byte 25 */ +#define HCI_SUP_LE_SET_SCAN_RESP_DATA 0x01 /*! Byte 26 */ +#define HCI_SUP_LE_SET_ADV_ENABLE 0x02 /*! Byte 26 */ +#define HCI_SUP_LE_SET_SCAN_PARAM 0x04 /*! Byte 26 */ +#define HCI_SUP_LE_SET_SCAN_ENABLE 0x08 /*! Byte 26 */ +#define HCI_SUP_LE_CREATE_CONN 0x10 /*! Byte 26 */ +#define HCI_SUP_LE_CREATE_CONN_CANCEL 0x20 /*! Byte 26 */ +#define HCI_SUP_LE_READ_WHITE_LIST_SIZE 0x40 /*! Byte 26 */ +#define HCI_SUP_LE_CLEAR_WHITE_LIST 0x80 /*! Byte 26 */ +#define HCI_SUP_LE_ADD_DEV_WHITE_LIST 0x01 /*! Byte 27 */ +#define HCI_SUP_LE_REMOVE_DEV_WHITE_LIST 0x02 /*! Byte 27 */ +#define HCI_SUP_LE_CONN_UPDATE 0x04 /*! Byte 27 */ +#define HCI_SUP_LE_SET_HOST_CHAN_CLASS 0x08 /*! Byte 27 */ +#define HCI_SUP_LE_READ_CHAN_MAP 0x10 /*! Byte 27 */ +#define HCI_SUP_LE_READ_REMOTE_FEAT 0x20 /*! Byte 27 */ +#define HCI_SUP_LE_ENCRYPT 0x40 /*! Byte 27 */ +#define HCI_SUP_LE_RAND 0x80 /*! Byte 27 */ +#define HCI_SUP_LE_START_ENCRYPTION 0x01 /*! Byte 28 */ +#define HCI_SUP_LE_LTK_REQ_REPL 0x02 /*! Byte 28 */ +#define HCI_SUP_LE_LTK_REQ_NEG_REPL 0x04 /*! Byte 28 */ +#define HCI_SUP_LE_READ_SUP_STATES 0x08 /*! Byte 28 */ +#define HCI_SUP_LE_RECEIVER_TEST 0x10 /*! Byte 28 */ +#define HCI_SUP_LE_TRANSMITTER_TEST 0x20 /*! Byte 28 */ +#define HCI_SUP_LE_TEST_END 0x40 /*! Byte 28 */ + +/*! Event mask */ +#define HCI_EVT_MASK_DISCONNECT_CMPL 0x10 /*! Byte 0 */ +#define HCI_EVT_MASK_ENC_CHANGE 0x80 /*! Byte 0 */ +#define HCI_EVT_MASK_READ_REMOTE_VER_INFO_CMPL 0x08 /*! Byte 1 */ +#define HCI_EVT_MASK_HW_ERROR 0x80 /*! Byte 1 */ +#define HCI_EVT_MASK_DATA_BUF_OVERFLOW 0x02 /*! Byte 3 */ +#define HCI_EVT_MASK_ENC_KEY_REFRESH_CMPL 0x80 /*! Byte 5 */ +#define HCI_EVT_MASK_LE_META 0x20 /*! Byte 7 */ + +/*! LE event mask */ +#define HCI_EVT_MASK_LE_CONN_CMPL_EVT 0x01 /*! Byte 0 */ +#define HCI_EVT_MASK_LE_ADV_REPORT_EVT 0x02 /*! Byte 0 */ +#define HCI_EVT_MASK_LE_CONN_UPDATE_CMPL_EVT 0x04 /*! Byte 0 */ +#define HCI_EVT_MASK_LE_READ_REMOTE_FEAT_CMPL_EVT 0x08 /*! Byte 0 */ +#define HCI_EVT_MASK_LE_LTK_REQ_EVT 0x10 /*! Byte 0 */ + +/*! LE supported features */ +#define HCI_LE_SUP_FEAT_ENCRYPTION 0x01 + +/*! Advertising command parameters */ +#define HCI_ADV_MIN_INTERVAL 0x0020 /*! Minimum advertising interval */ +#define HCI_ADV_NONCONN_MIN_INTERVAL 0x00A0 /*! Minimum nonconnectable adv. interval */ +#define HCI_ADV_MAX_INTERVAL 0x4000 /*! Maximum advertising interval */ +#define HCI_ADV_TYPE_CONN_UNDIRECT 0x00 /*! Connectable undirected advertising */ +#define HCI_ADV_TYPE_CONN_DIRECT 0x01 /*! Connectable directed advertising */ +#define HCI_ADV_TYPE_DISC_UNDIRECT 0x02 /*! Discoverable undirected advertising */ +#define HCI_ADV_TYPE_NONCONN_UNDIRECT 0x03 /*! Nonconnectable undirected advertising */ +#define HCI_ADV_CHAN_37 0x01 /*! Advertising channel 37 */ +#define HCI_ADV_CHAN_38 0x02 /*! Advertising channel 38 */ +#define HCI_ADV_CHAN_39 0x04 /*! Advertising channel 39 */ +#define HCI_ADV_FILT_NONE 0x00 /*! No scan request or connection filtering */ +#define HCI_ADV_FILT_SCAN 0x01 /*! White list filters scan requests */ +#define HCI_ADV_FILT_CONN 0x02 /*! White list filters connections */ +#define HCI_ADV_FILT_ALL 0x03 /*! White list filters scan req. and conn. */ + +/*! Scan command parameters */ +#define HCI_SCAN_TYPE_PASSIVE 0 /*! Passive scan */ +#define HCI_SCAN_TYPE_ACTIVE 1 /*! Active scan */ +#define HCI_SCAN_INTERVAL_MIN 0x0004 /*! Minimum scan interval */ +#define HCI_SCAN_INTERVAL_MAX 0x4000 /*! Maximum scan interval */ +#define HCI_SCAN_INTERVAL_DEFAULT 0x0010 /*! Default scan interval */ +#define HCI_SCAN_WINDOW_MIN 0x0004 /*! Minimum scan window */ +#define HCI_SCAN_WINDOW_MAX 0x4000 /*! Maximum scan window */ +#define HCI_SCAN_WINDOW_DEFAULT 0x0010 /*! Default scan window */ + +/*! Connection command parameters */ +#define HCI_CONN_INTERVAL_MIN 0x0006 /*! Minimum connection interval */ +#define HCI_CONN_INTERVAL_MAX 0x0C80 /*! Maximum connection interval */ +#define HCI_CONN_LATENCY_MAX 0x01F3 /*! Maximum connection latency */ +#define HCI_SUP_TIMEOUT_MIN 0x000A /*! Minimum supervision timeout */ +#define HCI_SUP_TIMEOUT_MAX 0x0C80 /*! Maximum supervision timeout */ + +/*! Connection event parameters */ +#define HCI_ROLE_MASTER 0 /*! Role is master */ +#define HCI_ROLE_SLAVE 1 /*! Role is slave */ +#define HCI_CLOCK_500PPM 0x00 /*! 500 ppm clock accuracy */ +#define HCI_CLOCK_250PPM 0x01 /*! 250 ppm clock accuracy */ +#define HCI_CLOCK_150PPM 0x02 /*! 150 ppm clock accuracy */ +#define HCI_CLOCK_100PPM 0x03 /*! 100 ppm clock accuracy */ +#define HCI_CLOCK_75PPM 0x04 /*! 75 ppm clock accuracy */ +#define HCI_CLOCK_50PPM 0x05 /*! 50 ppm clock accuracy */ +#define HCI_CLOCK_30PPM 0x06 /*! 30 ppm clock accuracy */ +#define HCI_CLOCK_20PPM 0x07 /*! 20 ppm clock accuracy */ + +/*! Advertising report event parameters */ +#define HCI_ADV_CONN_UNDIRECT 0x00 /*! Connectable undirected advertising */ +#define HCI_ADV_CONN_DIRECT 0x01 /*! Connectable directed advertising */ +#define HCI_ADV_DISC_UNDIRECT 0x02 /*! Discoverable undirected advertising */ +#define HCI_ADV_NONCONN_UNDIRECT 0x03 /*! Non-connectable undirected advertising */ +#define HCI_ADV_SCAN_RESPONSE 0x04 /*! Scan response */ + +/*! Misc command parameters */ +#define HCI_READ_TX_PWR_CURRENT 0 /*! Read current tx power */ +#define HCI_READ_TX_PWR_MAX 1 /*! Read maximum tx power */ +#define HCI_TX_PWR_MIN -30 /*! Minimum tx power dBm */ +#define HCI_TX_PWR_MAX 20 /*! Maximum tx power dBm */ +#define HCI_VERSION 6 /*! HCI specification version */ +#define HCI_RSSI_MIN -127 /*! Minimum RSSI dBm */ +#define HCI_RSSI_MAX 20 /*! Maximum RSSI dBm */ +#define HCI_ADDR_TYPE_PUBLIC 0 /*! Public device address */ +#define HCI_ADDR_TYPE_RANDOM 1 /*! Random device address */ +#define HCI_FILT_NONE 0 /*! No white list filtering */ +#define HCI_FILT_WHITE_LIST 1 /*! White list filtering */ +#define HCI_ROLE_MASTER 0 /*! Role is master */ +#define HCI_ROLE_SLAVE 1 /*! Role is slave */ + +/*! Parameter lengths */ +#define HCI_EVT_MASK_LEN 8 /*! Length of event mask byte array */ +#define HCI_LE_EVT_MASK_LEN 8 /*! Length of LE event mask byte array */ +#define HCI_FEAT_LEN 8 /*! Length of features byte array */ +#define HCI_ADV_DATA_LEN 31 /*! Length of advertising data */ +#define HCI_SCAN_DATA_LEN 31 /*! Length of scan response data */ +#define HCI_CHAN_MAP_LEN 5 /*! Length of channel map byte array */ +#define HCI_KEY_LEN 16 /*! Length of encryption key */ +#define HCI_ENCRYPT_DATA_LEN 16 /*! Length of data used in encryption */ +#define HCI_RAND_LEN 8 /*! Length of random number */ +#define HCI_LE_STATES_LEN 8 /*! Length of LE states byte array */ + +/*! Wicentric company ID */ +#define HCI_ID_WICENTRIC 0x005F + +#ifdef __cplusplus +}; +#endif + +#endif /* HCI_DEFS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/hci_handler.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,67 @@ +/*************************************************************************************************/ +/*! + * \file hci_handler.h + * + * \brief Interface to HCI event handler. + * + * $Date: 2012-03-29 13:24:04 -0700 (Thu, 29 Mar 2012) $ + * $Revision: 287 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef HCI_HANDLER_H +#define HCI_HANDLER_H + +#include "wsf_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn HciHandlerInit + * + * \brief HCI handler init function called during system initialization. + * + * \param handlerID WSF handler ID for HCI. + * + * \return None. + */ +/*************************************************************************************************/ +void HciHandlerInit(wsfHandlerId_t handlerId); + + +/*************************************************************************************************/ +/*! + * \fn HciHandler + * + * \brief WSF event handler for HCI. + * + * \param event WSF event mask. + * \param pMsg WSF message. + * + * \return None. + */ +/*************************************************************************************************/ +void HciHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg); + +#ifdef __cplusplus +}; +#endif + +#endif /* HCI_HANDLER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/l2c_api.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,173 @@ +/*************************************************************************************************/ +/*! + * \file l2c_api.h + * + * \brief L2CAP subsystem API. + * + * $Date: 2012-03-07 22:32:20 -0800 (Wed, 07 Mar 2012) $ + * $Revision: 268 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef L2C_API_H +#define L2C_API_H + +#include "hci_api.h" +#include "l2c_defs.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Control callback message events */ +#define L2C_CTRL_FLOW_ENABLE_IND 0 /*! Data flow enabled */ +#define L2C_CTRL_FLOW_DISABLE_IND 1 /*! Data flow disabled */ + +/************************************************************************************************** + Callback Function Types +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn l2cDataCback_t + * + * \brief This callback function sends a received L2CAP packet to the client. + * + * \param handle The connection handle. + * \param len The length of the L2CAP payload data in pPacket. + * \param pPacket A buffer containing the packet. + * + * \return None. + */ +/*************************************************************************************************/ +typedef void (*l2cDataCback_t)(uint16_t handle, uint16_t len, uint8_t *pPacket); + +/*************************************************************************************************/ +/*! + * \fn l2cCtrlCback_t + * + * \brief This callback function sends control messages to the client. + * + * \param pMsg Pointer to message structure. + * + * \return None. + */ +/*************************************************************************************************/ +typedef void (*l2cCtrlCback_t)(wsfMsgHdr_t *pMsg); + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn L2cInit + * + * \brief Initialize L2C subsystem. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cInit(void); + +/*************************************************************************************************/ +/*! + * \fn L2cMasterInit + * + * \brief Initialize L2C for operation as a Bluetooth LE master. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cMasterInit(void); + +/*************************************************************************************************/ +/*! + * \fn L2cSlaveInit + * + * \brief Initialize L2C for operation as a Bluetooth LE slave. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cSlaveInit(void); + +/*************************************************************************************************/ +/*! + * \fn L2cRegister + * + * \brief called by the L2C client, such as ATT or SMP, to register for the given CID. + * + * \param cid channel identifier. + * \param dataCback Callback function for L2CAP data received for this CID. + * \param ctrlCback Callback function for control events for this CID. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cRegister(uint16_t cid, l2cDataCback_t dataCback, l2cCtrlCback_t ctrlCback); + +/*************************************************************************************************/ +/*! + * \fn L2cDataReq + * + * \brief Send an L2CAP data packet on the given CID. + * + * \param cid The channel identifier. + * \param handle The connection handle. The client receives this handle from DM. + * \param len The length of the payload data in pPacket. + * \param pPacket A buffer containing the packet. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cDataReq(uint16_t cid, uint16_t handle, uint16_t len, uint8_t *pL2cPacket); + +/*************************************************************************************************/ +/*! + * \fn L2cDmConnUpdateReq + * + * \brief This function is called by DM to send an L2CAP connection update request. + * + * \param handle The connection handle. + * \param pConnSpec Pointer to the connection specification structure. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cDmConnUpdateReq(uint16_t handle, hciConnSpec_t *pConnSpec); + +/*************************************************************************************************/ +/*! + * \fn L2cDmConnUpdateRsp + * + * \brief This function is called by DM to send an L2CAP connection update response. + * + * \param identifier Identifier value previously passed from L2C to DM. + * \param handle The connection handle. + * \param result Connection update response result. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cDmConnUpdateRsp(uint8_t identifier, uint16_t handle, uint16_t result); + +#ifdef __cplusplus +}; +#endif + +#endif /* L2C_API_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/l2c_defs.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,76 @@ +/*************************************************************************************************/ +/*! + * \file l2c_defs.h + * + * \brief L2CAP constants and definitions from the Bluetooth specification. + * + * $Date: 2011-10-14 21:35:03 -0700 (Fri, 14 Oct 2011) $ + * $Revision: 191 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef L2C_DEFS_H +#define L2C_DEFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Packet definitions */ +#define L2C_HDR_LEN 4 /*! L2CAP packet header length */ +#define L2C_MIN_MTU 23 /*! Minimum packet payload MTU for LE */ +#define L2C_SIG_HDR_LEN 4 /*! L2CAP signaling command header length */ + +/*! Start of L2CAP payload in an HCI ACL packet buffer */ +#define L2C_PAYLOAD_START (HCI_ACL_HDR_LEN + L2C_HDR_LEN) + +/*! L2CAP signaling packet base length, including HCI header */ +#define L2C_SIG_PKT_BASE_LEN (HCI_ACL_HDR_LEN + L2C_HDR_LEN + L2C_SIG_HDR_LEN) + +/*! Signaling packet parameter lengths */ +#define L2C_SIG_CONN_UPDATE_REQ_LEN 8 +#define L2C_SIG_CONN_UPDATE_RSP_LEN 2 +#define L2C_SIG_CMD_REJ_LEN 2 + +/*! Connection identifiers */ +#define L2C_CID_ATT 0x0004 /*! CID for attribute protocol */ +#define L2C_CID_LE_SIGNALING 0x0005 /*! CID for LE signaling */ +#define L2C_CID_SMP 0x0006 /*! CID for security manager protocol */ + +/*! Signaling codes */ +#define L2C_SIG_CMD_REJ 0x01 /*! Comand reject */ +#define L2C_SIG_CONN_UPDATE_REQ 0x12 /*! Connection parameter update request */ +#define L2C_SIG_CONN_UPDATE_RSP 0x13 /*! Connection parameter update response */ + +/*! Signaling response code flag */ +#define L2C_SIG_RSP_FLAG 0x01 + +/*! Command reject reason codes */ +#define L2C_REJ_NOT_UNDERSTOOD 0x0000 /*! Command not understood */ +#define L2C_REJ_MTU_EXCEEDED 0x0001 /*! Signaling MTU exceeded */ +#define L2C_REJ_INVALID_CID 0x0002 /*! Invalid CID in request */ + +/*! Connection parameter update result */ +#define L2C_CONN_PARAM_ACCEPTED 0x0000 /*! Connection parameters accepted */ +#define L2C_CONN_PARAM_REJECTED 0x0001 /*! Connection parameters rejected */ + + +#ifdef __cplusplus +}; +#endif + +#endif /* L2C_DEFS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/l2c_handler.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,66 @@ +/*************************************************************************************************/ +/*! + * \file l2c_handler.h + * + * \brief L2CAP handler interface. + * + * $Date $ + * $Revision $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef L2C_HANDLER_H +#define L2C_HANDLER_H + +#include "wsf_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn L2cSlaveHandlerInit + * + * \brief Event handler initialization function for L2C when operating as a slave. + * + * \param handlerId ID for this event handler. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cSlaveHandlerInit(wsfHandlerId_t handlerId); + +/*************************************************************************************************/ +/*! + * \fn L2cSlaveHandler + * + * \brief The WSF event handler for L2C when operating as a slave. + * + * \param event Event mask. + * \param pMsg Pointer to message. + * + * \return None. + */ +/*************************************************************************************************/ +void L2cSlaveHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg); + +#ifdef __cplusplus +}; +#endif + +#endif /* L2C_HANDLER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/smp_api.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,195 @@ +/*************************************************************************************************/ +/*! + * \file smp_api.h + * + * \brief SMP subsystem API. + * + * $Date: 2011-10-14 21:35:03 -0700 (Fri, 14 Oct 2011) $ + * $Revision: 191 $ + * + * Copyright (c) 2010-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef SMP_API_H +#define SMP_API_H + +#include "wsf_os.h" +#include "smp_defs.h" +#include "dm_api.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Event handler messages for SMP state machines */ +enum +{ + SMP_MSG_API_PAIR_REQ = 1, /*! API pairing request */ + SMP_MSG_API_PAIR_RSP, /*! API pairing response */ + SMP_MSG_API_CANCEL_REQ, /*! API cancel request */ + SMP_MSG_API_AUTH_RSP, /*! API pin response */ + SMP_MSG_API_SECURITY_REQ, /*! API security request */ + SMP_MSG_CMD_PKT, /*! SMP command packet received */ + SMP_MSG_CMD_PAIRING_FAILED, /*! SMP pairing failed packet received */ + SMP_MSG_DM_ENCRYPT_CMPL, /*! Link encrypted */ + SMP_MSG_DM_ENCRYPT_FAILED, /*! Link encryption failed */ + SMP_MSG_DM_CONN_CLOSE, /*! Connection closed */ + SMP_MSG_WSF_AES_CMPL, /*! AES calculation complete */ + SMP_MSG_INT_SEND_NEXT_KEY, /*! Send next key to be distributed */ + SMP_MSG_INT_MAX_ATTEMPTS, /*! Maximum pairing attempts reached */ + SMP_MSG_INT_PAIRING_CMPL, /*! Pairing complete */ + SMP_MSG_INT_TIMEOUT, /*! Pairing protocol timeout */ + SMP_NUM_MSGS +}; + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Configurable parameters */ +typedef struct +{ + uint16_t attemptTimeout; /*! 'Repeated attempts' timeout in msec */ + uint8_t ioCap; /*! I/O Capability */ + uint8_t minKeyLen; /*! Minimum encryption key length */ + uint8_t maxKeyLen; /*! Maximum encryption key length */ + uint8_t maxAttempts; /*! Attempts to trigger 'repeated attempts' timeout */ + uint8_t auth; /*! Device authentication requirements */ +} smpCfg_t; + +/*! Data type for SMP_MSG_API_PAIR_REQ and SMP_MSG_API_PAIR_RSP */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t oob; + uint8_t auth; + uint8_t iKeyDist; + uint8_t rKeyDist; +} smpDmPair_t; + +/*! Data type for SMP_MSG_API_AUTH_RSP */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t authData[SMP_OOB_LEN]; + uint8_t authDataLen; +} smpDmAuthRsp_t; + +/*! Data type for SMP_MSG_API_SECURITY_REQ */ +typedef struct +{ + wsfMsgHdr_t hdr; + uint8_t auth; +} smpDmSecurityReq_t; + +/*! Union SMP DM message data types */ +typedef union +{ + wsfMsgHdr_t hdr; + smpDmPair_t pair; + smpDmAuthRsp_t authRsp; + smpDmSecurityReq_t securityReq; +} smpDmMsg_t; + +/************************************************************************************************** + Global Variables; +**************************************************************************************************/ + +/*! Configuration pointer */ +extern smpCfg_t *pSmpCfg; + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn SmpiInit + * + * \brief Initialize SMP initiator role. + * + * \return None. + */ +/*************************************************************************************************/ +void SmpiInit(void); + +/*************************************************************************************************/ +/*! + * \fn SmprInit + * + * \brief Initialize SMP responder role. + * + * \return None. + */ +/*************************************************************************************************/ +void SmprInit(void); + +/*************************************************************************************************/ +/*! + * \fn SmpNonInit + * + * \brief Use this SMP init function when SMP is not supported. + * + * \return None. + */ +/*************************************************************************************************/ +void SmpNonInit(void); + +/*************************************************************************************************/ +/*! + * \fn SmpDmMsgSend + * + * \brief This function is called by DM to send a message to SMP. + * + * \param pMsg Pointer to message structure. + * + * \return None. + */ +/*************************************************************************************************/ +void SmpDmMsgSend(smpDmMsg_t *pMsg); + +/*************************************************************************************************/ +/*! + * \fn SmpDmEncryptInd + * + * \brief This function is called by DM to notify SMP of encrypted link status. + * + * \param pMsg Pointer to HCI message structure. + * + * \return None. + */ +/*************************************************************************************************/ +void SmpDmEncryptInd(wsfMsgHdr_t *pMsg); + +/*************************************************************************************************/ +/*! + * \fn SmpDmGetStk + * + * \brief Return the STK for the given connection. + * + * \param connId Connection identifier. + * \param pSecLevel Returns the security level of pairing when STK was created. + * + * \return Pointer to STK or NULL if not available. + */ +/*************************************************************************************************/ +uint8_t *SmpDmGetStk(dmConnId_t connId, uint8_t *pSecLevel); + +#ifdef __cplusplus +}; +#endif + +#endif /* SMP_API_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/smp_defs.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,122 @@ +/*************************************************************************************************/ +/*! + * \file smp_defs.h + * + * \brief Security manager constants and definitions from the Bluetooth specification. + * + * $Date: 2011-10-14 21:35:03 -0700 (Fri, 14 Oct 2011) $ + * $Revision: 191 $ + * + * Copyright (c) 2010-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef SMP_DEFS_H +#define SMP_DEFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! PDU format */ +#define SMP_HDR_LEN 1 /*! Attribute PDU header length */ + +/*! Protocol timeout */ +#define SMP_TIMEOUT 30 /*! Protocol timeout in seconds */ + +/*! Encryption key size */ +#define SMP_KEY_SIZE_MAX 16 /*! Maximum encryption key size */ +#define SMP_KEY_SIZE_MIN 7 /*! Minimum encryption key size */ + +/*! OOB and PIN data lengths in bytes */ +#define SMP_OOB_LEN 16 +#define SMP_PIN_LEN 3 + +/*! Error codes */ +#define SMP_ERR_PASSKEY_ENTRY 0x01 /*! User input of passkey failed */ +#define SMP_ERR_OOB 0x02 /*! OOB data is not available */ +#define SMP_ERR_AUTH_REQ 0x03 /*! Authentication requirements cannot be met */ +#define SMP_ERR_CONFIRM_VALUE 0x04 /*! Confirm value does not match */ +#define SMP_ERR_PAIRING_NOT_SUP 0x05 /*! Pairing is not supported by the device */ +#define SMP_ERR_ENC_KEY_SIZE 0x06 /*! Insufficient encryption key size */ +#define SMP_ERR_COMMAND_NOT_SUP 0x07 /*! Command not supported */ +#define SMP_ERR_UNSPECIFIED 0x08 /*! Unspecified reason */ +#define SMP_ERR_ATTEMPTS 0x09 /*! Repeated attempts */ +#define SMP_ERR_INVALID_PARAM 0x0A /*! Invalid parameter or command length */ + +/*! Proprietary internal error codes */ +#define SMP_ERR_MEMORY 0xE0 /*! Out of memory */ +#define SMP_ERR_TIMEOUT 0xE1 /*! Transaction timeout */ + +/*! Command codes */ +#define SMP_CMD_PAIR_REQ 0x01 /*! Pairing Request */ +#define SMP_CMD_PAIR_RSP 0x02 /*! Pairing Response */ +#define SMP_CMD_PAIR_CNF 0x03 /*! Pairing Confirm */ +#define SMP_CMD_PAIR_RAND 0x04 /*! Pairing Random */ +#define SMP_CMD_PAIR_FAIL 0x05 /*! Pairing Failed */ +#define SMP_CMD_ENC_INFO 0x06 /*! Encryption Information */ +#define SMP_CMD_MASTER_ID 0x07 /*! Master Identification */ +#define SMP_CMD_ID_INFO 0x08 /*! Identity Information */ +#define SMP_CMD_ID_ADDR_INFO 0x09 /*! Identity Address Information */ +#define SMP_CMD_SIGN_INFO 0x0A /*! Signing Information */ +#define SMP_CMD_SECURITY_REQ 0x0B /*! Security Request */ +#define SMP_CMD_MAX 0x0C /*! Command code maximum */ + +/*! Command packet lengths */ +#define SMP_PAIR_REQ_LEN 7 +#define SMP_PAIR_RSP_LEN 7 +#define SMP_PAIR_CNF_LEN 17 +#define SMP_PAIR_RAND_LEN 17 +#define SMP_PAIR_FAIL_LEN 2 +#define SMP_ENC_INFO_LEN 17 +#define SMP_MASTER_ID_LEN 11 +#define SMP_ID_INFO_LEN 17 +#define SMP_ID_ADDR_INFO_LEN 8 +#define SMP_SIGN_INFO_LEN 17 +#define SMP_SECURITY_REQ_LEN 2 + +/*! I/O capabilities */ +#define SMP_IO_DISP_ONLY 0x00 /*! DisplayOnly */ +#define SMP_IO_DISP_YES_NO 0x01 /*! DisplayYesNo */ +#define SMP_IO_KEY_ONLY 0x02 /*! KeyboardOnly */ +#define SMP_IO_NO_IN_NO_OUT 0x03 /*! NoInputNoOutput */ +#define SMP_IO_KEY_DISP 0x04 /*! KeyboardDisplay */ + +/*! OOB data present */ +#define SMP_OOB_DATA_NONE 0x00 +#define SMP_OOB_DATA_PRESENT 0x01 + +/*! Authentication/security properties bit mask */ +#define SMP_AUTH_BOND_MASK 0x03 /*! Mask for bonding bits */ +#define SMP_AUTH_BOND_FLAG 0x01 /*! Bonding requested */ +#define SMP_AUTH_MITM_FLAG 0x04 /*! MITM (authenticated pairing) requested */ + +/*! Key distribution bit mask */ +#define SMP_KEY_DIST_ENC 0x01 /*! Distribute LTK */ +#define SMP_KEY_DIST_ID 0x02 /*! Distribute IRK */ +#define SMP_KEY_DIST_SIGN 0x04 /*! Distribute CSRK */ +#define SMP_KEY_DIST_MASK (SMP_KEY_DIST_ENC | SMP_KEY_DIST_ID | SMP_KEY_DIST_SIGN) + +/*! Various parameter lengths */ +#define SMP_RAND_LEN 16 +#define SMP_CONFIRM_LEN 16 +#define SMP_KEY_LEN 16 +#define SMP_RAND8_LEN 8 + +#ifdef __cplusplus +}; +#endif + +#endif /* SMP_DEFS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/stack/include/smp_handler.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,67 @@ +/*************************************************************************************************/ +/*! + * \file smp_handler.h + * + * \brief Interface to SMP event handler. + * + * $Date: 2012-03-29 13:24:04 -0700 (Thu, 29 Mar 2012) $ + * $Revision: 287 $ + * + * Copyright (c) 2010-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef SMP_HANDLER_H +#define SMP_HANDLER_H + +#include "wsf_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn SmpHandlerInit + * + * \brief SMP handler init function called during system initialization. + * + * \param handlerID WSF handler ID for SMP. + * + * \return None. + */ +/*************************************************************************************************/ +void SmpHandlerInit(wsfHandlerId_t handlerId); + + +/*************************************************************************************************/ +/*! + * \fn SmpHandler + * + * \brief WSF event handler for SMP. + * + * \param event WSF event mask. + * \param pMsg WSF message. + * + * \return None. + */ +/*************************************************************************************************/ +void SmpHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg); + +#ifdef __cplusplus +}; +#endif + +#endif /* SMP_HANDLER_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/util/bda.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,109 @@ +/*************************************************************************************************/ +/*! + * \file bda.h + * + * \brief Bluetooth device address utilities. + * + * $Date: 2012-05-08 10:58:07 -0700 (Tue, 08 May 2012) $ + * $Revision: 316 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef BDA_H +#define BDA_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! BD address length */ +#define BDA_ADDR_LEN 6 + +/*! BD address string length */ +#define BDA_ADDR_STR_LEN (BDA_ADDR_LEN * 2) + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! BD address data type */ +typedef uint8_t bdAddr_t[BDA_ADDR_LEN]; + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn BdaCpy + * + * \brief Copy a BD address from source to destination. + * + * \param pDst Pointer to destination. + * \param pSrc Pointer to source. + * + * \return None. + */ +/*************************************************************************************************/ +void BdaCpy(uint8_t *pDst, uint8_t *pSrc); + + +/*************************************************************************************************/ +/*! + * \fn BdaCmp + * + * \brief Compare two BD addresses. + * + * \param pAddr1 First address. + * \param pAddr2 Second address. + * + * \return TRUE if addresses match, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t BdaCmp(uint8_t *pAddr1, uint8_t *pAddr2); + +/*************************************************************************************************/ +/*! + * \fn BdaClr + * + * \brief Set a BD address to all zeros. + * + * \param pDst Pointer to destination. + * + * \return pDst + BDA_ADDR_LEN + */ +/*************************************************************************************************/ +uint8_t *BdaClr(uint8_t *pDst); + +/*************************************************************************************************/ +/*! + * \fn Bda2Str + * + * \brief Convert a BD address to a string. + * + * \param pAddr Pointer to BD address. + * + * \return Pointer to string. + */ +/*************************************************************************************************/ +char *Bda2Str(uint8_t *pAddr); + +#ifdef __cplusplus +}; +#endif + +#endif /* BDA_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/generic/wsf_os_int.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,105 @@ +/*************************************************************************************************/ +/*! + * \file wsf_os_int.h + * + * \brief Software foundation OS platform-specific interface file. + * + * $Date: 2012-10-01 13:53:07 -0700 (Mon, 01 Oct 2012) $ + * $Revision: 357 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef WSF_OS_INT_H +#define WSF_OS_INT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/* Task events */ +#define WSF_MSG_QUEUE_EVENT 0x01 /* Message queued for event handler */ +#define WSF_TIMER_EVENT 0x02 /* Timer expired for event handler */ +#define WSF_HANDLER_EVENT 0x04 /* Event set for event handler */ + +/* Derive task from handler ID */ +#define WSF_TASK_FROM_ID(handlerID) (((handlerID) >> 4) & 0x0F) + +/* Derive handler from handler ID */ +#define WSF_HANDLER_FROM_ID(handlerID) ((handlerID) & 0x0F) + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/* Event handler ID data type */ +typedef uint8_t wsfHandlerId_t; + +/* Event handler event mask data type */ +typedef uint8_t wsfEventMask_t; + +/* Task ID data type */ +typedef wsfHandlerId_t wsfTaskId_t; + +/* Task event mask data type */ +typedef uint8_t wsfTaskEvent_t; + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn wsfOsReadyToSleep + * + * \brief Check if WSF is ready to sleep. + * + * \param None. + * + * \return Return TRUE if there are no pending WSF task events set, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t wsfOsReadyToSleep(void); + +/*************************************************************************************************/ +/*! + * \fn wsfOsDispatcher + * + * \brief Event dispatched. Designed to be called repeatedly from infinite loop. + * + * \param None. + * + * \return None. + */ +/*************************************************************************************************/ +void wsfOsDispatcher(void); + +/*************************************************************************************************/ +/*! + * \fn WsfOsShutdown + * + * \brief Shutdown OS. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfOsShutdown(void); + +#ifdef __cplusplus +}; +#endif + +#endif /* WSF_OS_INT_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/generic/wsf_types.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,61 @@ +/*************************************************************************************************/ +/*! + * \file wsf_types.h + * + * \brief Platform-independent data types. + * + * $Date: 2012-04-28 22:02:14 -0700 (Sat, 28 Apr 2012) $ + * $Revision: 306 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef WSF_TYPES_H +#define WSF_TYPES_H + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/* Integer data types */ +#if ((defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) && \ + (__ICC8051__ == 0)) || defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) +#include <stdint.h> +#else +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef signed short int16_t; +typedef unsigned short uint16_t; +typedef signed long int32_t; +typedef unsigned long uint32_t; +#endif + +/* Boolean data type */ +typedef uint8_t bool_t; + +#endif /* WSF_TYPES_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/include/wsf_buf.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,137 @@ +/*************************************************************************************************/ +/*! + * \file wsf_buf.h + * + * \brief Buffer pool service. + * + * $Date: 2013-05-13 15:20:24 -0700 (Mon, 13 May 2013) $ + * $Revision: 612 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef WSF_BUF_H +#define WSF_BUF_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Length of the buffer statistics array */ +#define WSF_BUF_STATS_MAX_LEN 128 + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Buffer pool descriptor structure */ +typedef struct +{ + uint16_t len; /*! length of buffers in pool */ + uint8_t num; /*! number of buffers in pool */ +} wsfBufPoolDesc_t; + + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn WsfBufInit + * + * \brief Initialize the buffer pool service. This function should only be called once + * upon system initialization. + * + * \param bufMemLen Length in bytes of memory pointed to by pBufMem. + * \param pBufMem Memory in which to store the pools used by the buffer pool service. + * \param numPools Number of buffer pools. + * \param pDesc Array of buffer pool descriptors, one for each pool. + * + * \return TRUE if initialization was successful, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t WsfBufInit(uint16_t bufMemLen, uint8_t *pBufMem, uint8_t numPools, wsfBufPoolDesc_t *pDesc); + +/*************************************************************************************************/ +/*! + * \fn WsfBufAlloc + * + * \brief Allocate a buffer. + * + * \param len Length of buffer to allocate. + * + * \return Pointer to allocated buffer or NULL if allocation fails. + */ +/*************************************************************************************************/ +void *WsfBufAlloc(uint16_t len); + +/*************************************************************************************************/ +/*! + * \fn WsfBufFree + * + * \brief Free a buffer. + * + * \param pBuf Buffer to free. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfBufFree(void *pBuf); + +/*************************************************************************************************/ +/*! + * \fn WsfBufGetMaxAlloc + * + * \brief Diagnostic function to get maximum allocated buffers from a pool. + * + * \param pool Buffer pool number. + * + * \return Number of allocated buffers. + */ +/*************************************************************************************************/ +uint8_t WsfBufGetMaxAlloc(uint8_t pool); + +/*************************************************************************************************/ +/*! + * \fn WsfBufGetNumAlloc + * + * \brief Diagnostic function to get the number of currently allocated buffers in a pool. + * + * \param pool Buffer pool number. + * + * \return Number of allocated buffers. + */ +/*************************************************************************************************/ +uint8_t WsfBufGetNumAlloc(uint8_t pool); + +/*************************************************************************************************/ +/*! + * \fn WsfBufGetAllocStats + * + * \brief Diagnostic function to get the buffer allocation statistics. + * + * \return Buffer allocation statistics array. + */ +/*************************************************************************************************/ +uint8_t *WsfBufGetAllocStats(void); + + +#ifdef __cplusplus +}; +#endif + +#endif /* WSF_BUF_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/include/wsf_msg.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,123 @@ +/*************************************************************************************************/ +/*! + * \file wsf_msg.h + * + * \brief Message passing service. + * + * $Date: 2013-07-02 15:08:09 -0700 (Tue, 02 Jul 2013) $ + * $Revision: 779 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef WSF_MSG_H +#define WSF_MSG_H + +#include "wsf_queue.h" +#include "wsf_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn WsfMsgAlloc + * + * \brief Allocate a message buffer to be sent with WsfMsgSend(). + * + * \param len Message length in bytes. + * + * \return Pointer to message buffer or NULL if allocation failed. + */ +/*************************************************************************************************/ +void *WsfMsgAlloc(uint16_t len); + +/*************************************************************************************************/ +/*! + * \fn WsfMsgFree + * + * \brief Free a message buffer allocated with WsfMsgAlloc(). + * + * \param pMsg Pointer to message buffer. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfMsgFree(void *pMsg); + +/*************************************************************************************************/ +/*! + * \fn WsfMsgSend + * + * \brief Send a message to an event handler. + * + * \param handlerId Event handler ID. + * \param pMsg Pointer to message buffer. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfMsgSend(wsfHandlerId_t handlerId, void *pMsg); + +/*************************************************************************************************/ +/*! + * \fn WsfMsgEnq + * + * \brief Enqueue a message. + * + * \param pQueue Pointer to queue. + * \param handerId Set message handler ID to this value. + * \param pElem Pointer to message buffer. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfMsgEnq(wsfQueue_t *pQueue, wsfHandlerId_t handlerId, void *pMsg); + +/*************************************************************************************************/ +/*! + * \fn WsfMsgDeq + * + * \brief Dequeue a message. + * + * \param pQueue Pointer to queue. + * \param pHandlerId Handler ID of returned message; this is a return parameter. + * + * \return Pointer to message that has been dequeued or NULL if queue is empty. + */ +/*************************************************************************************************/ +void *WsfMsgDeq(wsfQueue_t *pQueue, wsfHandlerId_t *pHandlerId); + +/*************************************************************************************************/ +/*! + * \fn WsfMsgPeek + * + * \brief Get the next message without removing it from the queue. + * + * \param pQueue Pointer to queue. + * \param pHandlerId Handler ID of returned message; this is a return parameter. + * + * \return Pointer to the next message on the queue or NULL if queue is empty. + */ +/*************************************************************************************************/ +void *WsfMsgPeek(wsfQueue_t *pQueue, wsfHandlerId_t *pHandlerId); + +#ifdef __cplusplus +}; +#endif + +#endif /* WSF_MSG_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/include/wsf_os.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,147 @@ +/*************************************************************************************************/ +/*! + * \file wsf_os.h + * + * \brief Software foundation OS API. + * + * $Date: 2012-10-22 14:09:36 -0700 (Mon, 22 Oct 2012) $ + * $Revision: 359 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef WSF_OS_H +#define WSF_OS_H + +#include "wsf_os_int.h" +#include "wsf_queue.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Common message structure passed to event handler */ +typedef struct +{ + uint16_t param; /*! General purpose parameter passed to event handler */ + uint8_t event; /*! General purpose event value passed to event handler */ + uint8_t status; /*! General purpose status value passed to event handler */ +} wsfMsgHdr_t; + +/************************************************************************************************** + Callback Function Types +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn wsfEventHandler_t + * + * \brief Event handler callback function. + * + * \param event Mask of events set for the event handler. + * \param pMsg Pointer to message for the event handler. + * + * \return None. + */ +/*************************************************************************************************/ +typedef void (*wsfEventHandler_t)(wsfEventMask_t event, wsfMsgHdr_t *pMsg); + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn WsfSetEvent + * + * \brief Set an event for an event handler. + * + * \param handlerId Handler ID. + * \param event Event or events to set. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfSetEvent(wsfHandlerId_t handlerId, wsfEventMask_t event); + +/*************************************************************************************************/ +/*! + * \fn WsfTaskLock + * + * \brief Lock task scheduling. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTaskLock(void); + +/*************************************************************************************************/ +/*! + * \fn WsfTaskUnlock + * + * \brief Unlock task scheduling. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTaskUnlock(void); + +/*************************************************************************************************/ +/*! + * \fn WsfTaskSetReady + * + * \brief Set the task used by the given handler as ready to run. + * + * \param handlerId Event handler ID. + * \param event Task event mask. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTaskSetReady(wsfHandlerId_t handlerId, wsfTaskEvent_t event); + +/*************************************************************************************************/ +/*! + * \fn WsfTaskMsgQueue + * + * \brief Return the task message queue used by the given handler. + * + * \param handlerId Event handler ID. + * + * \return Task message queue. + */ +/*************************************************************************************************/ +wsfQueue_t *WsfTaskMsgQueue(wsfHandlerId_t handlerId); + +/*************************************************************************************************/ +/*! + * \fn WsfOsSetNextHandler + * + * \brief Set the next WSF handler function in the WSF OS handler array. This function + * should only be called as part of the OS initialization procedure. + * + * \param handler WSF handler function. + * + * \return WSF handler ID for this handler. + */ +/*************************************************************************************************/ +wsfHandlerId_t WsfOsSetNextHandler(wsfEventHandler_t handler); + +#ifdef __cplusplus +}; +#endif + +#endif /* WSF_OS_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/include/wsf_queue.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,155 @@ +/*************************************************************************************************/ +/*! + * \file wsf_queue.h + * + * \brief General purpose queue service. + * + * $Date: 2011-10-14 21:35:03 -0700 (Fri, 14 Oct 2011) $ + * $Revision: 191 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef WSF_QUEUE_H +#define WSF_QUEUE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/*! Initialize a queue */ +#define WSF_QUEUE_INIT(pQueue) {(pQueue)->pHead = NULL; (pQueue)->pTail = NULL;} + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Queue structure */ +typedef struct +{ + void *pHead; /*! head of queue */ + void *pTail; /*! tail of queue */ +} wsfQueue_t; + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn WsfQueueEnq + * + * \brief Enqueue an element to the tail of a queue. + * + * \param pQueue Pointer to queue. + * \param pElem Pointer to element. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfQueueEnq(wsfQueue_t *pQueue, void *pElem); + +/*************************************************************************************************/ +/*! + * \fn WsfQueueDeq + * + * \brief Dequeue an element from the head of a queue. + * + * \param pQueue Pointer to queue. + * + * \return Pointer to element that has been dequeued or NULL if queue is empty. + */ +/*************************************************************************************************/ +void *WsfQueueDeq(wsfQueue_t *pQueue); + +/*************************************************************************************************/ +/*! + * \fn WsfQueuePush + * + * \brief Push an element to the head of a queue. + * + * \param pQueue Pointer to queue. + * \param pElem Pointer to element. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfQueuePush(wsfQueue_t *pQueue, void *pElem); + +/*************************************************************************************************/ +/*! + * \fn WsfQueueInsert + * + * \brief Insert an element into a queue. This function is typically used when iterating + * over a queue. + * + * \param pQueue Pointer to queue. + * \param pElem Pointer to element to be inserted. + * \param pPrev Pointer to previous element in the queue before element to be inserted. + * Note: set pPrev to NULL if pElem is first element in queue. + * \return None. + */ +/*************************************************************************************************/ +void WsfQueueInsert(wsfQueue_t *pQueue, void *pElem, void *pPrev); + +/*************************************************************************************************/ +/*! + * \fn WsfQueueRemove + * + * \brief Remove an element from a queue. This function is typically used when iterating + * over a queue. + * + * \param pQueue Pointer to queue. + * \param pElem Pointer to element to be removed. + * \param pPrev Pointer to previous element in the queue before element to be removed. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfQueueRemove(wsfQueue_t *pQueue, void *pElem, void *pPrev); + +/*************************************************************************************************/ +/*! + * \fn WsfQueueCount + * + * \brief Count the number of elements in a queue. + * + * \param pQueue Pointer to queue. + * + * \return Number of elements in queue. + */ +/*************************************************************************************************/ +uint16_t WsfQueueCount(wsfQueue_t *pQueue); + +/*************************************************************************************************/ +/*! + * \fn WsfQueueEmpty + * + * \brief Return TRUE if queue is empty. + * + * \param pQueue Pointer to queue. + * + * \return TRUE if queue is empty, FALSE otherwise. + */ +/*************************************************************************************************/ +bool_t WsfQueueEmpty(wsfQueue_t *pQueue); + + +#ifdef __cplusplus +}; +#endif + +#endif /* WSF_QUEUE_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/include/wsf_sec.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,111 @@ +/*************************************************************************************************/ +/*! + * \file wsf_sec.h + * + * \brief AES and random number security service API. + * + * $Date: 2011-10-14 21:35:03 -0700 (Fri, 14 Oct 2011) $ + * $Revision: 191 $ + * + * Copyright (c) 2010-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + + */ +/*************************************************************************************************/ +#ifndef WSF_SEC_H +#define WSF_SEC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! AES callback parameters structure */ +typedef struct +{ + wsfMsgHdr_t hdr; /*! header */ + uint8_t *pCiphertext; /*! pointer to 16 bytes of ciphertext data */ +} wsfSecAes_t; + +/*! AES callback function type */ +typedef void (*wsfSecAesCback_t)(wsfSecAes_t *pMsg); + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn WsfSecInit + * + * \brief Initialize the security service. This function should only be called once + * upon system initialization. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfSecInit(void); + +/*************************************************************************************************/ +/*! + * \fn WsfSecRandInit + * + * \brief Initialize the random number service. This function should only be called once + * upon system initialization. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfSecRandInit(void); + +/*************************************************************************************************/ +/*! + * \fn WsfSecAes + * + * \brief Execute an AES calculation. When the calculation completes, a WSF message will be + * sent to the specified handler. This function returns a token value that + * the client can use to match calls to this function with messages. + * + * \param pKey Pointer to 16 byte key. + * \param pPlaintext Pointer to 16 byte plaintext. + * \param handlerId WSF handler ID. + * \param param Client-defined parameter returned in message. + * \param event Event for client's WSF handler. + * + * \return Token value. + */ +/*************************************************************************************************/ +uint8_t WsfSecAes(uint8_t *pKey, uint8_t *pPlaintext, wsfHandlerId_t handlerId, + uint16_t param, uint8_t event); + +/*************************************************************************************************/ +/*! + * \fn WsfSecRand + * + * \brief This function returns up to 16 bytes of random data to a buffer provided by the + * client. + * + * \param pRand Pointer to returned random data. + * \param randLen Length of random data. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfSecRand(uint8_t *pRand, uint8_t randLen); + +#ifdef __cplusplus +}; +#endif + +#endif /* WSF_SEC_H */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/exactLE/wsf/include/wsf_timer.h Thu Mar 03 14:13:21 2016 +0000 @@ -0,0 +1,161 @@ +/*************************************************************************************************/ +/*! + * \file wsf_timer.h + * + * \brief Timer service. + * + * $Date: 2013-07-19 17:17:05 -0700 (Fri, 19 Jul 2013) $ + * $Revision: 843 $ + * + * Copyright (c) 2009-2016 ARM Limited. All rights reserved. + * + * SPDX-License-Identifier: LicenseRef-PBL + * + * Licensed under the Permissive Binary License, Version 1.0 (the "License"); you may not use + * this file except in compliance with the License. You may obtain a copy of the License at + * + * https://www.mbed.com/licenses/PBL-1.0 + * + * See the License for the specific language governing permissions and limitations under the License. + */ +/*************************************************************************************************/ +#ifndef WSF_TIMER_H +#define WSF_TIMER_H + +#include "wsf_os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/************************************************************************************************** + Macros +**************************************************************************************************/ + +/************************************************************************************************** + Data Types +**************************************************************************************************/ + +/*! Timer ticks data type */ +typedef uint16_t wsfTimerTicks_t; + +/*! Timer structure */ +typedef struct wsfTimer_tag +{ + struct wsfTimer_tag *pNext; /*! pointer to next timer in queue */ + wsfTimerTicks_t ticks; /*! number of ticks until expiration */ + wsfHandlerId_t handlerId; /*! event handler for this timer */ + bool_t isStarted; /*! TRUE if timer has been started */ + wsfMsgHdr_t msg; /*! application-defined timer event parameters */ +} wsfTimer_t; + + +/************************************************************************************************** + Function Declarations +**************************************************************************************************/ + +/*************************************************************************************************/ +/*! + * \fn WsfTimerInit + * + * \brief Initialize the timer service. This function should only be called once + * upon system initialization. + * + * \param msPerTick Sets the number of milliseconds per timer tick. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTimerInit(uint8_t msPerTick); + +/*************************************************************************************************/ +/*! + * \fn WsfTimerStartSec + * + * \brief Start a timer in units of seconds. Before this function is called parameter + * pTimer->handlerId must be set to the event handler for this timer and parameter + * pTimer->msg must be set to any application-defined timer event parameters. + * + * \param pTimer Pointer to timer. + * \param sec Seconds until expiration. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTimerStartSec(wsfTimer_t *pTimer, wsfTimerTicks_t sec); + +/*************************************************************************************************/ +/*! + * \fn WsfTimerStartMs + * + * \brief Start a timer in units of milliseconds. + * + * \param pTimer Pointer to timer. + * \param ms Milliseconds until expiration. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTimerStartMs(wsfTimer_t *pTimer, wsfTimerTicks_t ms); + +/*************************************************************************************************/ +/*! + * \fn WsfTimerStop + * + * \brief Stop a timer. + * + * \param pTimer Pointer to timer. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTimerStop(wsfTimer_t *pTimer); + +/*************************************************************************************************/ +/*! + * \fn WsfTimerUpdate + * + * \brief Update the timer service with the number of elapsed ticks. This function is + * typically called only from timer porting code. + * + * \param ticks Number of ticks since last update. + * + * \return None. + */ +/*************************************************************************************************/ +void WsfTimerUpdate(wsfTimerTicks_t ticks); + +/*************************************************************************************************/ +/*! + * \fn WsfTimerNextExpiration + * + * \brief Return the number of ticks until the next timer expiration. Note that this + * function can return zero even if a timer is running, indicating the timer + * has expired but has not yet been serviced. + * + * \param pTimerRunning Returns TRUE if a timer is running, FALSE if no timers running. + * + * \return The number of ticks until the next timer expiration. + */ +/*************************************************************************************************/ +wsfTimerTicks_t WsfTimerNextExpiration(bool_t *pTimerRunning); + +/*************************************************************************************************/ +/*! + * \fn WsfTimerServiceExpired + * + * \brief Service expired timers for the given task. This function is typically called only + * WSF OS porting code. + * + * \param taskId OS Task ID of task servicing timers. + * + * \return Pointer to next expired timer or NULL if there are no expired timers. + */ +/*************************************************************************************************/ +wsfTimer_t *WsfTimerServiceExpired(wsfTaskId_t taskId); + +#ifdef __cplusplus +}; +#endif + +#endif /* WSF_TIMER_H */