Skip to content

Commit d6eeab1

Browse files
committed
Cordio: bring back device name & appearance function
Functions in Cordio for device name & appearance are currently unused as they are both part of and dependent on deprecated Mbed OS BLE APIs. Nonetheless we want to keep them (and disable using macros) so we can reintroduce them and make improvements in the future as needed.
1 parent 53550bb commit d6eeab1

File tree

3 files changed

+135
-0
lines changed

3 files changed

+135
-0
lines changed

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,29 @@ class GattServer : public ::ble::interface::GattServer<GattServer>,
149149
*/
150150
void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params);
151151

152+
#if 0 // Disabled until reworked and reintroduced to GattServer API
153+
/**
154+
* @see ::GattServer::setDeviceName
155+
*/
156+
ble_error_t setDeviceName(const uint8_t *deviceName);
157+
158+
/**
159+
* @see ::GattServer::getDeviceName
160+
*/
161+
void getDeviceName(const uint8_t*& name, uint16_t& length);
162+
163+
/**
164+
* @see ::GattServer::setAppearance
165+
*/
166+
void setAppearance(GapAdvertisingData::Appearance appearance);
167+
168+
/**
169+
* @see ::GattServer::getAppearance
170+
*/
171+
GapAdvertisingData::Appearance getAppearance();
172+
173+
#endif // Disabled until reworked and reintroduced to GattServer API
174+
152175
/**
153176
* @see ::GattServer::reset
154177
*/

features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,73 @@ class GenericAccessService : public ::ble::pal::GenericAccessService {
1919

2020
virtual ~GenericAccessService() { }
2121

22+
#if 0 // Disabled until reworked and reintroduced to GattServer API
23+
24+
virtual ble_error_t get_device_name_length(uint8_t& length) {
25+
#if BLE_FEATURE_GATT_SERVER
26+
const uint8_t* name = NULL;
27+
uint16_t actual_length = 0;
28+
29+
gatt_server().getDeviceName(name, actual_length);
30+
length = actual_length;
31+
32+
return BLE_ERROR_NONE;
33+
#else
34+
return BLE_ERROR_NOT_IMPLEMENTED;
35+
#endif
36+
}
37+
38+
virtual ble_error_t get_device_name(Span<uint8_t>& array) {
39+
#if BLE_FEATURE_GATT_SERVER
40+
const uint8_t* name = NULL;
41+
uint16_t length = 0;
42+
43+
gatt_server().getDeviceName(name, length);
44+
45+
if (length > array.size()) {
46+
return BLE_ERROR_PARAM_OUT_OF_RANGE;
47+
}
48+
49+
memcpy(array.data(), name, length);
50+
51+
return BLE_ERROR_NONE;
52+
#else
53+
return BLE_ERROR_NOT_IMPLEMENTED;
54+
#endif // BLE_FEATURE_GATT_SERVER
55+
}
56+
57+
virtual ble_error_t set_device_name(const uint8_t* device_name) {
58+
#if BLE_FEATURE_GATT_SERVER
59+
return gatt_server().setDeviceName(device_name);
60+
#else
61+
return BLE_ERROR_NOT_IMPLEMENTED;
62+
#endif // BLE_FEATURE_GATT_SERVER
63+
}
64+
65+
virtual ble_error_t get_appearance(
66+
GapAdvertisingData::Appearance& appearance
67+
) {
68+
#if BLE_FEATURE_GATT_SERVER
69+
appearance = gatt_server().getAppearance();
70+
return BLE_ERROR_NONE;
71+
#else
72+
return BLE_ERROR_NOT_IMPLEMENTED;
73+
#endif // BLE_FEATURE_GATT_SERVER
74+
}
75+
76+
virtual ble_error_t set_appearance(
77+
GapAdvertisingData::Appearance appearance
78+
) {
79+
#if BLE_FEATURE_GATT_SERVER
80+
gatt_server().setAppearance(appearance);
81+
return BLE_ERROR_NONE;
82+
#else
83+
return BLE_ERROR_NOT_IMPLEMENTED;
84+
#endif // BLE_FEATURE_GATT_SERVER
85+
}
86+
87+
#endif // Disabled until reworked and reintroduced to GattServer API
88+
2289
virtual ble_error_t get_peripheral_prefered_connection_parameters(
2390
::Gap::ConnectionParams_t& parameters
2491
) {

features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,51 @@ void GattServer::setPreferredConnectionParams(const ::Gap::ConnectionParams_t& p
818818
memcpy(generic_access_service.ppcp + 6, &params.connectionSupervisionTimeout, 2);
819819
}
820820

821+
#if 0 // Disabled until reworked and reintroduced to GattServer API
822+
823+
ble_error_t GattServer::setDeviceName(const uint8_t *deviceName)
824+
{
825+
size_t length = 0;
826+
827+
if (deviceName != NULL) {
828+
length = strlen((const char*)deviceName);
829+
}
830+
831+
if (length == 0) {
832+
free(generic_access_service.device_name_value());
833+
} else {
834+
uint8_t* res = (uint8_t*) realloc(generic_access_service.device_name_value(), length);
835+
if (res == NULL) {
836+
return BLE_ERROR_NO_MEM;
837+
}
838+
839+
generic_access_service.device_name_value() = res;
840+
memcpy(res, deviceName, length);
841+
}
842+
843+
generic_access_service.device_name_length = length;
844+
845+
return BLE_ERROR_NONE;
846+
}
847+
848+
void GattServer::getDeviceName(const uint8_t*& name, uint16_t& length)
849+
{
850+
length = generic_access_service.device_name_length;
851+
name = generic_access_service.device_name_value();
852+
}
853+
854+
void GattServer::setAppearance(GapAdvertisingData::Appearance appearance)
855+
{
856+
generic_access_service.appearance = appearance;
857+
}
858+
859+
GapAdvertisingData::Appearance GattServer::getAppearance()
860+
{
861+
return (GapAdvertisingData::Appearance) generic_access_service.appearance;
862+
}
863+
864+
#endif // Disabled until reworked and reintroduced to GattServer API
865+
821866
ble_error_t GattServer::reset_(void)
822867
{
823868
Base::reset_();

0 commit comments

Comments
 (0)