From 6f7f1337cd1c0c8224b9a40381a9688cc9aa3051 Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 24 May 2019 12:18:57 +0100 Subject: [PATCH 1/2] BLE: Replace uses of ArrayView with mbed::Span The platform API mbed::Span provides the same features as ArrayView. --- features/FEATURE_BLE/ble/BLETypes.h | 26 +++++----- features/FEATURE_BLE/ble/Gap.h | 4 +- .../ble/gap/AdvertisingDataBuilder.h | 2 +- .../ble/gap/AdvertisingDataParser.h | 1 - features/FEATURE_BLE/ble/gap/Events.h | 1 - features/FEATURE_BLE/ble/generic/GenericGap.h | 8 ++-- .../ble/generic/GenericSecurityManager.h | 3 +- features/FEATURE_BLE/ble/generic/SecurityDb.h | 4 +- features/FEATURE_BLE/ble/pal/AttClient.h | 13 +++-- .../ble/pal/AttClientToGattClientAdapter.h | 12 ++--- .../FEATURE_BLE/ble/pal/AttServerMessage.h | 29 ++++++----- features/FEATURE_BLE/ble/pal/GapEvents.h | 4 +- .../ble/pal/GenericAccessService.h | 4 +- features/FEATURE_BLE/ble/pal/PalGattClient.h | 11 ++--- .../ble/pal/SimpleAttServerMessage.h | 20 ++++---- .../FEATURE_BLE/source/generic/GenericGap.tpp | 21 ++++---- .../source/generic/GenericGattClient.tpp | 18 +++---- .../source/generic/GenericSecurityManager.tpp | 4 +- .../TARGET_CORDIO/CordioPalAttClient.h | 32 ++++++------- .../targets/TARGET_CORDIO/CordioPalGap.h | 2 +- .../CordioPalGenericAccessService.h | 2 +- .../TARGET_NRF51/source/nRF5xCrypto.cpp | 24 +++++----- .../TARGET_NRF51/source/nRF5xCrypto.h | 24 +++++----- .../TARGET_NRF51/source/nRF5xGap.cpp | 14 +++--- .../TARGET_NRF51/source/nRF5xPalGattClient.h | 10 ++-- .../source/nRF5xPalGattClient.tpp | 48 +++++++++---------- .../source/nRF5xPalSecurityManager.h | 2 +- .../source/nRF5xPalSecurityManager.tpp | 22 ++++----- .../TARGET_NRF52/source/nRF5xCrypto.cpp | 24 +++++----- .../TARGET_NRF52/source/nRF5xCrypto.h | 24 +++++----- .../TARGET_NRF52/source/nRF5xGap.cpp | 16 +++---- .../TARGET_NRF52/source/nRF5xPalGattClient.h | 10 ++-- .../source/nRF5xPalGattClient.tpp | 48 +++++++++---------- .../source/nRF5xPalSecurityManager.h | 2 +- .../source/nRF5xPalSecurityManager.tpp | 16 +++---- 35 files changed, 251 insertions(+), 254 deletions(-) diff --git a/features/FEATURE_BLE/ble/BLETypes.h b/features/FEATURE_BLE/ble/BLETypes.h index 652e46a4ef..6759fefb96 100644 --- a/features/FEATURE_BLE/ble/BLETypes.h +++ b/features/FEATURE_BLE/ble/BLETypes.h @@ -21,7 +21,7 @@ #include #include #include "ble/SafeEnum.h" -#include "ble/ArrayView.h" +#include "platform/Span.h" #include "ble/gap/Types.h" /** @@ -33,6 +33,10 @@ namespace ble { +using mbed::Span; +using mbed::make_Span; +using mbed::make_const_Span; + /** Special advertising set handle used for the legacy advertising set. */ static const advertising_handle_t LEGACY_ADVERTISING_HANDLE = 0x00; @@ -412,29 +416,29 @@ protected: }; /** - * Construct a fixed size ArrayView from a byte_array_t. + * Construct a fixed size Span from a byte_array_t. * - * @param src byte_array_t to create a view from. + * @param src byte_array_t to create a Span from. * - * @return An ArrayView to @p src. + * @return A Span to @p src. */ template -ArrayView make_ArrayView(byte_array_t& src) +Span make_Span(byte_array_t& src) { - return ArrayView(src.data(), src.size()); + return Span(src.data(), src.size()); } /** - * Construct a fixed size ArrayView from a const byte_array_t. + * Construct a fixed size Span from a const byte_array_t. * - * @param src byte_array_t to create a view from. + * @param src byte_array_t to create a Span from. * - * @return An ArrayView to @p src. + * @return A Span to @p src. */ template -ArrayView make_const_ArrayView(const byte_array_t& src) +Span make_const_Span(const byte_array_t& src) { - return ArrayView(src.data(), src.size()); + return Span(src.data(), src.size()); } /** 128 bit keys used by paired devices */ diff --git a/features/FEATURE_BLE/ble/Gap.h b/features/FEATURE_BLE/ble/Gap.h index e667b811b1..f8edd50e41 100644 --- a/features/FEATURE_BLE/ble/Gap.h +++ b/features/FEATURE_BLE/ble/Gap.h @@ -1438,13 +1438,13 @@ public: * Reset the value of the advertising payload advertised. * * @deprecated Deprecated since addition of extended advertising support. - * Use setAdvertisingPayload(ble::advertising_handle_t, mbed::Span, + * Use setAdvertisingPayload(ble::advertising_handle_t, Span, * bool). */ MBED_DEPRECATED_SINCE( "mbed-os-5.11.0", "Deprecated since addition of extended advertising support. " - "Use setAdvertisingPayload(ble::advertising_handle_t, mbed::Span," + "Use setAdvertisingPayload(ble::advertising_handle_t, Span," "bool)." ) void clearAdvertisingPayload(void); diff --git a/features/FEATURE_BLE/ble/gap/AdvertisingDataBuilder.h b/features/FEATURE_BLE/ble/gap/AdvertisingDataBuilder.h index 78574cce57..803e5c59ae 100644 --- a/features/FEATURE_BLE/ble/gap/AdvertisingDataBuilder.h +++ b/features/FEATURE_BLE/ble/gap/AdvertisingDataBuilder.h @@ -21,7 +21,7 @@ #include #include -#include "platform/Span.h" +#include "ble/BLETypes.h" #include "platform/NonCopyable.h" #include "ble/blecommon.h" diff --git a/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h b/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h index 1bc947cad0..53fbe23e31 100644 --- a/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h +++ b/features/FEATURE_BLE/ble/gap/AdvertisingDataParser.h @@ -19,7 +19,6 @@ #include #include "ble/gap/AdvertisingDataTypes.h" -#include "platform/Span.h" namespace ble { diff --git a/features/FEATURE_BLE/ble/gap/Events.h b/features/FEATURE_BLE/ble/gap/Events.h index fede40e2f4..f5660654a0 100644 --- a/features/FEATURE_BLE/ble/gap/Events.h +++ b/features/FEATURE_BLE/ble/gap/Events.h @@ -19,7 +19,6 @@ #include "ble/blecommon.h" #include "ble/BLETypes.h" -#include "platform/Span.h" namespace ble { diff --git a/features/FEATURE_BLE/ble/generic/GenericGap.h b/features/FEATURE_BLE/ble/generic/GenericGap.h index 91a5e698bf..c195aa83b8 100644 --- a/features/FEATURE_BLE/ble/generic/GenericGap.h +++ b/features/FEATURE_BLE/ble/generic/GenericGap.h @@ -183,14 +183,14 @@ public: */ ble_error_t setAdvertisingPayload_( advertising_handle_t handle, - mbed::Span payload + Span payload ); /** @copydoc Gap::setAdvertisingScanResponse */ ble_error_t setAdvertisingScanResponse_( advertising_handle_t handle, - mbed::Span response + Span response ); /** @copydoc Gap::startAdvertising @@ -222,7 +222,7 @@ public: */ ble_error_t setPeriodicAdvertisingPayload_( advertising_handle_t handle, - mbed::Span payload + Span payload ); /** @copydoc Gap::startPeriodicAdvertising @@ -626,7 +626,7 @@ public: private: ble_error_t setAdvertisingData( advertising_handle_t handle, - mbed::Span payload, + Span payload, bool minimiseFragmentation, bool scan_response ); diff --git a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h index 7f5f7be783..5f1254f537 100644 --- a/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h +++ b/features/FEATURE_BLE/ble/generic/GenericSecurityManager.h @@ -26,7 +26,6 @@ #include "ble/pal/SigningEventMonitor.h" #include "ble/generic/GenericGap.h" #include "ble/pal/PalSecurityManager.h" -#include "ble/ArrayView.h" namespace ble { namespace generic { @@ -473,7 +472,7 @@ private: * @param count Number of identities entries retrieved. */ void on_identity_list_retrieved( - ble::ArrayView& identity_list, + Span& identity_list, size_t count ); diff --git a/features/FEATURE_BLE/ble/generic/SecurityDb.h b/features/FEATURE_BLE/ble/generic/SecurityDb.h index a5577f1929..cbf2d7b328 100644 --- a/features/FEATURE_BLE/ble/generic/SecurityDb.h +++ b/features/FEATURE_BLE/ble/generic/SecurityDb.h @@ -121,7 +121,7 @@ public: SecurityEntrySigningDbCb_t; typedef mbed::Callback SecurityEntryIdentityDbCb_t; - typedef mbed::Callback&, size_t count)> + typedef mbed::Callback&, size_t count)> IdentitylistDbCb_t; typedef mbed::Callback WhitelistDbCb_t; @@ -340,7 +340,7 @@ public: */ virtual void get_identity_list( IdentitylistDbCb_t cb, - ArrayView& identity_list + Span& identity_list ) { size_t count = 0; for (size_t i = 0; i < get_entry_count() && count < identity_list.size(); ++i) { diff --git a/features/FEATURE_BLE/ble/pal/AttClient.h b/features/FEATURE_BLE/ble/pal/AttClient.h index 98affe8b32..40ba77b7bf 100644 --- a/features/FEATURE_BLE/ble/pal/AttClient.h +++ b/features/FEATURE_BLE/ble/pal/AttClient.h @@ -20,7 +20,6 @@ #include "ble/common/StaticInterface.h" #include "ble/UUID.h" #include "ble/BLETypes.h" -#include "ble/ArrayView.h" #include "ble/blecommon.h" #include "platform/Callback.h" #include "AttServerMessage.h" @@ -197,7 +196,7 @@ public: connection_handle_t connection_handle, attribute_handle_range_t discovery_range, uint16_t type, - const ArrayView& value + const Span& value ) { return impl()->find_by_type_value_request_( connection_handle, @@ -381,7 +380,7 @@ public: */ ble_error_t read_multiple_request( connection_handle_t connection_handle, - const ArrayView& attribute_handles + const Span& attribute_handles ) { return impl()->read_multiple_request_(connection_handle, attribute_handles); } @@ -489,7 +488,7 @@ public: ble_error_t write_request( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { return impl()->write_request_(connection_handle, attribute_handle, value); } @@ -511,7 +510,7 @@ public: ble_error_t write_command( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { return impl()->write_command_(connection_handle, attribute_handle, value); } @@ -538,7 +537,7 @@ public: ble_error_t signed_write_command( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { return impl()->signed_write_command_(connection_handle, attribute_handle, value); } @@ -593,7 +592,7 @@ public: connection_handle_t connection_handle, attribute_handle_t attribute_handle, uint16_t offset, - const ArrayView& value + const Span& value ) { return impl()->prepare_write_request_( connection_handle, diff --git a/features/FEATURE_BLE/ble/pal/AttClientToGattClientAdapter.h b/features/FEATURE_BLE/ble/pal/AttClientToGattClientAdapter.h index 71ecbad341..53025f5fa9 100644 --- a/features/FEATURE_BLE/ble/pal/AttClientToGattClientAdapter.h +++ b/features/FEATURE_BLE/ble/pal/AttClientToGattClientAdapter.h @@ -97,7 +97,7 @@ public: connection_handle, attribute_handle_range(discovery_range_begining, END_ATTRIBUTE_HANDLE), SERVICE_TYPE_UUID, - ArrayView( + Span( uuid.getBaseUUID(), (uuid.shortOrLong() == UUID::UUID_TYPE_SHORT) ? 2 : UUID::LENGTH_OF_LONG_UUID ) @@ -193,7 +193,7 @@ public: */ ble_error_t read_multiple_characteristic_values_( connection_handle_t connection_handle, - const ArrayView& characteristic_value_handles + const Span& characteristic_value_handles ) { return _client.read_multiple_request( connection_handle, @@ -207,7 +207,7 @@ public: ble_error_t write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { return _client.write_command( connection_handle, @@ -222,7 +222,7 @@ public: ble_error_t signed_write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { return _client.signed_write_command( connection_handle, @@ -237,7 +237,7 @@ public: ble_error_t write_attribute_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { return _client.write_request( connection_handle, @@ -252,7 +252,7 @@ public: ble_error_t queue_prepare_write_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ) { return _client.prepare_write_request( diff --git a/features/FEATURE_BLE/ble/pal/AttServerMessage.h b/features/FEATURE_BLE/ble/pal/AttServerMessage.h index 1862549673..a6e4e27634 100644 --- a/features/FEATURE_BLE/ble/pal/AttServerMessage.h +++ b/features/FEATURE_BLE/ble/pal/AttServerMessage.h @@ -18,7 +18,6 @@ #define BLE_PAL_ATT_SERVER_MESSAGE_H_ #include "ble/BLETypes.h" -#include "ble/ArrayView.h" namespace ble { namespace pal { @@ -400,7 +399,7 @@ struct AttReadByTypeResponse : public AttServerMessage { */ struct attribute_data_t { attribute_handle_t handle; - ArrayView value; + Span value; }; /** @@ -446,7 +445,7 @@ struct AttReadResponse : public AttServerMessage { /** * Construct a Read Response from an array of bytes. */ - AttReadResponse(ArrayView data_) : + AttReadResponse(Span data_) : AttServerMessage(AttributeOpcode::READ_RESPONSE), _data(data_) { } @@ -473,7 +472,7 @@ struct AttReadResponse : public AttServerMessage { } private: - const ArrayView _data; + const Span _data; }; @@ -495,7 +494,7 @@ struct AttReadBlobResponse : public AttServerMessage { /** * Construct a read blob response from the value responded. */ - AttReadBlobResponse(ArrayView data_) : + AttReadBlobResponse(Span data_) : AttServerMessage(AttributeOpcode::READ_BLOB_RESPONSE), _data(data_) { } @@ -522,7 +521,7 @@ struct AttReadBlobResponse : public AttServerMessage { } private: - const ArrayView _data; + const Span _data; }; @@ -539,7 +538,7 @@ struct AttReadMultipleResponse : public AttServerMessage { /** * Construct a Resd Multiple Response from the set of value received. */ - AttReadMultipleResponse(ArrayView data_) : + AttReadMultipleResponse(Span data_) : AttServerMessage(AttributeOpcode::READ_MULTIPLE_RESPONSE), _data(data_) { } @@ -559,7 +558,7 @@ struct AttReadMultipleResponse : public AttServerMessage { } private: - const ArrayView _data; + const Span _data; }; @@ -588,7 +587,7 @@ struct AttReadByGroupTypeResponse : public AttServerMessage { */ struct attribute_data_t { attribute_handle_range_t group_range; - ArrayView value; + Span value; }; /** @@ -651,7 +650,7 @@ struct AttPrepareWriteResponse : public AttServerMessage { AttPrepareWriteResponse( attribute_handle_t handle_, uint16_t offset_, - ArrayView value_ + Span value_ ) : AttServerMessage(AttributeOpcode::PREPARE_WRITE_RESPONSE), attribute_handle(handle_), offset(offset_), @@ -671,7 +670,7 @@ struct AttPrepareWriteResponse : public AttServerMessage { /** * The value of the attribute to be written at the offset indicated. */ - const ArrayView partial_value; + const Span partial_value; }; @@ -712,7 +711,7 @@ struct AttHandleValueNotification : public AttServerMessage { */ AttHandleValueNotification( attribute_handle_t attribute_handle, - ArrayView attribute_value + Span attribute_value ) : AttServerMessage(AttributeOpcode::HANDLE_VALUE_NOTIFICATION), attribute_handle(attribute_handle), attribute_value(attribute_value) { @@ -726,7 +725,7 @@ struct AttHandleValueNotification : public AttServerMessage { /** * The current value of the attribute. */ - const ArrayView attribute_value; + const Span attribute_value; }; @@ -748,7 +747,7 @@ struct AttHandleValueIndication : public AttServerMessage { * value indicated. */ AttHandleValueIndication( - attribute_handle_t handle, ArrayView value + attribute_handle_t handle, Span value ) : AttServerMessage(AttributeOpcode::HANDLE_VALUE_INDICATION), attribute_handle(handle), attribute_value(value) { } @@ -761,7 +760,7 @@ struct AttHandleValueIndication : public AttServerMessage { /** * The current value of the attribute. */ - const ArrayView attribute_value; + const Span attribute_value; }; diff --git a/features/FEATURE_BLE/ble/pal/GapEvents.h b/features/FEATURE_BLE/ble/pal/GapEvents.h index 8e0bb0dd78..79eb8fcce3 100644 --- a/features/FEATURE_BLE/ble/pal/GapEvents.h +++ b/features/FEATURE_BLE/ble/pal/GapEvents.h @@ -18,7 +18,7 @@ #define BLE_PAL_GAP_MESSAGE_H_ #include "GapTypes.h" -#include "ble/ArrayView.h" +#include "ble/BLETypes.h" namespace ble { namespace pal { @@ -307,7 +307,7 @@ struct GapAdvertisingReportEvent : public GapEvent { received_advertising_type_t type; connection_peer_address_type_t address_type; address_t address; - ArrayView data; + Span data; int8_t rssi; }; diff --git a/features/FEATURE_BLE/ble/pal/GenericAccessService.h b/features/FEATURE_BLE/ble/pal/GenericAccessService.h index 14c05e1533..1305528149 100644 --- a/features/FEATURE_BLE/ble/pal/GenericAccessService.h +++ b/features/FEATURE_BLE/ble/pal/GenericAccessService.h @@ -18,7 +18,7 @@ #define BLE_PAL_GENERIC_ACCESS_SERVICE_H_ #include "GapTypes.h" -#include "ble/ArrayView.h" +#include "ble/BLETypes.h" #include "ble/blecommon.h" #include "ble/GapAdvertisingData.h" #include "ble/Gap.h" @@ -71,7 +71,7 @@ struct GenericAccessService { * * @see Bluetooth 4.2 Vol 3 PartC: 12.1 - Device Name Characteristic */ - virtual ble_error_t get_device_name(ArrayView& array) = 0; + virtual ble_error_t get_device_name(Span& array) = 0; /** * Set the value of the device name characteristic exposed by the GAP GATT diff --git a/features/FEATURE_BLE/ble/pal/PalGattClient.h b/features/FEATURE_BLE/ble/pal/PalGattClient.h index bce051ef3a..390f614c57 100644 --- a/features/FEATURE_BLE/ble/pal/PalGattClient.h +++ b/features/FEATURE_BLE/ble/pal/PalGattClient.h @@ -20,7 +20,6 @@ #include "ble/common/StaticInterface.h" #include "ble/UUID.h" #include "ble/BLETypes.h" -#include "ble/ArrayView.h" #include "ble/blecommon.h" #include "platform/Callback.h" @@ -516,7 +515,7 @@ public: */ ble_error_t read_multiple_characteristic_values( connection_handle_t connection_handle, - const ArrayView& characteristic_value_handles + const Span& characteristic_value_handles ) { return self()->read_multiple_characteristic_values_( connection_handle, @@ -540,7 +539,7 @@ public: ble_error_t write_without_response( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { return self()->write_without_response_( connection_handle, @@ -568,7 +567,7 @@ public: ble_error_t signed_write_without_response( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { return self()->signed_write_without_response_( connection_handle, @@ -600,7 +599,7 @@ public: ble_error_t write_attribute( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { return self()->write_attribute_(connection_handle, attribute_handle, value); } @@ -637,7 +636,7 @@ public: ble_error_t queue_prepare_write( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ) { return self()->queue_prepare_write_( diff --git a/features/FEATURE_BLE/ble/pal/SimpleAttServerMessage.h b/features/FEATURE_BLE/ble/pal/SimpleAttServerMessage.h index a0f3346dea..b408d008ea 100644 --- a/features/FEATURE_BLE/ble/pal/SimpleAttServerMessage.h +++ b/features/FEATURE_BLE/ble/pal/SimpleAttServerMessage.h @@ -43,7 +43,7 @@ struct SimpleAttFindInformationResponse : public AttFindInformationResponse { * by the Format field */ SimpleAttFindInformationResponse( - Format format, ArrayView information_data + Format format, Span information_data ) : AttFindInformationResponse(), _format(format), _information_data(information_data), _item_size(information_data_item_size()) { @@ -82,7 +82,7 @@ private: } const Format _format; - const ArrayView _information_data; + const Span _information_data; const size_t _item_size; }; @@ -97,7 +97,7 @@ struct SimpleAttFindByTypeValueResponse : public AttFindByTypeValueResponse { * Handle Informations. * @param handles raw array containing one or more Handle Informations. */ - SimpleAttFindByTypeValueResponse(ArrayView handles) : + SimpleAttFindByTypeValueResponse(Span handles) : AttFindByTypeValueResponse(), _handles(handles) { } @@ -121,7 +121,7 @@ struct SimpleAttFindByTypeValueResponse : public AttFindByTypeValueResponse { private: static const size_t item_size = 4; - const ArrayView _handles; + const Span _handles; }; @@ -138,7 +138,7 @@ struct SimpleAttReadByTypeResponse : public AttReadByTypeResponse { * data. */ SimpleAttReadByTypeResponse( - uint8_t element_size, ArrayView attribute_data + uint8_t element_size, Span attribute_data ) : AttReadByTypeResponse(), _attribute_data(attribute_data), _element_size(element_size) { } @@ -160,7 +160,7 @@ struct SimpleAttReadByTypeResponse : public AttReadByTypeResponse { attribute_data_t result = { handle, - ArrayView( + Span( item + sizeof(handle), _element_size - sizeof(handle) ) @@ -170,7 +170,7 @@ struct SimpleAttReadByTypeResponse : public AttReadByTypeResponse { } private: - ArrayView _attribute_data; + Span _attribute_data; uint8_t _element_size; }; @@ -187,7 +187,7 @@ struct SimpleAttReadByGroupTypeResponse : public AttReadByGroupTypeResponse { * @param attribute_data Byte array containing the list of Attribute Data. */ SimpleAttReadByGroupTypeResponse( - uint8_t element_size, ArrayView attribute_data + uint8_t element_size, Span attribute_data ) : AttReadByGroupTypeResponse(), _attribute_data(attribute_data), _element_size(element_size) { } @@ -212,7 +212,7 @@ struct SimpleAttReadByGroupTypeResponse : public AttReadByGroupTypeResponse { attribute_data_t result = { { begin, end }, - ArrayView( + Span( item + sizeof(begin) + sizeof(end), _element_size - (sizeof(begin) + sizeof(end)) ) @@ -222,7 +222,7 @@ struct SimpleAttReadByGroupTypeResponse : public AttReadByGroupTypeResponse { } private: - ArrayView _attribute_data; + Span _attribute_data; uint8_t _element_size; }; diff --git a/features/FEATURE_BLE/source/generic/GenericGap.tpp b/features/FEATURE_BLE/source/generic/GenericGap.tpp index 0d0e4005cc..025db40c05 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.tpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.tpp @@ -27,7 +27,6 @@ #include "ble/generic/GenericGap.h" #include "drivers/Timeout.h" -#include "platform/Span.h" #include "ble/pal/Deprecated.h" @@ -1018,7 +1017,7 @@ ble_error_t GenericGap name(deviceName, *lengthP); + Span name(deviceName, *lengthP); err = _gap_service.get_device_name(name); if (err) { return err; @@ -1768,7 +1767,7 @@ void GenericGap(advertising.data.data(), advertising.data.size()) + Span(advertising.data.data(), advertising.data.size()) ) ); } @@ -2434,7 +2433,7 @@ ble_error_t GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::setAdvertisingPayload_( advertising_handle_t handle, - mbed::Span payload + Span payload ) { useVersionTwoAPI(); @@ -2450,7 +2449,7 @@ ble_error_t GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::setAdvertisingScanResponse_( advertising_handle_t handle, - mbed::Span response + Span response ) { useVersionTwoAPI(); @@ -2466,7 +2465,7 @@ ble_error_t GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::setAdvertisingData( advertising_handle_t handle, - mbed::Span payload, + Span payload, bool minimiseFragmentation, bool scan_response ) @@ -2562,7 +2561,7 @@ ble_error_t GenericGap sub_payload = payload.subspan( + Span sub_payload = payload.subspan( i, std::min(hci_length, (end - i)) ); @@ -2750,7 +2749,7 @@ ble_error_t GenericGap class PalGapImpl, class PalSecurityManager, class ConnectionEventMonitorEventHandler> ble_error_t GenericGap::setPeriodicAdvertisingPayload_( advertising_handle_t handle, - mbed::Span payload + Span payload ) { useVersionTwoAPI(); @@ -2790,7 +2789,7 @@ ble_error_t GenericGap sub_payload = payload.subspan( + Span sub_payload = payload.subspan( i, std::min(hci_length, (end - i)) ); @@ -2973,7 +2972,7 @@ void GenericGap::DiscoveryC GattClient* client, connection_handle_t connection_handle, uint16_t decl_handle, - const ArrayView value + const Span value ) : DiscoveredCharacteristic() { gattc = client; uuid = get_uuid(value); @@ -378,7 +378,7 @@ struct GenericGattClient::DiscoveryC connHandle = connection_handle; } - static UUID get_uuid(const ArrayView& value) { + static UUID get_uuid(const Span& value) { if (value.size() == 5) { return UUID(value[3] | (value[4] << 8)); } else { @@ -386,7 +386,7 @@ struct GenericGattClient::DiscoveryC } } - static DiscoveredCharacteristic::Properties_t get_properties(const ArrayView& value) { + static DiscoveredCharacteristic::Properties_t get_properties(const Span& value) { uint8_t raw_properties = value[0]; DiscoveredCharacteristic::Properties_t result; result._broadcast = (raw_properties & (1 << 0)) ? true : false; @@ -399,7 +399,7 @@ struct GenericGattClient::DiscoveryC return result; } - static uint16_t get_value_handle(const ArrayView& value) { + static uint16_t get_value_handle(const Span& value) { return value[1] | (value[2] << 8); } @@ -729,7 +729,7 @@ struct GenericGattClient::WriteContr if (offset < len) { err = client->_pal_client->queue_prepare_write( connection_handle, attribute_handle, - make_const_ArrayView( + make_const_Span( data + offset, std::min((len - offset), (mtu_size - 5)) ), @@ -1135,7 +1135,7 @@ ble_error_t GenericGattClient::write return _pal_client->write_without_response( connection_handle, attribute_handle, - make_const_ArrayView(value, length) + make_const_Span(value, length) ); #if BLE_FEATURE_SIGNING } else if (cmd == Base::GATT_OP_SIGNED_WRITE_CMD) { @@ -1145,7 +1145,7 @@ ble_error_t GenericGattClient::write ble_error_t status = _pal_client->signed_write_without_response( connection_handle, attribute_handle, - make_const_ArrayView(value, length) + make_const_Span(value, length) ); if (_signing_event_handler && (status == BLE_ERROR_NONE)) { @@ -1183,14 +1183,14 @@ ble_error_t GenericGattClient::write err = _pal_client->queue_prepare_write( connection_handle, attribute_handle, - make_const_ArrayView(value, mtu - PREPARE_WRITE_HEADER_LENGTH), + make_const_Span(value, mtu - PREPARE_WRITE_HEADER_LENGTH), /* offset */0 ); } else { err = _pal_client->write_attribute( connection_handle, attribute_handle, - make_const_ArrayView(value, length) + make_const_Span(value, length) ); } diff --git a/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp b/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp index 8fe9624463..05ae0a1117 100644 --- a/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp +++ b/features/FEATURE_BLE/source/generic/GenericSecurityManager.tpp @@ -861,7 +861,7 @@ ble_error_t GenericSecurityManager::init_re new (std::nothrow) SecurityEntryIdentity_t[resolving_list_capacity]; if (identity_list_p) { - ArrayView identity_list( + Span identity_list( identity_list_p, resolving_list_capacity ); @@ -1187,7 +1187,7 @@ void GenericSecurityManager::on_security_en template class TPalSecurityManager, template class SigningMonitor> void GenericSecurityManager::on_identity_list_retrieved( - ble::ArrayView& identity_list, + Span& identity_list, size_t count ) { typedef advertising_peer_address_type_t address_type_t; diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h index 1c2d9657d1..ea25bcc922 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalAttClient.h @@ -83,7 +83,7 @@ public: connection_handle_t connection_handle, attribute_handle_range_t discovery_range, uint16_t type, - const ArrayView& value + const Span& value ) { AttcFindByTypeValueReq( connection_handle, @@ -149,7 +149,7 @@ public: */ ble_error_t read_multiple_request_( connection_handle_t connection_handle, - const ArrayView& attribute_handles + const Span& attribute_handles ) { AttcReadMultipleReq( connection_handle, @@ -184,7 +184,7 @@ public: ble_error_t write_request_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { AttcWriteReq( connection_handle, @@ -201,7 +201,7 @@ public: ble_error_t write_command_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { AttcWriteCmd( connection_handle, @@ -218,7 +218,7 @@ public: ble_error_t signed_write_command_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { AttcSignedWriteCmd( connection_handle, @@ -250,7 +250,7 @@ public: connection_handle_t connection_handle, attribute_handle_t attribute_handle, uint16_t offset, - const ArrayView& value + const Span& value ) { AttcPrepareWriteReq( connection_handle, @@ -409,7 +409,7 @@ private: { return SimpleAttFindInformationResponse( static_cast(event->pValue[0]), - make_const_ArrayView( + make_const_Span( event->pValue + 1, event->valueLen - 1 ) @@ -424,7 +424,7 @@ private: static SimpleAttFindByTypeValueResponse convert(const attEvt_t* event) { return SimpleAttFindByTypeValueResponse( - make_const_ArrayView( + make_const_Span( event->pValue, event->valueLen ) @@ -440,7 +440,7 @@ private: { return SimpleAttReadByTypeResponse( event->pValue[0], - make_const_ArrayView( + make_const_Span( event->pValue + 1, event->valueLen - 1 ) @@ -455,7 +455,7 @@ private: static AttReadResponse convert(const attEvt_t* event) { return AttReadResponse( - make_const_ArrayView( + make_const_Span( event->pValue, event->valueLen ) @@ -470,7 +470,7 @@ private: static AttReadBlobResponse convert(const attEvt_t* event) { return AttReadBlobResponse( - make_const_ArrayView( + make_const_Span( event->pValue, event->valueLen ) @@ -485,7 +485,7 @@ private: static AttReadMultipleResponse convert(const attEvt_t* event) { return AttReadMultipleResponse( - make_const_ArrayView( + make_const_Span( event->pValue, event->valueLen ) @@ -501,7 +501,7 @@ private: { return SimpleAttReadByGroupTypeResponse( event->pValue[0], - make_const_ArrayView( + make_const_Span( event->pValue + 1, event->valueLen - 1 ) @@ -530,7 +530,7 @@ private: event->handle, to_uint16_t(event->pValue + 2), // FIXME: the stack set the lenght to 0, the data won't be seen ... - make_const_ArrayView( + make_const_Span( event->pValue + 4, event->valueLen ) @@ -556,7 +556,7 @@ private: { return AttHandleValueNotification( event->handle, - make_const_ArrayView( + make_const_Span( event->pValue, event->valueLen ) @@ -572,7 +572,7 @@ private: { return AttHandleValueIndication( event->handle, - make_const_ArrayView( + make_const_Span( event->pValue, event->valueLen ) diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h index 69b8674af3..a9e82cbcb1 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGap.h @@ -366,7 +366,7 @@ private: (received_advertising_type_t::type) scan_report->eventType, (connection_peer_address_type_t::type) scan_report->addrType, scan_report->addr, - make_const_ArrayView(scan_report->pData, scan_report->len), + make_const_Span(scan_report->pData, scan_report->len), scan_report->rssi }; return CordioGapAdvertisingReportEvent(advertising); diff --git a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h index 53f4728cf7..951dd4803e 100644 --- a/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h +++ b/features/FEATURE_BLE/targets/TARGET_CORDIO/CordioPalGenericAccessService.h @@ -33,7 +33,7 @@ public: #endif } - virtual ble_error_t get_device_name(ArrayView& array) { + virtual ble_error_t get_device_name(Span& array) { #if BLE_FEATURE_GATT_SERVER const uint8_t* name = NULL; uint16_t length = 0; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.cpp index e6ff14a21b..3fed2c5dde 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.cpp @@ -66,9 +66,9 @@ CryptoToolbox::~CryptoToolbox() { } bool CryptoToolbox::generate_keys( - ArrayView X, - ArrayView Y, - ArrayView secret + Span X, + Span Y, + Span secret ) { mbedtls_mpi secret_key; mbedtls_ecp_point public_keys; @@ -97,10 +97,10 @@ bool CryptoToolbox::generate_keys( } bool CryptoToolbox::generate_shared_secret( - const ArrayView& peer_X, - const ArrayView& peer_Y, - const ArrayView& own_secret, - ArrayView shared_secret + const Span& peer_X, + const Span& peer_Y, + const Span& own_secret, + Span shared_secret ) { mbedtls_mpi result; mbedtls_mpi secret_key; @@ -138,9 +138,9 @@ bool CryptoToolbox::generate_shared_secret( #endif bool CryptoToolbox::ah( - const ArrayView& irk, - const ArrayView& prand, - ArrayView hash + const Span& irk, + const Span& prand, + Span hash ) { // Note copy then swap operation can be optimized. @@ -169,13 +169,13 @@ bool CryptoToolbox::ah( #if defined(MBEDTLS_ECDH_C) -void CryptoToolbox::load_mpi(mbedtls_mpi& dest, const ArrayView& src) { +void CryptoToolbox::load_mpi(mbedtls_mpi& dest, const Span& src) { ble::public_key_coord_t src_be = src.data(); swap_endian(src_be.data(), src_be.size()); mbedtls_mpi_read_binary(&dest, src_be.data(), src_be.size()); } -void CryptoToolbox::store_mpi(ArrayView& dest, const mbedtls_mpi& src) { +void CryptoToolbox::store_mpi(Span& dest, const mbedtls_mpi& src) { mbedtls_mpi_write_binary(&src, dest.data(), dest.size()); swap_endian(dest.data(), dest.size()); } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.h index 123fac3564..4dcd327501 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xCrypto.h @@ -88,9 +88,9 @@ public: * false otherwise. */ bool generate_keys( - ArrayView X, - ArrayView Y, - ArrayView secret + Span X, + Span Y, + Span secret ); /** @@ -103,10 +103,10 @@ public: * false otherwise. */ bool generate_shared_secret( - const ArrayView& peer_X, - const ArrayView& peer_Y, - const ArrayView& own_secret, - ArrayView shared_secret + const Span& peer_X, + const Span& peer_Y, + const Span& own_secret, + Span shared_secret ); #endif @@ -125,17 +125,17 @@ public: * @return true in case of success and false otherwise. */ static bool ah( - const ArrayView& irk, - const ArrayView& prand, - ArrayView hash + const Span& irk, + const Span& prand, + Span hash ); private: #if defined(MBEDTLS_ECDH_C) - void load_mpi(mbedtls_mpi& dest, const ArrayView& src); + void load_mpi(mbedtls_mpi& dest, const Span& src); - void store_mpi(ArrayView& dest, const mbedtls_mpi& src); + void store_mpi(Span& dest, const mbedtls_mpi& src); #endif static void swap_endian(uint8_t* buf, size_t len); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGap.cpp index 2302336dd0..66e8e6b2d1 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xGap.cpp @@ -42,7 +42,7 @@ template class ble::interface::Gap; using ble::pal::vendor::nordic::nRF5xSecurityManager; typedef ble::impl::PalSecurityManagerImpl::resolving_list_entry_t resolving_list_entry_t; -using ble::ArrayView; +using mbed::Span; using ble::pal::advertising_peer_address_type_t; using ble::peer_address_type_t; @@ -280,10 +280,10 @@ ble_error_t nRF5xGap::startAdvertising_(const GapAdvertisingParams ¶ms) if (_privacy_enabled) { if (_peripheral_privacy_configuration.resolution_strategy != PeripheralPrivacyConfiguration_t::DO_NOT_RESOLVE) { - ArrayView entries = get_sm().get_resolving_list(); + Span entries = get_sm().get_resolving_list(); size_t limit = std::min( - entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE + (size_t) entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE ); for (size_t i = 0; i < limit; ++i) { @@ -348,10 +348,10 @@ ble_error_t nRF5xGap::startRadioScan_(const GapScanningParams &scanningParams) if (_privacy_enabled) { if (_central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::DO_NOT_RESOLVE) { - ArrayView entries = get_sm().get_resolving_list(); + Span entries = get_sm().get_resolving_list(); size_t limit = std::min( - entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE + (size_t) entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE ); for (size_t i = 0; i < limit; ++i) { @@ -531,10 +531,10 @@ ble_error_t nRF5xGap::connect( if (_privacy_enabled) { if (_central_privacy_configuration.resolution_strategy != CentralPrivacyConfiguration_t::DO_NOT_RESOLVE) { - ArrayView entries = get_sm().get_resolving_list(); + Span entries = get_sm().get_resolving_list(); size_t limit = std::min( - entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE + (size_t) entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE ); for (size_t i = 0; i < limit; ++i) { diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.h index dbb1ff38ed..22591f3e61 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.h @@ -136,7 +136,7 @@ public: */ ble_error_t read_multiple_characteristic_values_( connection_handle_t connection, - const ArrayView& characteristic_handles + const Span& characteristic_handles ); /** @@ -145,7 +145,7 @@ public: ble_error_t write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ); /** @@ -154,7 +154,7 @@ public: ble_error_t signed_write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ); /** @@ -163,7 +163,7 @@ public: ble_error_t write_attribute_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ); /** @@ -172,7 +172,7 @@ public: ble_error_t queue_prepare_write_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.tpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.tpp index 513d199e3c..14bd6486c4 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.tpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalGattClient.tpp @@ -285,7 +285,7 @@ ble_error_t nRF5xGattClient::read_attribute_blob_( template ble_error_t nRF5xGattClient::read_multiple_characteristic_values_( connection_handle_t connection, - const ArrayView& characteristic_handles + const Span& characteristic_handles ) { return launch_procedure( connection, characteristic_handles @@ -296,7 +296,7 @@ template ble_error_t nRF5xGattClient::write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { ble_gattc_write_params_t write_params = { BLE_GATT_OP_WRITE_CMD, @@ -315,7 +315,7 @@ template ble_error_t nRF5xGattClient::signed_write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { ble_gattc_write_params_t write_params = { BLE_GATT_OP_SIGN_WRITE_CMD, @@ -334,7 +334,7 @@ template ble_error_t nRF5xGattClient::write_attribute_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { return launch_procedure( connection_handle, attribute_handle, value @@ -345,7 +345,7 @@ template ble_error_t nRF5xGattClient::queue_prepare_write_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ) { return launch_procedure( @@ -513,7 +513,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProc using GattProcedure::procedure_opcode; using GattProcedure::connection_handle; using GattProcedure::terminate; - typedef ArrayView services_array_t; + typedef Span services_array_t; DiscoverPrimaryServiceProcedure(connection_handle_t connection) : GattProcedure(connection, AttributeOpcode::READ_BY_GROUP_TYPE_REQUEST), @@ -605,7 +605,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProc { attribute_data_t result = { to_ble_handle_range(services[i].handle_range), - make_const_ArrayView( + make_const_Span( reinterpret_cast(&services[i].uuid.uuid), sizeof(uint16_t) ) @@ -692,7 +692,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProc if (idx == count) { terminate(SimpleAttReadByGroupTypeResponse( sizeof(packed_discovery_response_t), - make_const_ArrayView( + make_const_Span( reinterpret_cast(response), count * sizeof(packed_discovery_response_t) )) @@ -726,7 +726,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : Re using GattProcedure::procedure_opcode; using GattProcedure::connection_handle; using GattProcedure::terminate; - typedef ArrayView services_array_t; + typedef Span services_array_t; DiscoverPrimaryServiceByUUIDProcedure(connection_handle_t connection) : RegularGattProcedure( @@ -779,7 +779,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : Re { attribute_data_t result = { to_ble_handle_range(services[i].handle_range), - make_ArrayView(uuid.getBaseUUID(), uuid.getLen()) + make_Span(uuid.getBaseUUID(), uuid.getLen()) }; return result; } @@ -804,7 +804,7 @@ struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGat using GattProcedure::procedure_opcode; using GattProcedure::connection_handle; using GattProcedure::terminate; - typedef ArrayView services_array_t; + typedef Span services_array_t; FindIncludedServicesProcedure(connection_handle_t connection) : RegularGattProcedure( @@ -860,7 +860,7 @@ struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGat terminate(SimpleAttReadByTypeResponse( element_size, - make_const_ArrayView(buffer, buffer_size) + make_const_Span(buffer, buffer_size) )); delete[] buffer; @@ -1031,7 +1031,7 @@ struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattPro void forward_response_and_terminate() { terminate(SimpleAttReadByTypeResponse( _response.element_size, - make_const_ArrayView( + make_const_Span( _response.buffer, _response.element_size * _response.count ) @@ -1223,7 +1223,7 @@ struct nRF5xGattClient::ReadAttributeProcedure : RegularGattProced return; } - terminate(AttReadResponse(make_const_ArrayView(rsp.data, rsp.len))); + terminate(AttReadResponse(make_const_Span(rsp.data, rsp.len))); } }; @@ -1278,7 +1278,7 @@ struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : Reg terminate(SimpleAttReadByTypeResponse( element_size, - make_const_ArrayView( + make_const_Span( rsp.handle_value, rsp.count * element_size ) @@ -1304,7 +1304,7 @@ struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : Reg { attribute_data_t result = { response.handle_value[i].handle, - make_const_ArrayView( + make_const_Span( response.handle_value[i].p_value, response.value_len ) @@ -1345,7 +1345,7 @@ struct nRF5xGattClient::ReadAttributeBlobProcedure : RegularGattPr virtual void do_handle(const ble_gattc_evt_t &evt) { - terminate(AttReadBlobResponse(make_const_ArrayView( + terminate(AttReadBlobResponse(make_const_Span( evt.params.read_rsp.data, evt.params.read_rsp.len ))); @@ -1369,7 +1369,7 @@ struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : Reg BLE_GATTC_EVT_CHAR_VALS_READ_RSP ) { } - ble_error_t start(const ArrayView& characteristic_handles) + ble_error_t start(const Span& characteristic_handles) { uint32_t err = sd_ble_gattc_char_values_read( connection_handle, @@ -1381,7 +1381,7 @@ struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : Reg virtual void do_handle(const ble_gattc_evt_t &evt) { - terminate(AttReadMultipleResponse(make_const_ArrayView( + terminate(AttReadMultipleResponse(make_const_Span( evt.params.char_vals_read_rsp.values, evt.params.char_vals_read_rsp.len ))); @@ -1404,7 +1404,7 @@ struct nRF5xGattClient::WriteAttributeProcedure : RegularGattProce ) { } ble_error_t start( - attribute_handle_t attribute_handle, const ArrayView& value + attribute_handle_t attribute_handle, const Span& value ) { ble_gattc_write_params_t write_params = { BLE_GATT_OP_WRITE_REQ, @@ -1444,7 +1444,7 @@ struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattPr ble_error_t start( attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ) { ble_gattc_write_params_t write_params = { @@ -1472,7 +1472,7 @@ struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattPr terminate(AttPrepareWriteResponse( response.handle, response.offset, - make_const_ArrayView(response.data, response.len) + make_const_Span(response.data, response.len) )); } }; @@ -1730,7 +1730,7 @@ void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt) connection, AttHandleValueNotification( hvx_evt.handle, - make_const_ArrayView(hvx_evt.data, hvx_evt.len) + make_const_Span(hvx_evt.data, hvx_evt.len) ) ); return; @@ -1741,7 +1741,7 @@ void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt) connection, AttHandleValueIndication( hvx_evt.handle, - make_const_ArrayView(hvx_evt.data, hvx_evt.len) + make_const_Span(hvx_evt.data, hvx_evt.len) ) ); return; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.h index 6ac36879a7..1207bc8a06 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.h @@ -110,7 +110,7 @@ public: * @param count The number of entries present in the resolving list. * @param pointer to the first entry of the resolving list. */ - ArrayView get_resolving_list(); + Span get_resolving_list(); /** * Try to resolve a private resolvable address. diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.tpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.tpp index fb5ccba2fc..8a87dae66a 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.tpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF51/source/nRF5xPalSecurityManager.tpp @@ -114,9 +114,9 @@ ble_error_t nRF5xSecurityManager::initialize_() { #if defined(MBEDTLS_ECDH_C) if (_crypto.generate_keys( - make_ArrayView(X), - make_ArrayView(Y), - make_ArrayView(secret) + make_Span(X), + make_Span(Y), + make_Span(secret) )) { return BLE_ERROR_NONE; } @@ -216,9 +216,9 @@ ble_error_t nRF5xSecurityManager::clear_resolving_list_() } template -ArrayView::resolving_list_entry_t> +Span::resolving_list_entry_t> nRF5xSecurityManager::get_resolving_list() { - return ArrayView( + return Span( resolving_list, resolving_list_entry_count ); @@ -236,11 +236,11 @@ nRF5xSecurityManager::resolve_address(const address_t& resolvable_ // Compute the hash part from the random address part when the irk of // the entry is used CryptoToolbox::ah( - make_const_ArrayView(entry.peer_irk), - make_const_ArrayView( + make_const_Span(entry.peer_irk), + make_const_Span( resolvable_address.data() + CryptoToolbox::hash_size_ ), - make_ArrayView(hash_generated) + make_Span(hash_generated) ); // Compare hash generated with the hash present in the address passed as @@ -953,9 +953,9 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt) ble_gap_lesc_dhkey_t shared_secret; _crypto.generate_shared_secret( - make_const_ArrayView(dhkey_request.p_pk_peer->pk), - make_const_ArrayView(dhkey_request.p_pk_peer->pk + key_size), - make_const_ArrayView(secret), + make_const_Span(dhkey_request.p_pk_peer->pk), + make_const_Span(dhkey_request.p_pk_peer->pk + key_size), + make_const_Span(secret), shared_secret.key ); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.cpp index 32419875a2..968fa26998 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.cpp @@ -64,9 +64,9 @@ CryptoToolbox::~CryptoToolbox() { } bool CryptoToolbox::generate_keys( - ArrayView X, - ArrayView Y, - ArrayView secret + Span X, + Span Y, + Span secret ) { mbedtls_mpi secret_key; mbedtls_ecp_point public_keys; @@ -95,10 +95,10 @@ bool CryptoToolbox::generate_keys( } bool CryptoToolbox::generate_shared_secret( - const ArrayView& peer_X, - const ArrayView& peer_Y, - const ArrayView& own_secret, - ArrayView shared_secret + const Span& peer_X, + const Span& peer_Y, + const Span& own_secret, + Span shared_secret ) { mbedtls_mpi result; mbedtls_mpi secret_key; @@ -134,9 +134,9 @@ bool CryptoToolbox::generate_shared_secret( } bool CryptoToolbox::ah( - const ArrayView& irk, - const ArrayView& prand, - ArrayView hash + const Span& irk, + const Span& prand, + Span hash ) { // Note copy then swap operation can be optimized. @@ -164,13 +164,13 @@ bool CryptoToolbox::ah( } -void CryptoToolbox::load_mpi(mbedtls_mpi& dest, const ArrayView& src) { +void CryptoToolbox::load_mpi(mbedtls_mpi& dest, const Span& src) { ble::public_key_coord_t src_be = src.data(); swap_endian(src_be.data(), src_be.size()); mbedtls_mpi_read_binary(&dest, src_be.data(), src_be.size()); } -void CryptoToolbox::store_mpi(ArrayView& dest, const mbedtls_mpi& src) { +void CryptoToolbox::store_mpi(Span& dest, const mbedtls_mpi& src) { mbedtls_mpi_write_binary(&src, dest.data(), dest.size()); swap_endian(dest.data(), dest.size()); } diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.h index 35c56a875e..c31da3cfa1 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xCrypto.h @@ -84,9 +84,9 @@ public: * false otherwise. */ bool generate_keys( - ArrayView X, - ArrayView Y, - ArrayView secret + Span X, + Span Y, + Span secret ); /** @@ -99,10 +99,10 @@ public: * false otherwise. */ bool generate_shared_secret( - const ArrayView& peer_X, - const ArrayView& peer_Y, - const ArrayView& own_secret, - ArrayView shared_secret + const Span& peer_X, + const Span& peer_Y, + const Span& own_secret, + Span shared_secret ); /** @@ -119,15 +119,15 @@ public: * @return true in case of success and false otherwise. */ bool ah( - const ArrayView& irk, - const ArrayView& prand, - ArrayView hash + const Span& irk, + const Span& prand, + Span hash ); private: - void load_mpi(mbedtls_mpi& dest, const ArrayView& src); + void load_mpi(mbedtls_mpi& dest, const Span& src); - void store_mpi(ArrayView& dest, const mbedtls_mpi& src); + void store_mpi(Span& dest, const mbedtls_mpi& src); void swap_endian(uint8_t* buf, size_t len); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp index f5e1789bd5..43886594de 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xGap.cpp @@ -40,7 +40,7 @@ template class ble::interface::LegacyGap; template class ble::interface::Gap; using ble::pal::vendor::nordic::nRF5xSecurityManager; -using ble::ArrayView; +using mbed::Span; using ble::pal::advertising_peer_address_type_t; using ble::peer_address_type_t; @@ -360,10 +360,10 @@ ble_error_t nRF5xGap::startAdvertising_(const GapAdvertisingParams ¶ms) if (_privacy_enabled) { if (_peripheral_privacy_configuration.resolution_strategy != PeripheralPrivacyConfiguration_t::DO_NOT_RESOLVE) { - ArrayView entries = get_sm().get_resolving_list(); + Span entries = get_sm().get_resolving_list(); size_t limit = std::min( - entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE + (size_t) entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE ); for (size_t i = 0; i < limit; ++i) { @@ -703,10 +703,10 @@ ble_error_t nRF5xGap::connect( // configure the "whitelist" with the IRK associated with the identity // address in input. if (is_identity_address(peerAddrType)) { - ArrayView entries = get_sm().get_resolving_list(); + Span entries = get_sm().get_resolving_list(); size_t i; - for (i = 0; i < entries.size(); ++i) { + for (i = 0; i < (size_t) entries.size(); ++i) { const ble::address_t& entry_address = entries[i].peer_identity_address; // entry found; fill the whitelist and invalidate addr_ptr @@ -720,7 +720,7 @@ ble_error_t nRF5xGap::connect( } // Occur only if the address in input hasn't been resolved. - if (i == entries.size()) { + if (i == (size_t) entries.size()) { return BLE_ERROR_INVALID_PARAM; } } @@ -1540,9 +1540,9 @@ ble_error_t nRF5xGap::update_identities_list(bool resolution_enabled) uint32_t err; if (resolution_enabled) { - ArrayView entries = get_sm().get_resolving_list(); + Span entries = get_sm().get_resolving_list(); size_t limit = std::min( - entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE + (size_t) entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE ); ble_gap_id_key_t* id_keys_pp[YOTTA_CFG_IRK_TABLE_MAX_SIZE]; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h index aae819f60d..856edddffa 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.h @@ -136,7 +136,7 @@ public: */ ble_error_t read_multiple_characteristic_values_( connection_handle_t connection, - const ArrayView& characteristic_handles + const Span& characteristic_handles ); /** @@ -145,7 +145,7 @@ public: ble_error_t write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ); /** @@ -154,7 +154,7 @@ public: ble_error_t signed_write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ); /** @@ -163,7 +163,7 @@ public: ble_error_t write_attribute_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ); /** @@ -172,7 +172,7 @@ public: ble_error_t queue_prepare_write_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ); diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.tpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.tpp index 9666435e4d..e461e9062b 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.tpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalGattClient.tpp @@ -287,7 +287,7 @@ ble_error_t nRF5xGattClient::read_attribute_blob_( template ble_error_t nRF5xGattClient::read_multiple_characteristic_values_( connection_handle_t connection, - const ArrayView& characteristic_handles + const Span& characteristic_handles ) { return launch_procedure( connection, characteristic_handles @@ -298,7 +298,7 @@ template ble_error_t nRF5xGattClient::write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { ble_gattc_write_params_t write_params = { BLE_GATT_OP_WRITE_CMD, @@ -317,7 +317,7 @@ template ble_error_t nRF5xGattClient::signed_write_without_response_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value + const Span& value ) { ble_gattc_write_params_t write_params = { BLE_GATT_OP_SIGN_WRITE_CMD, @@ -336,7 +336,7 @@ template ble_error_t nRF5xGattClient::write_attribute_( connection_handle_t connection_handle, attribute_handle_t attribute_handle, - const ArrayView& value + const Span& value ) { return launch_procedure( connection_handle, attribute_handle, value @@ -347,7 +347,7 @@ template ble_error_t nRF5xGattClient::queue_prepare_write_( connection_handle_t connection_handle, attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ) { return launch_procedure( @@ -515,7 +515,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProc using GattProcedure::procedure_opcode; using GattProcedure::connection_handle; using GattProcedure::terminate; - typedef ArrayView services_array_t; + typedef Span services_array_t; DiscoverPrimaryServiceProcedure(connection_handle_t connection) : GattProcedure(connection, AttributeOpcode::READ_BY_GROUP_TYPE_REQUEST), @@ -607,7 +607,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProc { attribute_data_t result = { to_ble_handle_range(services[i].handle_range), - make_const_ArrayView( + make_const_Span( reinterpret_cast(&services[i].uuid.uuid), sizeof(uint16_t) ) @@ -694,7 +694,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceProcedure : GattProc if (idx == count) { terminate(SimpleAttReadByGroupTypeResponse( sizeof(packed_discovery_response_t), - make_const_ArrayView( + make_const_Span( reinterpret_cast(response), count * sizeof(packed_discovery_response_t) )) @@ -728,7 +728,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : Re using GattProcedure::procedure_opcode; using GattProcedure::connection_handle; using GattProcedure::terminate; - typedef ArrayView services_array_t; + typedef Span services_array_t; DiscoverPrimaryServiceByUUIDProcedure(connection_handle_t connection) : RegularGattProcedure( @@ -781,7 +781,7 @@ struct nRF5xGattClient::DiscoverPrimaryServiceByUUIDProcedure : Re { attribute_data_t result = { to_ble_handle_range(services[i].handle_range), - make_ArrayView(uuid.getBaseUUID(), uuid.getLen()) + make_Span(uuid.getBaseUUID(), uuid.getLen()) }; return result; } @@ -806,7 +806,7 @@ struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGat using GattProcedure::procedure_opcode; using GattProcedure::connection_handle; using GattProcedure::terminate; - typedef ArrayView services_array_t; + typedef Span services_array_t; FindIncludedServicesProcedure(connection_handle_t connection) : RegularGattProcedure( @@ -862,7 +862,7 @@ struct nRF5xGattClient::FindIncludedServicesProcedure : RegularGat terminate(SimpleAttReadByTypeResponse( element_size, - make_const_ArrayView(buffer, buffer_size) + make_const_Span(buffer, buffer_size) )); delete[] buffer; @@ -1033,7 +1033,7 @@ struct nRF5xGattClient::DiscoverCharacteristicsProcedure : GattPro void forward_response_and_terminate() { terminate(SimpleAttReadByTypeResponse( _response.element_size, - make_const_ArrayView( + make_const_Span( _response.buffer, _response.element_size * _response.count ) @@ -1226,7 +1226,7 @@ struct nRF5xGattClient::ReadAttributeProcedure : RegularGattProced return; } - terminate(AttReadResponse(make_const_ArrayView(rsp.data, rsp.len))); + terminate(AttReadResponse(make_const_Span(rsp.data, rsp.len))); } }; @@ -1281,7 +1281,7 @@ struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : Reg terminate(SimpleAttReadByTypeResponse( element_size, - make_const_ArrayView( + make_const_Span( rsp.handle_value, rsp.count * element_size ) @@ -1307,7 +1307,7 @@ struct nRF5xGattClient::ReadUsingCharacteristicUUIDProcedure : Reg { attribute_data_t result = { response.handle_value[i].handle, - make_const_ArrayView( + make_const_Span( response.handle_value[i].p_value, response.value_len ) @@ -1348,7 +1348,7 @@ struct nRF5xGattClient::ReadAttributeBlobProcedure : RegularGattPr virtual void do_handle(const ble_gattc_evt_t &evt) { - terminate(AttReadBlobResponse(make_const_ArrayView( + terminate(AttReadBlobResponse(make_const_Span( evt.params.read_rsp.data, evt.params.read_rsp.len ))); @@ -1372,7 +1372,7 @@ struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : Reg BLE_GATTC_EVT_CHAR_VALS_READ_RSP ) { } - ble_error_t start(const ArrayView& characteristic_handles) + ble_error_t start(const Span& characteristic_handles) { uint32_t err = sd_ble_gattc_char_values_read( connection_handle, @@ -1384,7 +1384,7 @@ struct nRF5xGattClient::ReadMultipleCharacteristicsProcedure : Reg virtual void do_handle(const ble_gattc_evt_t &evt) { - terminate(AttReadMultipleResponse(make_const_ArrayView( + terminate(AttReadMultipleResponse(make_const_Span( evt.params.char_vals_read_rsp.values, evt.params.char_vals_read_rsp.len ))); @@ -1407,7 +1407,7 @@ struct nRF5xGattClient::WriteAttributeProcedure : RegularGattProce ) { } ble_error_t start( - attribute_handle_t attribute_handle, const ArrayView& value + attribute_handle_t attribute_handle, const Span& value ) { ble_gattc_write_params_t write_params = { BLE_GATT_OP_WRITE_REQ, @@ -1447,7 +1447,7 @@ struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattPr ble_error_t start( attribute_handle_t characteristic_value_handle, - const ArrayView& value, + const Span& value, uint16_t offset ) { ble_gattc_write_params_t write_params = { @@ -1475,7 +1475,7 @@ struct nRF5xGattClient::QueuePrepareWriteProcedure : RegularGattPr terminate(AttPrepareWriteResponse( response.handle, response.offset, - make_const_ArrayView(response.data, response.len) + make_const_Span(response.data, response.len) )); } }; @@ -1733,7 +1733,7 @@ void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt) connection, AttHandleValueNotification( hvx_evt.handle, - make_const_ArrayView(hvx_evt.data, hvx_evt.len) + make_const_Span(hvx_evt.data, hvx_evt.len) ) ); return; @@ -1744,7 +1744,7 @@ void nRF5xGattClient::handle_hvx_event(const ble_evt_t &evt) connection, AttHandleValueIndication( hvx_evt.handle, - make_const_ArrayView(hvx_evt.data, hvx_evt.len) + make_const_Span(hvx_evt.data, hvx_evt.len) ) ); return; diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h index 4a31345b85..8174c8df9a 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.h @@ -95,7 +95,7 @@ public: * @param count The number of entries present in the resolving list. * @param pointer to the first entry of the resolving list. */ - ArrayView get_resolving_list(); + Span get_resolving_list(); //////////////////////////////////////////////////////////////////////////// // Pairing diff --git a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.tpp b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.tpp index a0324a11d1..935fac82c8 100644 --- a/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.tpp +++ b/features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NORDIC_SOFTDEVICE/TARGET_NRF52/source/nRF5xPalSecurityManager.tpp @@ -114,9 +114,9 @@ ble_error_t nRF5xSecurityManager::initialize_() // Please do not change or we risk a stack overflow. CryptoToolbox* crypto = new CryptoToolbox(); bool success = crypto->generate_keys( - make_ArrayView(X), - make_ArrayView(Y), - make_ArrayView(secret) + make_Span(X), + make_Span(Y), + make_Span(secret) ); delete crypto; @@ -223,8 +223,8 @@ ble_error_t nRF5xSecurityManager::clear_resolving_list_() } template -ArrayView nRF5xSecurityManager::get_resolving_list() { - return ArrayView( +Span nRF5xSecurityManager::get_resolving_list() { + return Span( resolving_list, resolving_list_entry_count ); @@ -985,9 +985,9 @@ bool nRF5xSecurityManager::sm_handler(const ble_evt_t *evt) // Risk stack overflows if allocated on stack. CryptoToolbox* crypto = new CryptoToolbox(); crypto->generate_shared_secret( - make_const_ArrayView(dhkey_request.p_pk_peer->pk), - make_const_ArrayView(dhkey_request.p_pk_peer->pk + key_size), - make_const_ArrayView(secret), + make_const_Span(dhkey_request.p_pk_peer->pk), + make_const_Span(dhkey_request.p_pk_peer->pk + key_size), + ble::make_const_Span(secret), shared_secret.key ); delete crypto; From 7426a8a8605875483adfe8bfeeed6cf91ef12d4d Mon Sep 17 00:00:00 2001 From: Lingkai Dong Date: Fri, 24 May 2019 13:18:40 +0100 Subject: [PATCH 2/2] Remove ArrayView All use of ArrayView within mbed-os have been removed, and it is not a public API. --- features/FEATURE_BLE/ble/ArrayView.h | 443 --------------------------- 1 file changed, 443 deletions(-) delete mode 100644 features/FEATURE_BLE/ble/ArrayView.h diff --git a/features/FEATURE_BLE/ble/ArrayView.h b/features/FEATURE_BLE/ble/ArrayView.h deleted file mode 100644 index fad829eba1..0000000000 --- a/features/FEATURE_BLE/ble/ArrayView.h +++ /dev/null @@ -1,443 +0,0 @@ -/* mbed Microcontroller Library - * Copyright (c) 2017-2017 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BLE_ARRAY_VIEW_H_ -#define BLE_ARRAY_VIEW_H_ - -#include - -#include -#include -#include "platform/mbed_assert.h" - -/** - * @addtogroup ble - * @{ - * @addtogroup common - * @{ - */ - -/** - * @file - */ - -namespace ble { - -/** - * Special value for the Size parameter of ArrayView. - * If the type use this value then the size of the array is stored in the object - * at runtime. - */ -#define ARRAY_VIEW_DYNAMIC_SIZE -1 - -/** - * Immutable view to an array. - * - * Array views encapsulate the pointer to an array and its size into a single - * object or type; however, it does not manage the lifetime of the array viewed. - * You can use instances of ArrayView to replace the traditional pair of pointer - * and size arguments in function calls. - * - * You can use the size member function to query the number of elements present - * in the array, and overloads of the subscript operator allow code using - * this object to access to the content of the array viewed. - * - * @note You can create ArrayView instances with the help of the function - * template make_ArrayView() and make_const_ArrayView(). - * - * @note ArrayView objects can be implicitly converted to ArrayView - * objects where required. - * - * @tparam T type of objects held by the array. - * @tparam Size The size of the array viewed. The default value - * ARRAY_VIEW_DYNAMIC_SIZE is special as it allows construction of ArrayView - * objects of any size (set at runtime). - */ -template -struct ArrayView { - - MBED_STATIC_ASSERT(Size >= 0, "Invalid size for an ArrayView"); - - /** - * Construct a view to an empty array. - * - * @post a call to size() will return 0, and data() will return NULL. - */ - ArrayView() : _array(NULL) { } - - /** - * Construct an array view from a pointer to a buffer. - * - * @param array_ptr Pointer to the array data - * @param array_size Number of elements of T present in the array. - * - * @post a call to size() will return array_size and data() will return - * array_tpr. - */ - ArrayView(T* array_ptr, size_t array_size) : - _array(array_ptr) { - MBED_ASSERT(array_size >= (size_t) Size); - } - - /** - * Construct an array view from the reference to an array. - * - * @param elements Reference to the array viewed. - * - * @tparam Size Number of elements of T presents in the array. - * - * @post a call to size() will return Size, and data() will return - * a pointer to elements. - */ - ArrayView(T (&elements)[Size]): - _array(elements) { } - - /** - * Return the size of the array viewed. - * - * @return The number of elements present in the array viewed. - */ - size_t size() const - { - return _array ? Size : 0; - } - - /** - * Access to a mutable element of the array. - * - * @param index Element index to access. - * - * @return A reference to the element at the index specified in input. - * - * @pre index shall be less than size(). - */ - T& operator[](size_t index) - { - return _array[index]; - } - - /** - * Access to an immutable element of the array. - * - * @param index Element index to access. - * - * @return A const reference to the element at the index specified in input. - * - * @pre index shall be less than size(). - */ - const T& operator[](size_t index) const - { - return _array[index]; - } - - /** - * Get the raw pointer to the array. - * - * @return The raw pointer to the array. - */ - T* data() - { - return _array; - } - - /** - * Get the raw const pointer to the array. - * - * @return The raw pointer to the array. - */ - const T* data() const - { - return _array; - } - -private: - T* const _array; -}; - -/** - * ArrayView specialisation that handle dynamic array size. - */ -template -struct ArrayView { - - /** - * Construct a view to an empty array. - * - * @post a call to size() will return 0, and data() will return NULL. - */ - ArrayView() : _array(0), _size(0) { } - - /** - * Construct an array view from a pointer to a buffer and its size. - * - * @param array_ptr Pointer to the array data - * @param array_size Number of elements of T present in the array. - * - * @post a call to size() will return array_size and data() will return - * array_tpr. - */ - ArrayView(T* array_ptr, size_t array_size) : - _array(array_ptr), _size(array_size) { } - - /** - * Construct an array view from the reference to an array. - * - * @param elements Reference to the array viewed. - * - * @tparam Size Number of elements of T presents in the array. - * - * @post a call to size() will return Size, and data() will return - * a pointer to elements. - */ - template - ArrayView(T (&elements)[Size]): - _array(elements), _size(Size) { } - - - /** - * Construct a ArrayView object with a dynamic size from an ArrayView object - * with a static size. - * @param other The ArrayView object used to construct this. - */ - template - ArrayView(ArrayView other): - _array(other.data()), _size(other.size()) { } - - /** - * Return the size of the array viewed. - * - * @return The number of elements present in the array viewed. - */ - size_t size() const - { - return _size; - } - - /** - * Access to a mutable element of the array. - * - * @param index Element index to access. - * - * @return A reference to the element at the index specified in input. - * - * @pre index shall be less than size(). - */ - T& operator[](size_t index) - { - return _array[index]; - } - - /** - * Access to an immutable element of the array. - * - * @param index Element index to access. - * - * @return A const reference to the element at the index specified in input. - * - * @pre index shall be less than size(). - */ - const T& operator[](size_t index) const - { - return _array[index]; - } - - /** - * Get the raw pointer to the array. - * - * @return The raw pointer to the array. - */ - T* data() - { - return _array; - } - - /** - * Get the raw const pointer to the array. - * - * @return The raw pointer to the array. - */ - const T* data() const - { - return _array; - } - -private: - T* const _array; - const size_t _size; -}; - - -/** - * Equality operator. - * - * @param lhs Left hand side of the binary operation. - * @param rhs Right hand side of the binary operation. - * - * @return True if arrays in input have the same size and the same content - * and false otherwise. - */ -template -bool operator==(const ArrayView& lhs, const ArrayView& rhs) -{ - if (lhs.size() != rhs.size()) { - return false; - } - - if (lhs.data() == rhs.data()) { - return true; - } - - return std::equal(lhs.data(), lhs.data() + lhs.size(), rhs.data()); -} - -/** - * Not equal operator - * - * @param lhs Left hand side of the binary operation. - * @param rhs Right hand side of the binary operation. - * - * @return True if arrays in input do not have the same size or the same - * content and false otherwise. - */ -template -bool operator!=(const ArrayView& lhs, const ArrayView& rhs) -{ - return !(lhs == rhs); -} - - -/** - * Generate an array view from a reference to a C/C++ array. - * - * @tparam T Type of elements held in elements. - * @tparam Size Number of items held in elements. - * - * @param elements The reference to the array viewed. - * - * @return The ArrayView to elements. - * - * @note This helper avoids the typing of template parameter when ArrayView is - * created 'inline'. - */ -template -ArrayView make_ArrayView(T (&elements)[Size]) -{ - return ArrayView(elements); -} - -/** - * Generate an array view from a pointer to a C/C++ array. - * - * @tparam Size Number of items held in elements. - * @tparam T Type of elements held in elements. - * - * @param elements The reference to the array viewed. - * - * @return The ArrayView to elements. - * - * @note This helper avoids the typing of template parameter when ArrayView is - * created 'inline'. - */ -template -ArrayView make_ArrayView(T* elements) -{ - return ArrayView(elements, Size); -} - -/** - * Generate an array view from a C/C++ pointer and the size of the array. - * - * @tparam T Type of elements held in array_ptr. - * - * @param array_ptr The pointer to the array to viewed. - * @param array_size The number of T elements in the array. - * - * @return The ArrayView to array_ptr with a size of array_size. - * - * @note This helper avoids the typing of template parameter when ArrayView is - * created 'inline'. - */ -template -ArrayView make_ArrayView(T* array_ptr, size_t array_size) -{ - return ArrayView(array_ptr, array_size); -} - -/** - * Generate a const array view from a reference to a C/C++ array. - * - * @tparam T Type of elements held in elements. - * @tparam Size Number of items held in elements. - * - * @param elements The array viewed. - * @return The ArrayView to elements. - * - * @note This helper avoids the typing of template parameter when ArrayView is - * created 'inline'. - */ -template -ArrayView make_const_ArrayView(T (&elements)[Size]) -{ - return ArrayView(elements); -} - -/** - * Generate a const array view from a pointer to a C/C++ array. - * - * @tparam Size Number of items held in elements. - * @tparam T Type of elements held in elements. - * - * @param elements The reference to the array viewed. - * - * @return The ArrayView to elements. - * - * @note This helper avoids the typing of template parameter when ArrayView is - * created 'inline'. - */ -template -ArrayView make_const_ArrayView(const T* elements) -{ - return ArrayView(elements, Size); -} - -/** - * Generate a const array view from a C/C++ pointer and the size of the array. - * - * @tparam T Type of elements held in array_ptr. - * - * @param array_ptr The pointer to the array to viewed. - * @param array_size The number of T elements in the array. - * - * @return The ArrayView to array_ptr with a size of array_size. - * - * @note This helper avoids the typing of template parameter when ArrayView is - * created 'inline'. - */ -template -ArrayView make_const_ArrayView(T* array_ptr, size_t array_size) -{ - return ArrayView(array_ptr, array_size); -} - -} // namespace ble - -/** - * @} - * @} - */ - - -#endif /* BLE_ARRAY_VIEW_H_ */