diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h index 0232b27fef..b74e3da292 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioGattServer.h @@ -149,6 +149,29 @@ public: */ void setPreferredConnectionParams(const ::Gap::ConnectionParams_t& params); +#if 0 // Disabled until reworked and reintroduced to GattServer API + /** + * @see ::GattServer::setDeviceName + */ + ble_error_t setDeviceName(const uint8_t *deviceName); + + /** + * @see ::GattServer::getDeviceName + */ + void getDeviceName(const uint8_t*& name, uint16_t& length); + + /** + * @see ::GattServer::setAppearance + */ + void setAppearance(GapAdvertisingData::Appearance appearance); + + /** + * @see ::GattServer::getAppearance + */ + GapAdvertisingData::Appearance getAppearance(); + +#endif // Disabled until reworked and reintroduced to GattServer API + /** * @see ::GattServer::reset */ diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h index 5eea4cefdb..6247e58211 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h @@ -19,6 +19,73 @@ public: virtual ~GenericAccessService() { } +#if 0 // Disabled until reworked and reintroduced to GattServer API + + virtual ble_error_t get_device_name_length(uint8_t& length) { +#if BLE_FEATURE_GATT_SERVER + const uint8_t* name = NULL; + uint16_t actual_length = 0; + + gatt_server().getDeviceName(name, actual_length); + length = actual_length; + + return BLE_ERROR_NONE; +#else + return BLE_ERROR_NOT_IMPLEMENTED; +#endif + } + + virtual ble_error_t get_device_name(Span& array) { +#if BLE_FEATURE_GATT_SERVER + const uint8_t* name = NULL; + uint16_t length = 0; + + gatt_server().getDeviceName(name, length); + + if (length > array.size()) { + return BLE_ERROR_PARAM_OUT_OF_RANGE; + } + + memcpy(array.data(), name, length); + + return BLE_ERROR_NONE; +#else + return BLE_ERROR_NOT_IMPLEMENTED; +#endif // BLE_FEATURE_GATT_SERVER + } + + virtual ble_error_t set_device_name(const uint8_t* device_name) { +#if BLE_FEATURE_GATT_SERVER + return gatt_server().setDeviceName(device_name); +#else + return BLE_ERROR_NOT_IMPLEMENTED; +#endif // BLE_FEATURE_GATT_SERVER + } + + virtual ble_error_t get_appearance( + GapAdvertisingData::Appearance& appearance + ) { +#if BLE_FEATURE_GATT_SERVER + appearance = gatt_server().getAppearance(); + return BLE_ERROR_NONE; +#else + return BLE_ERROR_NOT_IMPLEMENTED; +#endif // BLE_FEATURE_GATT_SERVER + } + + virtual ble_error_t set_appearance( + GapAdvertisingData::Appearance appearance + ) { +#if BLE_FEATURE_GATT_SERVER + gatt_server().setAppearance(appearance); + return BLE_ERROR_NONE; +#else + return BLE_ERROR_NOT_IMPLEMENTED; +#endif // BLE_FEATURE_GATT_SERVER + } + +#endif // Disabled until reworked and reintroduced to GattServer API + virtual ble_error_t get_peripheral_prefered_connection_parameters( ::Gap::ConnectionParams_t& parameters ) { diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp index f7131e4623..11169fa082 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/source/CordioGattServer.cpp @@ -818,6 +818,51 @@ void GattServer::setPreferredConnectionParams(const ::Gap::ConnectionParams_t& p memcpy(generic_access_service.ppcp + 6, ¶ms.connectionSupervisionTimeout, 2); } +#if 0 // Disabled until reworked and reintroduced to GattServer API + +ble_error_t GattServer::setDeviceName(const uint8_t *deviceName) +{ + size_t length = 0; + + if (deviceName != NULL) { + length = strlen((const char*)deviceName); + } + + if (length == 0) { + free(generic_access_service.device_name_value()); + } else { + uint8_t* res = (uint8_t*) realloc(generic_access_service.device_name_value(), length); + if (res == NULL) { + return BLE_ERROR_NO_MEM; + } + + generic_access_service.device_name_value() = res; + memcpy(res, deviceName, length); + } + + generic_access_service.device_name_length = length; + + return BLE_ERROR_NONE; +} + +void GattServer::getDeviceName(const uint8_t*& name, uint16_t& length) +{ + length = generic_access_service.device_name_length; + name = generic_access_service.device_name_value(); +} + +void GattServer::setAppearance(GapAdvertisingData::Appearance appearance) +{ + generic_access_service.appearance = appearance; +} + +GapAdvertisingData::Appearance GattServer::getAppearance() +{ + return (GapAdvertisingData::Appearance) generic_access_service.appearance; +} + +#endif // Disabled until reworked and reintroduced to GattServer API + ble_error_t GattServer::reset_(void) { Base::reset_();