Skip to content

Commit 0025b68

Browse files
committed
BLE: Generic Access Service Adaptation layer
Add an abstraction which manage the state of the GAP service exposed by the GATT server.
1 parent 744abca commit 0025b68

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017-2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef BLE_PAL_GENERIC_ACCESS_SERVICE_H_
18+
#define BLE_PAL_GENERIC_ACCESS_SERVICE_H_
19+
20+
#include "GapTypes.h"
21+
#include "ble/ArrayView.h"
22+
#include "ble/blecommon.h"
23+
#include "ble/GapAdvertisingData.h"
24+
#include "ble/Gap.h"
25+
26+
namespace ble {
27+
namespace pal {
28+
29+
/**
30+
* Manage state of the GAP service exposed by the GATT server.
31+
*
32+
* @see Bluetooth 4.2 Vol 3 PartC: 12 - GAP service and characteristics for GATT
33+
* server.
34+
*/
35+
struct GenericAccessService {
36+
37+
/**
38+
* Empty, default, constructor
39+
*/
40+
GenericAccessService() { }
41+
42+
/**
43+
* Virtual destructor
44+
*/
45+
virtual ~GenericAccessService() { }
46+
47+
/**
48+
* Acquire the length of the device name.
49+
* The length can range from 0 (no device name) to 248 octets
50+
*
51+
* @param length The length of the device name currently stored in the GAP
52+
* service.
53+
*
54+
* @return BLE_ERROR_NONE in case of success or the appropriate error code
55+
* otherwise.
56+
*
57+
* @see Bluetooth 4.2 Vol 3 PartC: 12.1 - Device Name Characteristic
58+
*/
59+
virtual ble_error_t get_device_name_length(uint8_t& length) = 0;
60+
61+
/**
62+
* Get the current device name.
63+
* The result is stored in the array pass in input if the operation
64+
* succeed. Prior to this call the length of the device name can be acquired
65+
* with a call to get_device_name_length.
66+
*
67+
* @param The array which will host the device name
68+
*
69+
* @return BLE_ERROR_NONE in case of success or the appropriate error code
70+
* otherwise.
71+
*
72+
* @see Bluetooth 4.2 Vol 3 PartC: 12.1 - Device Name Characteristic
73+
*/
74+
virtual ble_error_t get_device_name(ArrayView<uint8_t>& array) = 0;
75+
76+
/**
77+
* Set the value of the device name characteristic exposed by the GAP GATT
78+
* service.
79+
*
80+
* @param device_name The name of the device. If NULL the device name
81+
* value has a length of 0.
82+
*
83+
* @return BLE_ERROR_NONE in case of success or the appropriate error code
84+
* otherwise.
85+
*
86+
* @see Bluetooth 4.2 Vol 3 PartC: 12.1 - Device Name Characteristic
87+
*/
88+
virtual ble_error_t set_device_name(const uint8_t* device_name) = 0;
89+
90+
/**
91+
* Acquire the appearance stored in the appearance characteristic of the GAP
92+
* GATT service.
93+
*
94+
* @param appearance: If the call succeed will contain the value of the
95+
* appearance characteristic.
96+
*
97+
* @return BLE_ERROR_NONE in case of success or the appropriate error code
98+
* otherwise.
99+
*
100+
* @see Bluetooth 4.2 Vol 3 PartC: 12.2 - Appearance Characteristic
101+
*/
102+
virtual ble_error_t get_appearance(
103+
GapAdvertisingData::Appearance& appearance
104+
) = 0;
105+
106+
/**
107+
* Set the value of the appearance characteristic of the GAP GATT service.
108+
*
109+
* @param appearance: The appearance to set.
110+
*
111+
* @return BLE_ERROR_NONE in case of success or the appropriate error code
112+
* otherwise.
113+
*
114+
* @see Bluetooth 4.2 Vol 3 PartC: 12.2 - Appearance Characteristic
115+
*/
116+
virtual ble_error_t set_appearance(
117+
GapAdvertisingData::Appearance appearance
118+
) = 0;
119+
120+
/**
121+
* Acquire the peripheral prefered connection parameters stored in the GAP
122+
* GATT service.
123+
*
124+
* @param parameters: If the call succeed will contain the value of
125+
* the peripheral prefered connection parameters characteristic.
126+
*
127+
* @return BLE_ERROR_NONE in case of success or the appropriate error code
128+
* otherwise.
129+
*
130+
* @see Bluetooth 4.2 Vol 3 PartC: 12.3 - Peripheral Preferred Connection
131+
* Parameters Characteristic
132+
*/
133+
virtual ble_error_t get_peripheral_prefered_connection_parameters(
134+
::Gap::ConnectionParams_t& parameters
135+
) = 0;
136+
137+
/**
138+
* set the value of the peripheral prefered connection parameters stored in
139+
* the GAP GATT service.
140+
*
141+
* @param parameters: If the peripheral prefered connection parameters
142+
* to set.
143+
*
144+
* @return BLE_ERROR_NONE in case of success or the appropriate error code
145+
* otherwise.
146+
*
147+
* @see Bluetooth 4.2 Vol 3 PartC: 12.3 - Peripheral Preferred Connection
148+
* Parameters Characteristic
149+
*/
150+
virtual ble_error_t set_peripheral_prefered_connection_parameters(
151+
const ::Gap::ConnectionParams_t& parameters
152+
) = 0;
153+
154+
private:
155+
GenericAccessService(const GenericAccessService&);
156+
GenericAccessService& operator=(const GenericAccessService&);
157+
};
158+
159+
} // namespace pal
160+
} // namespace ble
161+
162+
#endif /* BLE_PAL_GENERIC_ACCESS_SERVICE_H_ */

0 commit comments

Comments
 (0)