From 78d4a9b6c8a980a4a016ef3c6a54d2f09a3b4ee1 Mon Sep 17 00:00:00 2001 From: Vincent Coubard Date: Sun, 25 Nov 2018 11:22:55 +0000 Subject: [PATCH] BLE: Cleanup enum duplicates in gap/Types.h --- .../ble/gap/AdvertisingParameters.h | 4 +- features/FEATURE_BLE/ble/gap/Types.h | 60 +++++++------------ features/FEATURE_BLE/ble/pal/GapEvents.h | 2 +- .../FEATURE_BLE/source/generic/GenericGap.cpp | 20 +++---- .../source/generic/GenericSecurityManager.cpp | 10 ++-- 5 files changed, 40 insertions(+), 56 deletions(-) diff --git a/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h b/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h index 9056c7a7811..6ed73e7cb5b 100644 --- a/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h +++ b/features/FEATURE_BLE/ble/gap/AdvertisingParameters.h @@ -127,7 +127,7 @@ class AdvertisingParameters { * @note If value in input are out of range, they will be normalized. */ AdvertisingParameters( - advertising_type_t advType = advertising_type_t::ADV_CONNECTABLE_UNDIRECTED, + advertising_type_t advType = advertising_type_t::CONNECTABLE_UNDIRECTED, adv_interval_t minInterval = adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MIN), adv_interval_t maxInterval = adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MAX) ) : @@ -151,7 +151,7 @@ class AdvertisingParameters { _includeHeaderTxPower(false) { /* Min interval is slightly larger than in other modes. */ - if (_advType == advertising_type_t::ADV_NON_CONNECTABLE_UNDIRECTED) { + if (_advType == advertising_type_t::NON_CONNECTABLE_UNDIRECTED) { _minInterval = adv_interval_t(std::max(_minInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON)); _maxInterval = adv_interval_t(std::max(_maxInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON)); } diff --git a/features/FEATURE_BLE/ble/gap/Types.h b/features/FEATURE_BLE/ble/gap/Types.h index 29117e0df83..d56ed9fc526 100644 --- a/features/FEATURE_BLE/ble/gap/Types.h +++ b/features/FEATURE_BLE/ble/gap/Types.h @@ -95,14 +95,14 @@ typedef Duration > conn_interval_t; * * @note this time should be no larger than (1 + ConnLatency) * ConnIntervalMax * 2 */ -typedef Duration > supervision_timeout_t; +typedef Duration > supervision_timeout_t; /** * Duration of a connection event. * * The duration is in unit of 625µs and ranges from 0x0 to 0xFFFF . */ -typedef Duration > conn_event_length_t; +typedef Duration > conn_event_length_t; /** * Time after which a periodic sync link is considered loss if the receiver hasn't @@ -110,14 +110,14 @@ typedef Duration > conn_event_length_t * * The duration is in unit of 10 milliseconds and ranges from 0x0A to 0x4000. */ -typedef Duration > sync_timeout_t; +typedef Duration > sync_timeout_t; /** * Interval between two periodic advertsising events. * * The duration is in unit of 1.250ms and ranges from 0x06 to 0xFFFF. */ -typedef Duration > periodic_interval_t; +typedef Duration > periodic_interval_t; /** * Number of connection events that can be skipped by the slave. @@ -155,38 +155,42 @@ struct advertising_type_t : SafeEnum { * * @see Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1. */ - ADV_CONNECTABLE_UNDIRECTED = 0x00, - ADV_IND = 0x00, + CONNECTABLE_UNDIRECTED = 0x00, /** * Device is connectable and expects connection from a specific peer. * (3.75 ms or smaller Advertising Interval) * @see Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2. */ - ADV_CONNECTABLE_DIRECTED = 0x01, - ADV_DIRECT_IND = 0x01, + CONNECTABLE_DIRECTED = 0x01, /** * Device is scannable but not connectable. * * @see Vol 6, Part B, Section 2.3.1.4. */ - ADV_SCANNABLE_UNDIRECTED = 0x02, - ADV_SCAN_IND = 0x02, + SCANNABLE_UNDIRECTED = 0x02, /** * Device is not connectable and not scannable. * * @see Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3. */ - ADV_NON_CONNECTABLE_UNDIRECTED = 0x03, - ADV_NONCONN_IND = 0x03, + NON_CONNECTABLE_UNDIRECTED = 0x03, /** * Device is connectable and expects connection from a specific peer (sent at long user set intervals). */ - ADV_CONNECTABLE_DIRECTED_LOW_DUTY = 0x04, + CONNECTABLE_DIRECTED_LOW_DUTY = 0x04, + +#if !defined(DOXYGEN_ONLY) + // used by the PAL; naming in line with the the spec. + ADV_IND = 0x00, + ADV_DIRECT_IND = 0x01, + ADV_SCAN_IND = 0x02, + ADV_NONCONN_IND = 0x03, ADV_DIRECT_IND_LOW_DUTY_CYCLE = 0x04 +#endif }; /** @@ -329,7 +333,7 @@ struct advertising_event_t { */ bool complete() const { - return data_status().value() == advertising_data_status_t::COMPLETE; + return data_status() == advertising_data_status_t::COMPLETE; } /** Is there more data coming. @@ -338,7 +342,7 @@ struct advertising_event_t { */ bool more_data_to_come() const { - return data_status().value() == advertising_data_status_t::INCOMPLETE_MORE_DATA; + return data_status() == advertising_data_status_t::INCOMPLETE_MORE_DATA; } /** Is the payload truncated. @@ -347,7 +351,7 @@ struct advertising_event_t { */ bool truncated() const { - return data_status().value() == advertising_data_status_t::INCOMPLETE_DATA_TRUNCATED; + return data_status() == advertising_data_status_t::INCOMPLETE_DATA_TRUNCATED; } private: @@ -535,13 +539,11 @@ struct own_address_type_t : SafeEnum { /** * Use the public device address. */ - PUBLIC_ADDRESS = 0x00, PUBLIC = 0x00, /** * Use the random device address. */ - RANDOM_ADDRESS = 0x01, RANDOM = 0x01, /** @@ -577,10 +579,7 @@ struct target_peer_address_type_t : SafeEnum { */ CENTRAL = 0x00, - /** - * @see CENTRAL - */ - MASTER = 0x00, - /** * Peripheral Role. * @@ -721,12 +715,7 @@ struct connection_role_t : SafeEnum { * * @note A peripheral is a broadcaster. */ - PERIPHERAL = 0x01, - - /** - * @see PERIPHERAL - */ - SLAVE = 0x01 + PERIPHERAL = 0x01 }; /** @@ -761,25 +750,21 @@ struct local_disconnection_reason_t : SafeEnum { /** * Connection parameters were unacceptable. */ - CONN_INTERVAL_UNACCEPTABLE = 0x3B + UNACCEPTABLE_CONNECTION_PARAMETERS = 0x3B }; /** diff --git a/features/FEATURE_BLE/ble/pal/GapEvents.h b/features/FEATURE_BLE/ble/pal/GapEvents.h index 728205479f4..28623eb3f44 100644 --- a/features/FEATURE_BLE/ble/pal/GapEvents.h +++ b/features/FEATURE_BLE/ble/pal/GapEvents.h @@ -158,7 +158,7 @@ struct GapConnectionCompleteEvent : public GapEvent { connection_handle(connection_handle), role(role), peer_address_type( - peer_address_type == advertising_peer_address_type_t::PUBLIC_ADDRESS ? + peer_address_type == advertising_peer_address_type_t::PUBLIC ? peer_address_type_t::PUBLIC : peer_address_type_t::RANDOM ), diff --git a/features/FEATURE_BLE/source/generic/GenericGap.cpp b/features/FEATURE_BLE/source/generic/GenericGap.cpp index 5aa9fb2bc15..3c59c4f7266 100644 --- a/features/FEATURE_BLE/source/generic/GenericGap.cpp +++ b/features/FEATURE_BLE/source/generic/GenericGap.cpp @@ -1097,7 +1097,7 @@ ble_error_t GenericGap::startRadioScan(const GapScanningParams &scanningParams) pal::own_address_type_t own_address_type = get_own_address_type(CENTRAL_SCAN /* central, can use non resolvable address for scan requests */); - if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM_ADDRESS)) { + if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) { // Use non-resolvable static random address set_random_address_rotation(true); } @@ -1227,7 +1227,7 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams ¶ms) pal::own_address_type_t own_address_type = get_own_address_type(address_use_type); - if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM_ADDRESS)) { + if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) { // Use non-resolvable static random address set_random_address_rotation(true); } @@ -1243,7 +1243,7 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams ¶ms) /* advertising_interval_max */ params.getIntervalInADVUnits(), (pal::advertising_type_t::type) params.getAdvertisingType(), own_address_type, - pal::advertising_peer_address_type_t::PUBLIC_ADDRESS, + pal::advertising_peer_address_type_t::PUBLIC, ble::address_t(), pal::advertising_channel_map_t::ALL_ADVERTISING_CHANNELS, _advertising_filter_policy @@ -1473,7 +1473,7 @@ BLE_DEPRECATED_API_USE_END() bool needs_authentication = false; if (_privacy_enabled && - e.role.value() == e.role.SLAVE && + e.role.value() == e.role.PERIPHERAL && e.peer_address_type == peer_address_type_t::RANDOM ) { // Apply privacy policy if in peripheral mode for non-resolved addresses @@ -1490,7 +1490,7 @@ BLE_DEPRECATED_API_USE_END() // Reject connection request - the user will get notified through a callback _pal_gap.disconnect( e.connection_handle, - pal::disconnection_reason_t::AUTHENTICATION_FAILLURE + pal::disconnection_reason_t::AUTHENTICATION_FAILURE ); return; @@ -1508,7 +1508,7 @@ BLE_DEPRECATED_API_USE_END() } } - if (e.role.value() == e.role.SLAVE) { + if (e.role.value() == e.role.PERIPHERAL) { _advertising_timeout.detach(); _pal_gap.advertising_enable(false); @@ -1534,7 +1534,7 @@ BLE_DEPRECATED_API_USE_END() processConnectionEvent( e.connection_handle, - e.role.value() == e.role.MASTER ? ::Gap::CENTRAL : ::Gap::PERIPHERAL, + e.role.value() == e.role.CENTRAL ? ::Gap::CENTRAL : ::Gap::PERIPHERAL, e.peer_address_type, e.peer_address.data(), _address_type, @@ -1606,7 +1606,7 @@ pal::own_address_type_t GenericGap::get_own_address_type(AddressUseType_t addres // An non resolvable private address should be generated if (use_non_resolvable_address) { - return pal::own_address_type_t::RANDOM_ADDRESS; + return pal::own_address_type_t::RANDOM; } switch (_address_type) { @@ -1619,9 +1619,9 @@ pal::own_address_type_t GenericGap::get_own_address_type(AddressUseType_t addres switch (_address_type) { case BLEProtocol::AddressType::PUBLIC: - return pal::own_address_type_t::PUBLIC_ADDRESS; + return pal::own_address_type_t::PUBLIC; default: - return pal::own_address_type_t::RANDOM_ADDRESS; + return pal::own_address_type_t::RANDOM; } } diff --git a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp index fc6da98b71d..0c5e047dc48 100644 --- a/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp +++ b/features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp @@ -1100,8 +1100,8 @@ void GenericSecurityManager::on_security_entry_retrieved( _pal.add_device_to_resolving_list( identity->identity_address_is_public ? - address_type_t::PUBLIC_ADDRESS : - address_type_t::RANDOM_ADDRESS, + address_type_t::PUBLIC : + address_type_t::RANDOM, identity->identity_address, identity->irk ); @@ -1117,8 +1117,8 @@ void GenericSecurityManager::on_identity_list_retrieved( for (size_t i = 0; i < count; ++i) { _pal.add_device_to_resolving_list( identity_list[i].identity_address_is_public ? - address_type_t::PUBLIC_ADDRESS : - address_type_t::RANDOM_ADDRESS, + address_type_t::PUBLIC : + address_type_t::RANDOM, identity_list[i].identity_address, identity_list[i].irk ); @@ -1564,7 +1564,7 @@ void GenericSecurityManager::on_keys_distributed_bdaddr( _db->set_entry_peer_bdaddr( cb->db_entry, - (peer_address_type == advertising_peer_address_type_t::PUBLIC_ADDRESS), + (peer_address_type == advertising_peer_address_type_t::PUBLIC), peer_identity_address ); }