Skip to content

Commit a36e578

Browse files
committed
[BEETLE] Add Beetle target to BLE Object
This patch adds the support for Beetle target to the BLE Object. Signed-off-by: Vincenzo Frascino <[email protected]>
1 parent 60b8656 commit a36e578

File tree

8 files changed

+1538
-0
lines changed

8 files changed

+1538
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* PackageLicenseDeclared: Apache-2.0
3+
* Copyright (c) 2016 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef _ARMBLE_H_
19+
#define _ARMBLE_H_
20+
21+
#include "BLE.h"
22+
#include "blecommon.h"
23+
#include "BLEInstanceBase.h"
24+
25+
#include "ArmGap.h"
26+
#include "ArmGattServer.h"
27+
#include "ArmGattClient.h"
28+
#include "ArmSecurityManager.h"
29+
30+
class ArmBLE : public BLEInstanceBase
31+
{
32+
public:
33+
ArmBLE(void);
34+
virtual ~ArmBLE(void);
35+
36+
virtual ble_error_t init(BLE::InstanceID_t instanceID, FunctionPointerWithContext<BLE::InitializationCompleteCallbackContext *> initCallback);
37+
virtual bool hasInitialized(void) const {
38+
return initialized;
39+
}
40+
virtual ble_error_t shutdown(void);
41+
virtual const char *getVersion(void);
42+
43+
virtual Gap &getGap() {
44+
return ArmGap::getInstance();
45+
};
46+
virtual const Gap &getGap() const {
47+
return ArmGap::getInstance();
48+
};
49+
virtual GattServer &getGattServer() {
50+
return ArmGattServer::getInstance();
51+
};
52+
virtual const GattServer &getGattServer() const {
53+
return ArmGattServer::getInstance();
54+
};
55+
virtual GattClient &getGattClient() {
56+
return ArmGattClient::getInstance();
57+
};
58+
virtual SecurityManager &getSecurityManager() {
59+
return ArmSecurityManager::getInstance();
60+
};
61+
virtual const SecurityManager &getSecurityManager() const {
62+
return ArmSecurityManager::getInstance();
63+
};
64+
65+
virtual void waitForEvent(void);
66+
67+
virtual void processEvents();
68+
69+
private:
70+
bool initialized;
71+
BLE::InstanceID_t instanceID;
72+
73+
static void timeoutCallback(void);
74+
void callDispatcher(void);
75+
};
76+
77+
#endif /* _ARMBLE_H_ */
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* PackageLicenseDeclared: Apache-2.0
3+
* Copyright (c) 2016 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef _ARM_GAP_H_
19+
#define _ARM_GAP_H_
20+
21+
#include "mbed.h"
22+
#include "blecommon.h"
23+
#include "GapAdvertisingParams.h"
24+
#include "GapAdvertisingData.h"
25+
#include "Gap.h"
26+
#include "GapScanningParams.h"
27+
#include "dm_api.h"
28+
#include "att_api.h"
29+
30+
/**************************************************************************/
31+
/*!
32+
\brief
33+
34+
*/
35+
/**************************************************************************/
36+
class ArmGap : public Gap
37+
{
38+
public:
39+
static ArmGap &getInstance();
40+
41+
/* Functions that must be implemented from Gap */
42+
virtual ble_error_t setAddress(AddressType_t type, const Address_t address);
43+
virtual ble_error_t getAddress(AddressType_t *typeP, Address_t address);
44+
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &);
45+
46+
#define BLE_GAP_ADV_INTERVAL_MIN 0x0020 /**< Minimum Advertising interval in 625 us units, i.e. 20 ms. */
47+
#define BLE_GAP_ADV_NONCON_INTERVAL_MIN 0x00A0 /**< Minimum Advertising interval in 625 us units for non connectable mode, i.e. 100 ms. */
48+
#define BLE_GAP_ADV_INTERVAL_MAX 0x4000 /**< Armum Advertising interval in 625 us units, i.e. 10.24 s. */
49+
50+
virtual uint16_t getMinAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MIN; }
51+
virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const { return BLE_GAP_ADV_NONCON_INTERVAL_MIN; }
52+
virtual uint16_t getMaxAdvertisingInterval(void) const { return BLE_GAP_ADV_INTERVAL_MAX; }
53+
54+
virtual ble_error_t startAdvertising(const GapAdvertisingParams &);
55+
virtual ble_error_t stopAdvertising(void);
56+
virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason);
57+
virtual ble_error_t disconnect(DisconnectionReason_t reason);
58+
59+
virtual ble_error_t setDeviceName(const uint8_t *deviceName);
60+
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP);
61+
virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance);
62+
virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP);
63+
64+
virtual ble_error_t setTxPower(int8_t txPower);
65+
virtual void getPermittedTxPowerValues(const int8_t **valueArrayPP, size_t *countP);
66+
67+
void setConnectionHandle(uint16_t m_connectionHandle);
68+
uint16_t getConnectionHandle(void);
69+
70+
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params);
71+
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params);
72+
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params);
73+
74+
virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams);
75+
virtual ble_error_t stopScan(void);
76+
77+
void advertisingStopped(void);
78+
79+
private:
80+
uint16_t m_connectionHandle;
81+
addr_type_t m_type;
82+
ArmGap() {
83+
m_connectionHandle = DM_CONN_ID_NONE;
84+
m_type = BLEProtocol::AddressType::RANDOM_STATIC;
85+
}
86+
87+
ArmGap(ArmGap const &);
88+
void operator=(ArmGap const &);
89+
};
90+
91+
#endif /* _ARM_GAP_H_ */
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* PackageLicenseDeclared: Apache-2.0
3+
* Copyright (c) 2016 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef _ARM_GATT_CLIENT_H_
19+
#define _ARM_GATT_CLIENT_H_
20+
21+
#include <stddef.h>
22+
23+
#include "GattClient.h"
24+
25+
class ArmGattClient : public GattClient
26+
{
27+
public:
28+
static ArmGattClient &getInstance() {
29+
static ArmGattClient m_instance;
30+
return m_instance;
31+
}
32+
33+
public:
34+
ArmGattClient() {
35+
/* empty */
36+
}
37+
38+
private:
39+
40+
};
41+
42+
#endif /* _ARM_GATT_CLIENT_H_ */
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* PackageLicenseDeclared: Apache-2.0
3+
* Copyright (c) 2016 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef _ARM_GATT_SERVER_H_
19+
#define _ARM_GATT_SERVER_H_
20+
21+
#include <stddef.h>
22+
23+
#include "blecommon.h"
24+
#include "GattServer.h"
25+
#include "generic/wsf_types.h"
26+
#include "att_api.h"
27+
28+
class ArmGattServer : public GattServer
29+
{
30+
public:
31+
static ArmGattServer &getInstance();
32+
33+
/* Functions that must be implemented from GattServer */
34+
virtual ble_error_t addService(GattService &);
35+
36+
virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
37+
virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP);
38+
virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
39+
virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false);
40+
41+
virtual ble_error_t areUpdatesEnabled(const GattCharacteristic &characteristic, bool *enabledP);
42+
virtual ble_error_t areUpdatesEnabled(Gap::Handle_t connectionHandle, const GattCharacteristic &characteristic, bool *enabledP);
43+
44+
virtual bool isOnDataReadAvailable() const { return true; }
45+
46+
private:
47+
static void cccCback(attsCccEvt_t *pEvt);
48+
static void attCback(attEvt_t *pEvt);
49+
static uint8_t attsReadCback(dmConnId_t connId, uint16_t handle, uint8_t operation, uint16_t offset, attsAttr_t *pAttr);
50+
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);
51+
52+
/*! client characteristic configuration descriptors settings */
53+
#define MAX_CCC_CNT 20
54+
attsCccSet_t cccSet[MAX_CCC_CNT];
55+
uint16_t cccValues[MAX_CCC_CNT];
56+
uint16_t cccHandles[MAX_CCC_CNT];
57+
uint8_t cccCnt;
58+
59+
private:
60+
ArmGattServer() : GattServer(), cccSet(), cccValues(), cccHandles(), cccCnt(0) {
61+
/* empty */
62+
}
63+
64+
ArmGattServer(const ArmGattServer &);
65+
const ArmGattServer& operator=(const ArmGattServer &);
66+
};
67+
68+
#endif /* _ARM_GATT_SERVER_H_ */
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* PackageLicenseDeclared: Apache-2.0
3+
* Copyright (c) 2016 ARM Limited
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef _ARM_SECURITY_MANAGER_H_
19+
#define _ARM_SECURITY_MANAGER_H_
20+
21+
#include <stddef.h>
22+
23+
#include "SecurityManager.h"
24+
25+
class ArmSecurityManager : public SecurityManager
26+
{
27+
public:
28+
static ArmSecurityManager &getInstance() {
29+
static ArmSecurityManager m_instance;
30+
return m_instance;
31+
}
32+
33+
public:
34+
ArmSecurityManager() {
35+
/* empty */
36+
}
37+
};
38+
39+
#endif /* _ARM_SECURITY_MANAGER_H_ */

0 commit comments

Comments
 (0)